I just did THE COOLEST PIECE OF CODE I ever written!
I just did a new build I'm testing of the dynarec, that is now completely "threaded", meaning it NEVER leaves the function, instead, jumping around within it. The cool thing is, this function is RECOMPILED! That means I have the code regenerating itself in its buffer and jumping within it, calling the recompile function when not cached filling in it's own buffer! It's giving slight speedup's already after 30 minutes of work!
Imagine it like this, you have a buffer containing a magical ABCD:
A - B - C - D
A is the recompiled "function" that handles the calling of the recompile function.
B is the first recompiled function spot.
C is empty.
D is empty.
The recompile function is called, and B is filled in. At the end of B the recompiled instructions check if it's next instruction after the branch is cached or not, if it is branch to it, if not, call A.
B is executed, this is the only time this buffer will be executed from "C".
B runs, and finds that nothings cached, so it calls A.
A recompiles and fills in C. C is then branched to.
The next branch is cached, so it jumps to it at B.
B then branches and needs recompiles so it calls A.
A then fills in D and jumps to it.
D runs and is out of memory so unfortunately B, C, and, D will be no longer cached, and can be filled in and the above is repeated infinitely.
So I made myself happy with this project, I wrote code that I never thought was even possible, a threaded dynarec.