use scaled addressing in preference to unscaled where possible #233
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This patch changes the address generation plan for AArch64 to use scaled displacement addressing in preference to unscaled displacement addressing. It's only a cosmetic change since neither is better than the other in terms of how the code executes, yet it seems cosmetics do have a point.
Why?
Unscaled addressing generates an instruction ldur xr, [xm,#nnn] where nnn is a 9-bit signed unscaled displacement (offsets from -2^9 inclusive up to 2^9 exclusive). Scaled addressing generates an instruction ldr xr, [xm, #nnn] where nnn is a 12 bit unsigned scaled displacement (i.e. byte offsets up to 2^12, qword aligned offsets up to 2^15). For any positive nnn value fitting into 8 bits there is no difference between the two instructions except for the presence of ldur/ldr. Outside that range (negative <= 2^9 or positive between 2^9 and 2^15) there is no option to choose between ldr or ldur.
Stack loads and object field loads always use a positive displacement. So, with the present preference offsets which can be embedded as displacements switch generation from employing ldur to ldr when the (scaled) displacement exceeds the 8 bit limit. Changing the address plan to prefer scaled addressing means that all stack and object loads which can use a displacement are generated as ldr, making it easier to read generated code.
Testing:
All unit tests pass after this change. I also ran netbeans as a smoke test and encountered no problems.