Zeex / amx_assembly

Interesting #emit stuff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FastJumpTargets

Y-Less opened this issue · comments

So I removed a load of code from codescan because I thought I realised it was pointless, because jumps always adjust the stack before they jump, so the stack at the destination would be correct.

However, codescan doesn't follow code paths, so this code:

PUSH.C 0
; Anything...
JSLESS fail
STACK 4
JUMP after
fail:
STACK 4
after:

Will correctly reset the stack in each code path, but if you just read through the code linearly, you end up with a stack size of -4 (clearly wrong). I was worried there was an issue, which is why I left the code in a branch for so long. Shame I found the issue days after choosing to merge it.

This also deals more correctly with slightly stupid code like:

new a
continue;
continue;
continue;

Each continue will correct the stack by removing a. This is possibly a compiler bug, since it means the stack size is decreased by 12, but really how well should it handle unreachable code? With the slower jump code, this is all done correctly.

I did have some ideas for making the jump targets much faster before I just decided to remove the whole lot. I'll have to try and remember what those ideas were now and implement them. I think it was something to do with sorting them and using a binary search to determine if the current address was a jump target, but for only a few jumps that doesn't sound much faster.