riscv / riscv-bitmanip

Working draft of the proposed RISC-V Bitmanipulation extension

Home Page:https://jira.riscv.org/browse/RVG-122

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Clarify behavior of shift immediate operands

JamesKenneyImperas opened this issue · comments

I'm unsure about the intended design of instructions here that take immediate shift operands. At the moment this affects only slli.uw, but in future also gorci and grevi will be affected (when ratified).

In the base architecture, I think that when a shift amount (shamt) is encountered, this has to be in the range 0..XLEN-1, otherwise it is an Illegal Instruction. Historically, this hasn't been the case in this B extension; for example, in the previous 0.94 specification, slli.uw was defined like this:

uint_xlen_t slliuw(uint_xlen_t rs1, int imm)
{
uint_xlen_t rs1u = (uint32_t)rs1;
int shamt = imm & (XLEN - 1);
return rs1u << shamt;
}

With this decode:

| 00001 | imm | rs1 | 001 | rd | 0011011 | SLLI.UW

This allowed any 7-bit constant to be used and simply masked to the active XLEN, so no Illegal Instruction. Now, the decode of slli.uw has changed so that only a six-bit constant is allowed, and this is a shamt. I have three questions:

  1. Is the reduction from 7 to 6 bits for this field intentional?
  2. Is it expected that the field follows the standard shamt rules from the base architecture, so that if shamt >= 32 on RV32 this is an Illegal Instruction, or is it simply masked to 0...XLEN-1 as was the case in 0.94?
  3. If the proposed behavior has changed from 0.94, will this also be the case for gorci and grevi?

Apologies if this has been discussed elsewhere: if so, can you point me at that.

Thanks.

I just remembered that slli.uw is of course RV64 only, to the comments about RV32 don't apply.

I would still like to know the answer for questions 1 and 3.

Thanks.

Ok, so you are saying that this is an intentional change from 0.94?

Thanks.

Do you know of any other intentional changes like this between 0.94 and 1.0.0? Is there a list somewhere I can see?

Thanks.

Since there is no list of intentional changes like this between 0.94 and 1.0.0, I think I'll close this. My preliminary scan didn't find anything else that differed.

I came across this in some consistency checking of the document and can offer a bit more information...

The 0.93/0.94 version already had limited the width of immediates for RV32 and RV64 (see 2.12: "All shift instructions use funct3=001 for left shifts and funct3=101 for right shifts. Just like in the RISC-V integer base ISA, the shift-immediate instructions have a 5 bit immediate on RV32, and a 6 bit immediate on RV64, and we reserve encoding space for a 7 bit immediate for RV128."), but did not make it explicit that this would require raising an undefined instruction if the high bit is set for RV32.