I wish there was better documentation for DynASM. I wonder what cool programming projects would be created if DynASM was better known and better documented.
[1] http://blog.reverberate.org/2012/12/hello-jit-world-joy-of-s...
"The Unofficial DynASM Documentation" by Peter Cawley is not to be missed: https://corsix.github.io/dynasm-doc/
Using DynASM itself was smooth sailing. It is officially undocumented, but like the site says, the code is sufficiently well commented.
Generating simple-minded machine code is easy enough (in my opinion) and the results run decently fast.
I didn't integrate run-time generated functions with exceptions and debugging (host language was C++). These areas seemed very sparsely documented (exceedingly sparsely, IIRC, for 64bit Windows) and looked like they would eat more work than everything else up to that point.
So if you're in the market for a lightweight JIT engine and target C++/X86, I'd give Xbyak a whirl too and see which one you like better.
It doesn't care how you call a function, it doesn't even care about 2 or 3 address op syntax. All it does is adding simple template logic to let you handle the platform-specific abstractions by yourself.
And in the end it's easier to add your own prologue or prepcall1 macro, than relying on a library.
people always looked at the "most portable jit library". dynasm offers no platform support per se, as all the others do. you have to do by yourself. it's the least portable of all. but in the end it was much more powerful, and offered the most ports. you get the asm anyway by dissambling the target function. with the libraries (such as LLVM) you'd need to translate a high-level overview to the library API. with dynasm you just need to adjust your types, prologue, struct field accesses and epilogue. and dynasm is perfect and practical in doing this, whilst the other libraries try do to much more, with much more handholding and are much bigger and less effective.
I don't agree with the genius part though. lua itself was pretty much perfect already, and lua took most of the good parts from earlier dynamic languages, lisp and self, and esp. Inferno's "Dis VM". http://doc.cat-v.org/inferno/4th_edition/dis_VM_specificatio... which was Lucent's faster and smaller competitor of Sun's stack-based and GC-heavy JVM. it just missed besides a jit a good OO, and luajit didn't add that neither. e.g. _why the lucky stiff added a nice OO layer on top of lua, plus a nice simple jit. much simplier than luajit.
luajit just objected to some questionable decisions in lua regarding performance, and then took over. esp. nan tagging makes a lot of sense, but the compiler optimizations are also pretty cool. esp. when compared to the massive LLVM overhead.
luajit is using the slower and bigger 3-address SSA and the optimizations based on that. but the CPU and the lua bytecode is just using the fast and natural two address op syntax, where it is not easy to add SSA. This is the genius part. http://wiki.luajit.org/SSA-IR-2.0
Thanks in advance for any explanation. I'm clearly missing something that should be obvious.
Valgrind operates like this. Instrument the allocation routines and with tracking of pointer variables you can detect dangling pointers and overflows and leaks and so on.
Also, it isn't that hard to pick up the basics of assembly, the main reasons it's not common anymore is tedium of writing code in assembly, and not being as portable as higher level languages.
A couple interesting links about the internals:
So unlike those languages Lua can really be considered "done". Version 5.2 was a lot like C99, maybe people considered one or two features "nice to have" but most Lua programmers saw no need to upgrade. Others like Mike Pall even considered 5.2 inferior to 5.1.
Now we have 5.3 which is really all about one special-purpose feature: 64 bit integers. That is a feature most Lua users do not need and it comes with a massive complexity and performance price tag.
Unless you really need 64 bit integer math in your scripts 5.3 is the inferior language.
I really enjoy that in classic Lua a number is a number, that is such a relief compared to the hell that is C's countless numeric types and all the potential bugs resulting from (silent) conversions between them. Lua 5.3 brought that problem to Lua e.g.
a = 9223372036854775000
b = 0.5
c = a + b
c = c - b
print(c) // 9.2233720368548e+18
The third line silently converts a 64-bit integer variable to a 64-bit floating point variable, corrupting its value.And of course Lua 5.3 is slower and needs more memory because of the additional complexity which must be handled.
Thanks but no thanks.
I mean Lua 5.3 still makes sense if you really need 64-bit integers in your Lua scripts. But otherwise it is a downgrade.
I have little experience in lua myself, and I know only that lua is meant to be a simple language. That said, I can't see from your example what's wrong with lua5.3. I ran the same code with lua5.1, lua5.2, and lua5.3 – and the output was identical across all:
$ diff <(lua5.1 numcheck.lua) <(lua5.3 numcheck.lua)
$ diff <(lua5.2 numcheck.lua) <(lua5.3 numcheck.lua)
$In Lua < 5.3 the value is immediately corrupted (check the value of 'a' after the initial assignment) and static analysis can detect that line as a bug.
In contrast in Lua 5.3 it is perfectly fine code and the value of 'a' will be 9223372036854775000 as one would expect. However the moment you - maybe accidentally - mix that int64 variable with a float64 variable in an expression you end up with a (silent) bug.
Such bugs will happen. They happen all the time in C and in Lua's case things are even worse because function parameters do not have types. The possibilities of hard to find, nasty bugs are endless here. E.g. simply forgetting the second '/' in '//' in one part of the program can cause bugs in a completely different part, maybe even in a third party module, and only under certain circumstances.
/ducks
He also criticized 128 bits interpreter values mandated by the support of 64 bits integer in v5.3. These take twice as much cache space and damage performance.
I don't have enough context to know if breaking backwards compatibility is justified or not. I generally think it's a poor decision that's hostile to developers to break backwards compatibility in a programming language without providing a clear migration path. Issues between 5.1, 5.2, and 5.3 definitely seem to have splintered the community.
There was a very good reason for this change, which is that Lua introduced an integer type instead of using floating point numbers for everything. This means that LUA_NUMBER_DOUBLE and LUA_NUMBER_FLOAT do not really make sense anymore (when you check those you may want to check the type of the integer numbers or the type of the floating-point numbers).
In any case, porting luabitop doesn't really matter that much: if LuaJIT supported Lua 5.3 people would use the native 64 bit bitwise operators it introduced instead.
[1]: http://tarantool.org/ [2]: https://github.com/tarantool/luajit
P.S. there are shortcoming plans to establish a non-profit foundation to continue development of LuaJIT.
// Disclaimer, I'm a contributor of [1]