Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hi16[], ha16[], lo16[] support to the PowerPC assembler #45

Merged
merged 9 commits into from
Jan 18, 2017

Conversation

davidgiven
Copy link
Owner

This adds both assembler support and backend linker support for Apple-style hi16[], ha16[], lo16[] expressions which can be used in instructions which take 16-bit constant operands.

This allows more compact instructions when doing things like loads from constant addresses, using syntax like this:

addis r3, r0, ha16[value+88]
lwz r3, r3, lo16[value+88]

Also clean up led a bit for more standard use of system #includes.

…ructions;

this should allow oris/lwz constant value loads, which will save an opcode.
… to ori's

payload being unsigned while lwz's payload is signed.
…having two

assembler directives, ha16() and has16(), for the upper half; has16() applies
the sign adjustment. .powerpcfixup is now gone, as we generate the relocation
in ha*() instead. Add special logic to the linker for undoing and redoing the
sign adjustment when reading/writing fixups. Tests still pass.
accordingly. (Memo to self: read the docs *before* doing the work.)
@davidgiven davidgiven merged commit 1a5c595 into default Jan 18, 2017
@davidgiven davidgiven deleted the dtrg-fixups branch January 18, 2017 19:18
@kernigh
Copy link
Contributor

kernigh commented Feb 1, 2017

This part from mach/powerpc/ncg/table looks wrong:

	pat loi $1==INT32                  /* Load word indirect */
		with LABEL
			uses REG
			gen
				lis %a, {LABEL_HA, %1.adr}
				lwz %a, {GPRINDIRECT_OFFSET_LO, %a, %1.adr}
			yields %a

I believe that we can't yield a register here, because it isn't a token in the MEMORY set. I'm currently thinking about how to rewrite this.

@kernigh
Copy link
Contributor

kernigh commented Feb 1, 2017

My last comment was wrong. We can yield a register because the lwz did read the memory. We don't need to kill the register if we change the value in memory. This is different from a token like IND_RC_W. The token would delay reading the memory, and we would need to kill the token before we changed the value in memory, because we must read the value before we change it.

In fact, we can't yield a token here, because our assembler needs lo16 in the next instruction after ha16. So we can't yield a token that would delay the lo16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants