Skip to content

Branch Optimization II

February 8, 2018

18-02-08 branch analysis blink
I figured out my overall theory and tried it out successfully. The code runs through the expanded assembly a line at a time keeping track of the size of code generated so it always knows the program counter. When it encounters a label it stores it with its address. When it encounters a long branch it checks the target to see if it’s on the same page and if so it converts it to a shot branch. Sometimes the label hasn’t been defined yet so it calls itself recursively starting at the next line looking for that label. The insight, if there is one, is that because I’m always moving forward, shortening a branch will never screw up a decision i’ve already made – it can only move the target closer.

This works, at least for Blink. There were six long branches encountered including the branch to lcc1802init generated by the prolog. I don’t bother with the branch to lcc1802init but the other five were successfully converted to short branches.

Now I need to try a bigger program sample and clean up the code.

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: