Alright, time to run some LuaJIT in my RISC-V emulator.
Alright, time to run some LuaJIT in my RISC-V emulator.
function fib(n, acc, prev)
if (n < 1) then
return acc
else
return fib(n - 1, prev + acc, acc)
end
end
print(fib(50, 0, 1))
$ ./rvlinux -P ~/github/LuaRiscvJIT/src/luajit -- test.lua
12586269025
>>> Program exited, exit code = 0 (0x0)
Runtime: 0.281ms (Use --accurate for instruction counting)
Pages in use: 429 (1716 kB virtual memory, total 2674 kB)
It's definitely working!Calling C functions using the old stack API would cause the JIT to abort. In Garrysmod's case, that includes such simple operations as constructing and performing arithmetic on vectors.
So when I was building a high-performance voxel library for Garrysmod, I ended up splitting my hot code into chunks that the JIT compiler would usually be happy with. One fast loop to generate a mesh, then a slow loop to convert that into a mesh structure the engine wants. Very carefully designed methods for bit-packing trees of 12-bit integer voxel data into flat tables of floats.
We ran Lua for the entire core of a game in a 400kb preallocated on the PSP about 20 years ago. I know of many places that used it long before us.