Skip to content

lowest/highest_set_bit functions should return a Bits type? #473

Open
@ThinkOpenly

Description

@ThinkOpenly

Describe the bug
I think the IDL functions lowest_set_bit and highest_set_bit are defined slightly incorrectly.

In reviewing #471, the following assignment was being slightly corrected:

X[rd] = (xlen() - 1) - $signed(lowest_set_bit(X[rs1]));
  • X[rd] and X[rs1] are of type Bits[XLEN] (I believe, as BUILTIN).
  • xlen() is defined:
    function xlen {
      returns Bits<8>
    
    (I'll note that Extension B: fix ctz instruction IDL code #471 is removing the use of xlen(), but it's useful for additional context here.)
  • I confess not knowing where $signed is defined (?)
  • lowest_set_bit(...) is defined:
    function highest_set_bit {
      returns XReg
      arguments XReg value
    [...]
    function lowest_set_bit {
      returns XReg
      arguments XReg value
    

It makes sense to me that the *set_bit functions accept an XReg parameter.

It does not make sense to me that they return an XReg value. Ignoring $signed, the calculation is using register values to compute an integer value (less than or equal to XLEN).

Should these functions instead return Bits<8> (or essentially Bits<log2(XLEN)>, but we presume that 8 is sufficient)?

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggood first issueGood for newcomers

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions