Simn / genjvm

13 stars 1 forks source link

Comparison operator flipping #19

Closed Simn closed 5 years ago

Simn commented 5 years ago

The generator currently flips some comparison operators, which is not safe to do because of NaN stuff.

The reason it does that is because I initially got mega-confused by the if instructions. They branch on comparison with 0, so if_eq with 0/false on the stack branches.

Simn commented 5 years ago

Turns out the flipping wasn't the issue, I just wasn't respecting the actual comparison operator. It has to generate dcmpl for the > and >= cases and dcmpg for < and <=.

nadako commented 5 years ago

I think the only problem with operator flipping and NaN is that both > and < with NaN is false, so rewriting !(a < NaN) to a >= NaN changes behaviour. Equality operators should be fine to flip.