January 2018

S M T W T F S
  123456
78910111213
14151617181920
21222324252627
28293031   

Style Credit

Expand Cut Tags

No cut tags
Monday, May 30th, 2011 06:44 pm
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.
Monday, May 30th, 2011 09:37 pm (UTC)
Genius :-)
Monday, May 30th, 2011 09:54 pm (UTC)
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.
Tuesday, May 31st, 2011 11:35 am (UTC)
Do you go back and rewrite once you know whether the jump distance is within the limit?
Wednesday, June 1st, 2011 09:20 am (UTC)
Not yet, but that's a possibility (and probably an easier one than accurately calculating the jump distance ahead-of-time). Thanks!