riscv-isa-sim icon indicating copy to clipboard operation
riscv-isa-sim copied to clipboard

Supporting variable XLEN

Open aswaterman opened this issue 10 months ago • 3 comments

No one has been beating down the door requesting changeable XLEN, but since it'll probably happen eventually, I wanted to have a place to take notes on what changes need to be made. (cc @jerryz123 @scottj97)

  • In XLEN=32 mode, Spike currently assumes that the x-registers' contents are all canonically sign-extended. Under that premise, instructions are guaranteed to always produce canonical sign-extended values. But that doesn't conform to the spec, which says that the implementation should ignore the upper XLEN-32 bits, rather than assuming they are canonical (https://github.com/riscv/riscv-isa-manual/blob/217b3f8cdbd94583f4933bb7c7b35bae3e70f74d/src/machine.adoc#L500-L505). HOWEVER, I think the following clause in the spec allows an alternative implementation, where we canonicalize the MSBs whenever XLEN changes. That would be much simpler to implement. https://github.com/riscv/riscv-isa-manual/blob/217b3f8cdbd94583f4933bb7c7b35bae3e70f74d/src/machine.adoc#L232-L233

aswaterman avatar Apr 11 '24 21:04 aswaterman

Question about this: assuming you are on an RV64 machine (== native XLEN=64), if you change to XLEN=32, are you expecting it to produce results as if it was an RV32 machine, or will there be discrepancies? There are some RV64-only instructions-- will they be treated as illegal? There are some RV32-only instructions (e.g. scalar crypto), do these become legal?

The scenario I'm thinking of is being able to run a binary compiled for RV32, on an RV64 machine.

aamartin0000 avatar Apr 19 '24 18:04 aamartin0000

An RV64-native machine with XLEN set to 32 should behave just the same as a native RV32 machine. Now of course the machine could have some non-conforming extensions (e.g. the RV64-only ADDW instruction might be present when XLEN=32, as a non-conforming extension), but then the implementation would not be able to claim that it implements the Ssstrict extension.

aswaterman avatar Apr 19 '24 20:04 aswaterman

Another question: does setting XLEN=32 also imply setting FLEN=32?

  • if not (i.e. FLEN != XLEN), how is the MSW handled for fmv/fcvt operations?
  • what about RV32D/RV64F instructions?
  • Zfa adds some instructions to deal with moving int32<->fp64 registers

aamartin0000 avatar Apr 22 '24 17:04 aamartin0000