-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Llvm sem #130
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for doing the hard work of checking these andres! I have a single flavour of question about the bits
, and one that I have left unreviewed because I don't trust myself enough tonight.
def srem? {w : Nat} (x y : BitVec w) : Option <| BitVec w := | ||
if y.toInt = 0 | ||
then none | ||
else | ||
let div := (x.toInt / y.toInt) | ||
if div < Int.ofNat (2^w) | ||
then some $ BitVec.ofInt w (x.toInt.rem y.toInt) | ||
else none |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be reviewed carefully, but I lack the mental acuity today to do so. I'm postponing this to tomorrow, I'm afraid :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe your answers to my previous questions, and left one more type of question: I wonder if we should also check for negative overflow, with div >= - Int.ofNat (2^w)
then none | ||
else | ||
let div := (x.toInt / y.toInt) | ||
if div < Int.ofNat (2^w) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to check overflow on the negative side as well?
if div < Int.ofNat (2^w) | |
if div < Int.ofNat (2^w) && div >= - (Int.ofNat (2^w)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bollu good point! but then it should be < intMin
or > intMax
, right? (in particular, that's 2^(w-1)
, no?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, in 2s complement, something of width w
goes from
then none | ||
else | ||
let div := (x.toInt / y.toInt) | ||
if div < Int.ofNat (2^w) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not need to check the other side of overflow as well?
if div < Int.ofNat (2^w) | |
if div < Int.ofNat (2^w) && div >= - (Int.ofNat (2^w)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above
Co-authored-by: Siddharth <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there is some kind of unit test we can write for these, since it seems quite error prone to get these right.
It all looks consistent to me now, so feel invited to merge!
Co-authored-by: Siddharth <[email protected]>
yeah, ideally we should use the mlirnatural entry point and run a bunch of tests to compare with LLVM/MLIR. I'll add an issue for that. |
Check our denotation with the LLVM semantics (and document those).
The only thing I'm not 100% sure is what happens with constants when they exceed the bitwidth (will check that with examples later)