Closed drewrisinger closed 5 years ago
val=0x1999 9999 9999 | |||
---|---|---|---|
lower= val & 0xFFFF FFFF | lower= np.int32(np.int64(val)) | lower=np.int32(val) | |
upper= (val >> 32) & 0xFFFF FFFF | 0x0000 1999, 0x9999 9999 | 0x0000 1999, 0x9999 9999 | 0xFFFF FFFF, 0x9999 9999 |
upper= np.int32(val / 65536 / 65536) | 0x0000 1999, 0x9999 9999 | 0x0000 1999, 0x9999 9999 | 0x0000 0000, 0x9999 9999 |
upper= np.int32(val >> 32) | 0x0000 1999, 0x9999 9999 | 0x0000 1999, 0x9999 9999 | 0xFFFF FFFF, 0x9999 9999 |
upper= np.int32(np.int64(val / 65536 / 65536)) | 0x0000 1999, 0x9999 9999 | 0x0000 1999, 0x9999 9999 | 0x0000 0000, 0x9999 9999 |
Did not completely test with setting val=np.int64(0x1999 9999 9999)
, but all problems above did not appear.
Semi-related: does ARTIQ's LLVM not do a constant folding pass? Cause if so, this shouldn't be an issue unless it's an error in the compiler's type handling.
This is expected (although undesirable) behavior that results from the way overflowing operations interact with polymorphic integer literals and type inference. It was well known to me that this kind of issue would arise when I was implementing it and hopefully I've commucated that to @sbourdeauducq.
I invite anyone with good ideas on solving this problem within the constraints (i.e. type inference, polymorphic literals and overflowing integers) to suggest their solution here. One unfortunate consequence of this design already being used is that any new design must not silently change the meaning of existing, even buggy, code. That makes it much harder.
No. How is val
anything other than a 64-bit integer in the first place?
Bug Report
One-Line Summary
Inconsistent results when casting binary numbers.
Issue Details
Steps to Reproduce
Sample Program:
Expected Behavior
All combinations of statements should output same values: (0x0000 1999, 0x9999 9999)
Actual (undesired) Behavior
Any of the upper bit statements combined with the last lower statement (
val_lower_32 = np.int32(val)
) fail whenval = 0x1999 9999 9999
, but work whenval = np.int64(0x1999 9999 9999)
. See comment below for failure table.My best guess is this is either a compiler error (maybe the type inferencer), or a reorder buffer & ALU overflow bit issue (it shouldn't be possible for a later type cast to affect the value of the upper bits, but it apparently does).
Understanding that this will probably take a while to get fixed, is the consensus that we should just explicitly declare the type of all integers to avoid similar issues?
Your System