Skip to content

[RISCV] Implement "B" bit-manipulation extension and WCH vendor-proprietary "XW" extension#7859

Open
ArcaneNibble wants to merge 7 commits into
Vector35:devfrom
ArcaneNibble:riscv-work-cleanup
Open

[RISCV] Implement "B" bit-manipulation extension and WCH vendor-proprietary "XW" extension#7859
ArcaneNibble wants to merge 7 commits into
Vector35:devfrom
ArcaneNibble:riscv-work-cleanup

Conversation

@ArcaneNibble

Copy link
Copy Markdown

This PR implements support for the RISC-V B bit manipulation instructions, which are broken up into Zba, Zbb, and Zbs sub-features.

If acceptable for upstream, it also implements proprietary opcodes from Nanjing Qinheng Microelectronics which are used in their microcontroller products. This is currently not able to be auto-detected from .riscv.attributes and must be manually selected.

Also fixes #7809

These indicate to the linker that a relaxation _may_ be performed.
This is an optimization which is not required. Silences log warnings.
These are single-bit bit-manipulation instructions.
These instructions assist with address-related computations.
These are "basic" bit-manipulation instructions which have
a straightforward lifting to LLIL.
This includes a hardware-accelerated memory copy and custom compressed
byte/halfword load/store instructions.
@CLAassistant

CLAassistant commented Jan 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@zznop

zznop commented Jul 1, 2026

Copy link
Copy Markdown
Member

I added two follow-up commits on top of the original PR (after rebasing) - they can be found in the test_pr_7859 branch:

  1. 9af751ae fixes integration issues from rebasing the PR:

    • Renames the WCH architecture from rv32-wch to rv32gc_wch so it matches the existing RISC-V architecture naming style.
    • Updates the WCH calling convention registration to use the current Rust API closure form.
    • Fixes section-relative ELF relocation symbol lookup by not adding imageBaseAdjustment a second time. This was causing RISC-V PCREL_HI20/LO12 relocation pairs to bind to the wrong local label and produce incorrect relocated ADDI immediates.
      • I would like to see the binary that prompted you to make this change if you can share.
  2. 2754c377 updates the new bitmanip lifting to use first-class LLIL operations:

    • Replaces custom/intrinsic lifting for clz, ctz, cpop, and rev8 with LLIL_CLZ, LLIL_CTZ, LLIL_POPCNT, and LLIL_BSWAP.
    • Replaces the branchy max, maxu, min, and minu lifting with LLIL_MAXS, LLIL_MAXU, LLIL_MINS, and LLIL_MINU

I also created two binaries so I could test/observe the lifting output for the new instruction support. The riscv_wch.elf binary must be opened with options to select the rv32gc_wch architecture.

riscv_zba_zbb_zbs.elf.zip
riscv_wch.elf.zip

@zznop zznop added this to the Krypton milestone Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect RISC-V relocation processing when multiple symbols have the same name

4 participants