pozorvlak: (Default)
pozorvlak ([personal profile] pozorvlak) wrote2011-05-30 06:44 pm

(no subject)

I have just written the following commit message:
"Branch over unconditional jump" hack for arbitrary-length brcc.
    
 - brcc (branch and compare) instructions can have static branch-prediction
   hints, but can only jump a limited distance.
 - Calculating the distance of a jump at expand-time is hard.
 - So instead of emitting just a brcc instruction, we emit an unconditional
   jump to the same place and a branch over it.
 - I added a simple counter to emit/state to number the labels thus introduced.
 - With this commit, I forfeit all right to criticise the hackiness of anyone
   else's code.
 - Though I doubt that will stop me.

[identity profile] necaris.livejournal.com 2011-05-30 09:37 pm (UTC)(link)
Genius :-)

[identity profile] pozorvlak.livejournal.com 2011-05-30 09:54 pm (UTC)(link)
Thanks!

I should point out that the blame credit for the "branch over unconditional jump" trick properly belongs to [livejournal.com profile] aaroncrane. The idea to do it all in the assembly-emission pass (rather than, say, doing it in IR and fixing up the control-flow graph accordingly) was all mine, though. As was the decision to create a new L_BRCC_HACK goto-label family (using raw printfs) rather than trying to work out how to access the existing label-creation system.

[identity profile] gareth-rees.livejournal.com 2011-05-31 11:35 am (UTC)(link)
Do you go back and rewrite once you know whether the jump distance is within the limit?

[identity profile] pozorvlak.livejournal.com 2011-06-01 09:20 am (UTC)(link)
Not yet, but that's a possibility (and probably an easier one than accurately calculating the jump distance ahead-of-time). Thanks!