Re: Probably a bug in LuaJIT x86

  • From: Egor Skriptunoff <egor.skriptunoff@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 16 Aug 2018 22:48:17 +0300

On Thu, Aug 16, 2018 at 10:54 AM, Mike Pall wrote:

Egor Skriptunoff wrote:
   local dwords = ffi.typeof("uint32_t[?]")
   local ror = bit.ror

Bit operations have signed results.

         arr[i] = arr[i-2] + ror(arr[i-1], 7)

The result of the addition is a signed double. The conversion to
an unsigned FFI type (implicitly via the assignment) is undefined,
if the result is negative.



Do you mean that in LuaJIT after assigning negative integer value to
uint32_t
the difference between the unsigned result and the original signed number
might be not a multiple of 2^32 ?
It sounds like an unpleasant surprise.

Ok, I replaced ffi.typeof("uint32_t[?]") with ffi.typeof("int32_t[?]").
And 0xDEADBEEF with 0xEADBEEF.
Now all the datatypes are signed and all the constants are inside signed
int32 range.
The bug didn't disappear: a pair of unequal numbers is printed under LuaJIT
x86.

-1051461028
-1295642679

Other related posts: