Re: Probably a bug in LuaJIT x86

  • From: Daurnimator <quae@xxxxxxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 16 Aug 2018 13:19:00 +1000

On 16 August 2018 at 11:41, Sean Conner <sean@xxxxxxxxxx> wrote:

It was thus said that the Great Egor Skriptunoff once stated:
Hi!

The function f() is deterministic, but its result is changing when run on
LuaJIT x86.

   local ffi = require "ffi"
   local dwords = ffi.typeof("uint32_t[?]")
   local ror = bit.ror

   local function f()

      local arr = dwords(100, 0xDEADBEEF)
      for i = 2, 99 do
         arr[i] = arr[i-2] + ror(arr[i-1], 7)
      end

  I would like to say that arr[0] and arr[1] have undefined values.  So
going through some the first spots:

        arr[0] = ??
        arr[1] = ??
        arr[2] = ?? + ror(??,7)

  I think this is where your odd behavior stems from.

The array (of 100 elements) is initialised to 0xDEADBEEF.
From https://luajit.org/ext_ffi_semantics.html#init
The elements of an array are initialized, starting at index zero. If a single 
initializer is given for an array, it's repeated for all remaining elements. 
This doesn't happen if two or more initializers are given: all remaining 
uninitialized elements are filled with zero bytes.

Other related posts: