Skip to content

[rtl] Switch to ratified bitmanip extensions - #2459

Open
thommythomaso wants to merge 1 commit into
lowRISC:masterfrom
thommythomaso:tbenz/bitmanip
Open

[rtl] Switch to ratified bitmanip extensions#2459
thommythomaso wants to merge 1 commit into
lowRISC:masterfrom
thommythomaso:tbenz/bitmanip

Conversation

@thommythomaso

@thommythomaso thommythomaso commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

This PR switches the RTL of Ibex from our currently unratified bitmanip extension to the officially ratified extensions.

An overview of the changes can be found here.

This PR only introduces the RTL changes and ensures the CI tests pass. Certain scalar crypto extensions are not yet fully verified; see #2468.

@marnovandermaas marnovandermaas left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial comments from me. Do you think it is worth squashing the commits that just remove things? I think it may be excessive to have 9 separate commits for removing instructions.

Comment thread rtl/ibex_decoder.sv
Comment thread rtl/ibex_decoder.sv Outdated
Comment thread doc/01_overview/compliance.rst
@thommythomaso

Copy link
Copy Markdown
Contributor Author

Initial comments from me. Do you think it is worth squashing the commits that just remove things? I think it may be excessive to have 9 separate commits for removing instructions.

I have them as individual commits to help people review the changes. I would have squashed all into one after the review process. What do you think?

@thommythomaso
thommythomaso marked this pull request as ready for review July 16, 2026 06:53

@SamuelRiedel SamuelRiedel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning up the bitmanip @thommythomaso. I did a quite thorough review, but most of it should be easy to fix.

The only thing that is left is that we should update RISC-V DV to also support the latest ratified extensions. I saw that the ratified B extensions are supported already, but for the scalar crypto ones, we currently simply enable the Zbp still, right? I think this is good enough for now, but we should create an issue documenting the current state, like which instructions are emitted by riscv-dv and which aren't and what we would ideally want to then clean up the DV in a second step at least.

Comment thread doc/01_overview/compliance.rst Outdated
Comment thread doc/01_overview/compliance.rst Outdated
Comment thread doc/03_reference/instruction_decode_execute.rst Outdated
Comment thread doc/03_reference/instruction_decode_execute.rst
Comment thread dv/cosim/spike_cosim.cc
Comment thread rtl/ibex_decoder.sv Outdated
Comment thread rtl/ibex_decoder.sv Outdated
Comment thread rtl/ibex_decoder.sv Outdated
Comment thread rtl/ibex_tracer_pkg.sv Outdated
Comment thread rtl/ibex_alu.sv Outdated
This PR removes the unratified bitmanip extensions from Ibex and switches to the ratified set.

We remove `Xzbe0p93`, `Xzbf0p93`, `Xzbr0p93`, `Xzbt0p93`, and `Xzbe0p93`, replacing them with
`Zbkb` and `Zbkx`.

Signed-off-by: Thomas Benz <tbenz@lowrisc.org>

@vogelpi vogelpi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @thommythomaso for taking this effort on in the first place and for the PR. This is nice work!

Apart from a couple of nits, I think we should do the following things before merging this PR:

  • We should consider implementing ror/rol in the shifter rather than making it a multicycle instruction. Because these instructions were never a driver for introducing multi-cycle instructions in the ALU, but once the support was there, it was good to re-use the infrastructure to avoid making the shifter more complex. Now, it would be possible to have everything single cycle and I believe moving the complexity to the shifter would not increase the critical path but reduce complexity and area.
  • There are quite a few single-line (plus default) unique_case statements in the decoder now. While it's easier to review the changes as is. We should rewrite these statements IMO to increase readability.

In general, I wondering how confident we are that when adding DV support for the scalar crypto, we don't find out that stuff is missing or not properly implemented? Have @SamuelRiedel and @marnovandermaas done a thorough enough review such that we are reasonable confident? On my end, I mostly focused on ensuring we don't drop an instruction which is not meant to be dropped (according to your sheet @thommythomaso ).

Comment on lines +39 to +41
* - **B**: Standard Extension for Bit-Manipulation Instructions (Zba, Zbb, Zbc, Zbs)
- 1.0.0
- optional

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that B just comprises Zba, Zbb and Zbs. The collection comprising Zba, Zbb, Zbc and Zbs is called RISC-V bit manipulation extension v.1.0.0 (see https://www.ece.lsu.edu/ee4720/doc/riscv-bitmanip-1.0.0.pdf, it's the same doc you referenced above but this doesn't reference "B" anymore).

So, here we should probably say:

  • B + Zbc because that's what we use our ISA string
  • or then Zba, Zbb, Zbc, Zbs as above

Comment thread rtl/ibex_alu.sv
Comment on lines 231 to 233
always_comb begin
if (bfp_op) begin
shift_amt[4:0] = bfp_off; // length field of bfp control word
end else begin
shift_amt[4:0] = instr_first_cycle_i ?
(operand_b_i[5] && shift_funnel ? shift_amt_compl[4:0] : operand_b_i[4:0]) :
(operand_b_i[5] && shift_funnel ? operand_b_i[4:0] : shift_amt_compl[4:0]);
end
shift_amt[4:0] = instr_first_cycle_i ? operand_b_i[4:0] : shift_amt_compl[4:0];
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You now have an always_comb with a single ternary statement in it. Can you please just convert this to an assign?

Comment thread rtl/ibex_alu.sv
Comment on lines 264 to 267
end else begin
unique case (1'b1)
bfp_op: shift_operand = bfp_mask_rev;
shift_sbmode: shift_operand = 32'h8000_0000;
default: shift_operand = shift_left ? operand_a_rev : operand_a_i;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You now have quite a few unique case (1'b1) statements with a single case plus the default in here. I think an if/else would make more sense but I also appreciate the diff now being smaller meaning the review is simpler.

Comment thread rtl/ibex_alu.sv
Comment on lines +506 to +508
////////////////////////////////
// rev8 / brev8 / orc.b //
////////////////////////////////

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you anyway change this, is there a reason for not minimizing the width of the header? i.e.,

    //////////////////////////
    // rev8 / brev8 / orc.b //
    //////////////////////////

Comment thread rtl/ibex_alu.sv
Comment on lines +812 to +813
// Shift Rotations
// operand_a_i is tied to rs1, operand_b_i is tied to rs2.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shift rotations are now the only multi-cycle instructions of the ALU and those are the most simple instructions of the original set of multi-cycle instructions. IIRC, we decided to make them multi-cycle as the register is now there anyway and it was better to use it compared to also making the shifter wider.

But now, we only keep the register and the control (+ verification complexity) to implement an instruction which could probably simply be implemented with a slightly different shifter. Have you considered this option?

Comment thread rtl/ibex_decoder.sv
5'b0_0101, // bseti
5'b0_1101: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // binvi
5'b0_1101: illegal_insn = (instr[26:25] == 2'b00 && RV32B != RV32BNone) ?
1'b0 : 1'b1; // binvi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the // binvi comment should be moved left by one space ;-)

Comment thread rtl/ibex_decoder.sv
5'b0_1100, // rori
5'b0_1001: illegal_insn = (RV32B != RV32BNone) ? 1'b0 : 1'b1; // bexti
5'b0_1001: illegal_insn = (instr[26:25] == 2'b00 && RV32B != RV32BNone) ?
1'b0 : 1'b1; // bexti

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: move comment // bexti left by 1 space.

Comment thread rtl/ibex_decoder.sv
illegal_insn = 1'b1;
end
// orc.b (Zbb): gorci restricted to shamt 0x07
illegal_insn = (instr[25:20] == 6'b000111 && RV32B != RV32BNone) ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 6'00_0111 would be more readable.

@SamuelRiedel

Copy link
Copy Markdown
Contributor

Thanks @thommythomaso for taking this effort on in the first place and for the PR. This is nice work!

Apart from a couple of nits, I think we should do the following things before merging this PR:

  • We should consider implementing ror/rol in the shifter rather than making it a multicycle instruction. Because these instructions were never a driver for introducing multi-cycle instructions in the ALU, but once the support was there, it was good to re-use the infrastructure to avoid making the shifter more complex. Now, it would be possible to have everything single cycle and I believe moving the complexity to the shifter would not increase the critical path but reduce complexity and area.
  • There are quite a few single-line (plus default) unique_case statements in the decoder now. While it's easier to review the changes as is. We should rewrite these statements IMO to increase readability.

In general, I wondering how confident we are that when adding DV support for the scalar crypto, we don't find out that stuff is missing or not properly implemented? Have @SamuelRiedel and @marnovandermaas done a thorough enough review such that we are reasonable confident? On my end, I mostly focused on ensuring we don't drop an instruction which is not meant to be dropped (according to your sheet @thommythomaso ).

@vogelpi I reviewed the hardware thoroughly, including the scalar crypto extensions, and I am confident we aren't missing any instructions. As noted though, the DV still needs cleanup. While I'd prefer a clean DV run to ensure all corner cases are covered, this PR doesn't add any new instructions/logic and the old DV still runs. Therefore, IMO we match the current D1 state, can merge the RTL, and address the DV in the next step.

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.

4 participants