4 ms·
Some threaded interpreters do this, as it lets you use the return address branch predictor and continue control flow with just a ret.
by saagarjha 5y ago
Some threaded interpreters do this, as it lets you use the return address branch predictor and continue control flow with just a ret.
- KMag 5y agoInteresting! My understanding of efficient direct-threaded interpreters is basically limited to Jones Forth. If I understand you correctly, these interpreters store their lists of subroutines in reverse order, set the stack pointer to the end of the list, and then everywhere jonesforth.s uses "lodsl\njmp *(%eax)" to iterate forward over a list of function pointers pointed to by %edi, these interpreters use "ret" to iterate backward over a list of function pointers pointed to by %esp. Is that correct? I take it these interpreters can't register any signal handlers, as at a minimum, the kernel would write a return address above the stack's "red zone" before invoking the signal handler, which would corrupt the code. Is that right?
- saagarjha 5y agoHere's an example: https://github.com/wishstudio/flinux/wiki/Dynamic-Binary-Translation#return-handling https://github.com/wishstudio/flinux/wiki/Dynamic-Binary-Tra.... You don't have to push everything to the stack, but that's definitely an option–it wouldn't interfere with the red zone because you'd be pushing in the opposite direction.