Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
32 bit signed xor broken on VM #10482
The cause of the bug is, on the VM negatives numbers are represented in higher precision. So a -1 has 64 bits set to 1, even if it represents a 32 bit -1. In combination with xor and a positive number, these upper bits are set to 0. If only the actual 32 important bits would be taken care of everything would seem fine, but sadly the CPU thinks these are now positive numbers.
import strutils static: # only the visible part is printed let x = -1'i32 let y = 1'i32 echo toHex(x) # FFFFFFFF echo toHex(y) # 00000001 echo toHex(x xor y) # FFFFFFFE echo toHex(-2'i32) # FFFFFFFE <- seems right doesn't it ? echo int64(x xor y) # 4294967294 <- something is wrong here echo toHex(int64(x xor y)) # 00000000FFFFFFFE <-\ echo toHex(int64(-2)) # FFFFFFFFFFFFFFFE <---- the difference is in the hidden part