[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: [LuaJIT] JIT bug when passing many function arguments?
- From: Adam Strzelecki <ono@...>
- Date: Tue, 7 Feb 2012 23:23:32 +0100
During playing with different methods of multiplying 4x4 matrices in LuaJIT, I think I encountered strange problem with JIT. I got mmul function that takes 2x16 = 32 arguments and returns 16 arguments - multiplying two 4x4 matrices. See attached source code.
For testing I am multiplying A = A * B, where A is initially identity matrix) and B is PI/2 rotation matrix. Every 4 iterations A should be back to identity, however when JIT kicks in then a11 mysteriously changes to 0 (ZERO) and remains 0, when I turn off JIT the result is just fine I got identity every 4 iterations.
$ luajit -joff luajit-mmul.lua
done in 0.000395 seconds
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
$ luajit -jon luajit-mmul.lua
done in 0.000219 seconds
0 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Also there's something weird in this example, if I set iter=20000000 (20 million) then it needs below <0.5 second to complete whole loop, when GCC compiled example using SSE intrinsics needs over 2 seconds to do the same and intrinsics free implementation needs over 2.2 seconds.
FYI I have also LuaJIT FFI struct based implementation using MT operators and it needs over 5 seconds to do 20 million iterations (probably due allocations discussed on other thread) but that implementation has no such JIT problem.
--
Adam Strzelecki
Attachment:
luajit-mmul.lua
Description: Binary data