News for hackers. Stuff that matters.
Re:Wasm3 – A high performance WebAssembly interpreter in C by thermals on Monday January 13, 2020 @04:52AM (#22033128)
Yeah, this is a good way to design a fast interpreter! It's traditionally called a "threaded interpreter", or (somewhat confusingly) "threaded code":

https://en.wikipedia.org/wiki/Threaded_code

http://www.complang.tuwien.ac.at/forth/threaded-code.html

You can see an example of this particular implementation style (where each operation is a tail call to a C function, passing the registers as arguments) at the second link above, under "continuation-passing style".

One of the big advantages of a threaded interpreter is relatively good branch prediction. A simple switch-based dispatch loop has a single indirect jump at its core, which is almost entirely unpredictable -- whereas threaded dispatch puts a copy of that indirect jump at the end of each opcode's implementation, giving the branch predictor way more data to work with. Effectively, you're letting it use the current opcode to help predict the next opcode!

Re:Wasm3 – A high performance WebAssembly interpreter in C by vshymanskyy on Monday January 13, 2020 @07:55AM (#22034000)
Yeah, but... It's not only the "threaded code" approach, that makes Wasm3 so fast. In fact, Intel's WAMR also utilizes this method, yet is 30 times slower..
Re:Wasm3 – A high performance WebAssembly interpreter in C by sound_and_form on Tuesday January 14, 2020 @07:17PM (#22050613)
Thanks for the links! I've long searched google trying to find a similar "tail-cail" interpreter. No wonder I couldn't hit anything -- it was so poorly named! :)