Skip to content

Commit

Permalink
liblink: generate correct code for MOVD $-n(Rm), x on ppc64
Browse files Browse the repository at this point in the history
On ppc64, liblink rewrites MOVD's of >32-bit constants by putting the
constant in memory and rewriting the MOVD to load from that memory
address.  However, there were two bugs in the condition:

a) owing to an incorrect sign extension, it triggered for all negative
   constants, and

b) it could trigger for constant offsets from registers (addresses of
   the form $n(Rm) in assembly)

Together, these meant instructions of the form MOVD $-n(Rm), x were
compiled by putting -n in memory and rewriting the MOVD to load this
constant from memory (completely dropping Rm).

Change-Id: I1f6cc980efa3e3d6f164b46c985b2c3b55971cca
Reviewed-on: https://go-review.googlesource.com/1752
Reviewed-by: Minux Ma <[email protected]>
  • Loading branch information
aclements committed Dec 18, 2014
1 parent e0e1cee commit b21e936
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/cmd/9l/9.out.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ enum
C_ANDCON, /* 0 < v <= 0xFFFF */
C_LCON, /* other 32 */
C_DCON, /* other 64 (could subdivide further) */
C_SACON,
C_SACON, /* $n(REG) where n is small */
C_SECON,
C_LACON,
C_LACON, /* $n(REG) where n is large */
C_LECON,
C_SBRA,
C_LBRA,
Expand Down
3 changes: 2 additions & 1 deletion src/liblink/obj9.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ progedit(Link *ctxt, Prog *p)
}
break;
case AMOVD:
if(p->from.type == D_CONST && p->from.name == D_NONE && (int64)(uint32)p->from.offset != p->from.offset) {
// Put >32-bit constants in memory and load them
if(p->from.type == D_CONST && p->from.name == D_NONE && p->from.reg == NREG && (int32)p->from.offset != p->from.offset) {
sprint(literal, "$i64.%016llux", (uvlong)p->from.offset);
s = linklookup(ctxt, literal, 0);
s->size = 8;
Expand Down

0 comments on commit b21e936

Please sign in to comment.