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 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.