3 ms·
The coolest interpreter technique I saw was one that put instruction bodies in static functions which the "compiler" main loop would memcpy the body of the func
by beholdo 2mo ago
The coolest interpreter technique I saw was one that put instruction bodies in static functions which the "compiler" main loop would memcpy the body of the function out to straight-line code that would be executed from memory - a poor man's jit. All instruction functions had the same args and gcc would emit position independent code with the same predictable register calling convention. Brittle as hell, sure, but great compilation speed with low run-time overhead. It was able to run interpreted code at 1/5th of compiled code speed, compared to 1/10th speed for typical highly optimized computed goto loop interpreters.
I can't find a link, but if anyone recalls or wrote such an jit interpreter, please post.
- scheme271 2mo agoSounds like a copy and patch JIT ( https://en.wikipedia.org/wiki/Copy-and-patch https://en.wikipedia.org/wiki/Copy-and-patch ). The python interpreter was experimenting with this and it provides a decent speedup.
- ack_complete 2mo agoOdd that the Wikipedia article gives 2021 as the first description of this technique when it is far, far older than that. I worked with a software rasterizer JIT that used it in ~2003 and I thought similar techniques were used in the classic MacOS m68k emulator on PowerPC.
- scheme271 2mo agoYeah, I think it was in use before. The wiki article is probably incorrect in the 2021 date.
- kijiki 2mo agoqemu used to use that technique, but as you note, it was pretty brittle. They switched to the more traditional TCG backend.
- shuklaayush 2mo agoNeat, I guess this gets you the same output as a per-instruction translator without having to run an assembler and linker over the whole program. I should try this and add it to the post for completeness