ashrMInt caveat
sdasgup3 opened this issue · 0 comments
sdasgup3 commented
This is regarding the implementation of ashrMInt
What is the Problem
ashrMInt(mi(4, -8), 1) gives -4 //i.e ashrMInt(1000, 1) gives 1100, which is correct
ashrMInt(mi(4, 8), 1) gives 4 //i.e ashrMInt(1000, 1) gives 0100, which is not Correct
Why this is a problem
- As both Mints mi(4, 8) and mi(4, -8) represent the same bit vector (1000), arithmatic right shifts on them should not be affected by how the Mints are created.
Root Cause
MInts ( or BitVector) are stored as a value: BigInteger and a bitwidth: Int. Now right shift is performed on the BigInteger which expects the BigInteger to be a signed value and hence the problem.
Fix suggestion
- Either Implement the hook ashrMInt as
syntax MInt ::= ashrMInt(MInt, Int) [function]
rule ashrMInt(MI, I) => ashrMIntHelper(mi(bitwidthMInt(MI), svalueMInt(MI)), I)
syntax MInt ::= ashrMIntHelper(MInt, Int) [function] [function, hook(MINT.ashr)]
I can send the patch, if you need.
- Or adding a comment in domains.k about the usage model of ashrMInt