I've noticed that there are at least two different approaches being used for encoding immediate values that exclude one or more LSBs in the ISA documentation. I think this multiplicity of methods could cause misunderstandings and mistakes...
The first approach in use is to shift all the bit ranges/indexes such that all LSBs of the provided value are used. I found this approach in use in RV32_I.hs. For example, LUI in "The RISC-V Instruction Set Manual - Volume I: Unprivileged ISA - 20191213" specifies imm[31:12], but lui_raw at RV32_I.hs:169 takes imm[19:0]. Both take 20 bits, but the former specifies the top 20 and the latter takes the bottom 20. This seems fine if all present and future usages of the lui instruction adhere to this convention, if more confusing for some people (and perhaps more intuitive for other people). I wonder if this approach is legacy behaviour from a time when, perhaps, the bit range behaviour of the encode function was not developed to the same extent that it is now.
However, there is another approach in use that leaves the bit ranges/indexes as they are given in the spec. I found this approach in use in RV_C.hs. For example, C.LUI in the spec document mentioned earlier specifies nzimm[17:12] (nzimm[17] and nzimm[16:12]), and also c_lui_raw at RV_C.hs:144 takes nzimm[17:12] (nzimm[17] and nzimm[16:12]). This means that the 12 LSBs of the provided immediate are dropped when c_lui is used, with only the 6 bits above them being encoded. Again, this seems fine if all present and future usages of c_lui adhere to this convention, but it seems needlessly confusing for this behaviour to differ between the compressed and uncompressed versions of the same instruction.
I suppose the first question might be, is the wider issue of multiple approaches to immediate bit-ranges of concern to anyone other than me?
If so, which approach is generally preferred, if any?
And ultimately, is standardisation of this worth the effort and chance of introducing a new issue?
I've noticed that there are at least two different approaches being used for encoding immediate values that exclude one or more LSBs in the ISA documentation. I think this multiplicity of methods could cause misunderstandings and mistakes...
The first approach in use is to shift all the bit ranges/indexes such that all LSBs of the provided value are used. I found this approach in use in RV32_I.hs. For example,
LUIin "The RISC-V Instruction Set Manual - Volume I: Unprivileged ISA - 20191213" specifiesimm[31:12], butlui_rawat RV32_I.hs:169 takesimm[19:0]. Both take 20 bits, but the former specifies the top 20 and the latter takes the bottom 20. This seems fine if all present and future usages of theluiinstruction adhere to this convention, if more confusing for some people (and perhaps more intuitive for other people). I wonder if this approach is legacy behaviour from a time when, perhaps, the bit range behaviour of theencodefunction was not developed to the same extent that it is now.However, there is another approach in use that leaves the bit ranges/indexes as they are given in the spec. I found this approach in use in RV_C.hs. For example,
C.LUIin the spec document mentioned earlier specifiesnzimm[17:12](nzimm[17]andnzimm[16:12]), and alsoc_lui_rawat RV_C.hs:144 takesnzimm[17:12](nzimm[17]andnzimm[16:12]). This means that the 12 LSBs of the provided immediate are dropped whenc_luiis used, with only the 6 bits above them being encoded. Again, this seems fine if all present and future usages ofc_luiadhere to this convention, but it seems needlessly confusing for this behaviour to differ between the compressed and uncompressed versions of the same instruction.I suppose the first question might be, is the wider issue of multiple approaches to immediate bit-ranges of concern to anyone other than me?
If so, which approach is generally preferred, if any?
And ultimately, is standardisation of this worth the effort and chance of introducing a new issue?