From 475a2414465eeb0c77a798d61ee5332c77116218 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 13 Jan 2019 11:59:14 -0800 Subject: [PATCH] operand: include '+0' in named symbol references Intended to address an asmdecl error. [amd64] Butterfly: use of unnamed argument 0(FP); offset 0 is x0+0(FP) Updates #24 --- README.md | 4 ++-- examples/add/README.md | 2 +- examples/add/add.s | 2 +- examples/args/args.s | 2 +- examples/complex/README.md | 2 +- examples/complex/complex.s | 4 ++-- examples/data/data.s | 6 +++--- examples/dot/dot.s | 2 +- examples/fnv1a/fnv1a.s | 2 +- examples/geohash/geohash.s | 22 +++++++++++----------- examples/returns/returns.s | 14 +++++++------- examples/sha1/sha1.s | 2 +- examples/stadtx/stadtx.s | 2 +- examples/sum/sum.s | 2 +- operand/types.go | 10 ++++------ operand/types_test.go | 2 +- printer/goasm_test.go | 2 +- tests/cast/cast.s | 2 +- 18 files changed, 41 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index 49a5febe..44a804d2 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ After running `go generate` the [`add.s`](examples/add/add.s) file will contain // func Add(x uint64, y uint64) uint64 TEXT ·Add(SB), NOSPLIT, $0-24 - MOVQ x(FP), AX + MOVQ x+0(FP), AX MOVQ y+8(FP), CX ADDQ AX, CX MOVQ CX, ret+16(FP) @@ -137,7 +137,7 @@ The result from this code generator is: // func Sum(xs []uint64) uint64 TEXT ·Sum(SB), NOSPLIT, $0-32 - MOVQ xs_base(FP), AX + MOVQ xs_base+0(FP), AX MOVQ xs_len+8(FP), CX // Initialize sum register to zero. diff --git a/examples/add/README.md b/examples/add/README.md index 38c0d0cc..600ca190 100644 --- a/examples/add/README.md +++ b/examples/add/README.md @@ -43,7 +43,7 @@ This produces [`add.s`](add.s) as follows: // func Add(x uint64, y uint64) uint64 TEXT ·Add(SB), NOSPLIT, $0-24 - MOVQ x(FP), AX + MOVQ x+0(FP), AX MOVQ y+8(FP), CX ADDQ AX, CX MOVQ CX, ret+16(FP) diff --git a/examples/add/add.s b/examples/add/add.s index a5659b0e..08548921 100644 --- a/examples/add/add.s +++ b/examples/add/add.s @@ -4,7 +4,7 @@ // func Add(x uint64, y uint64) uint64 TEXT ·Add(SB), NOSPLIT, $0-24 - MOVQ x(FP), AX + MOVQ x+0(FP), AX MOVQ y+8(FP), CX ADDQ AX, CX MOVQ CX, ret+16(FP) diff --git a/examples/args/args.s b/examples/args/args.s index 1a99d0d1..6d65041b 100644 --- a/examples/args/args.s +++ b/examples/args/args.s @@ -34,7 +34,7 @@ TEXT ·ArrayThree(SB), NOSPLIT, $0-64 // func FieldByte(s Struct) byte TEXT ·FieldByte(SB), NOSPLIT, $0-177 - MOVB s_Byte(FP), AL + MOVB s_Byte+0(FP), AL MOVB AL, ret+176(FP) RET diff --git a/examples/complex/README.md b/examples/complex/README.md index 8c4ce342..81e77553 100644 --- a/examples/complex/README.md +++ b/examples/complex/README.md @@ -25,7 +25,7 @@ Generated assembly: ```s // func Norm(z complex128) float64 TEXT ·Norm(SB), NOSPLIT, $0-24 - MOVSD z_real(FP), X0 + MOVSD z_real+0(FP), X0 MOVSD z_imag+8(FP), X1 MULSD X0, X0 MULSD X1, X1 diff --git a/examples/complex/complex.s b/examples/complex/complex.s index ff4475cf..3084222a 100644 --- a/examples/complex/complex.s +++ b/examples/complex/complex.s @@ -4,7 +4,7 @@ // func Real(z complex128) float64 TEXT ·Real(SB), NOSPLIT, $0-24 - MOVSD z_real(FP), X0 + MOVSD z_real+0(FP), X0 MOVSD X0, ret+16(FP) RET @@ -16,7 +16,7 @@ TEXT ·Imag(SB), NOSPLIT, $0-24 // func Norm(z complex128) float64 TEXT ·Norm(SB), NOSPLIT, $0-24 - MOVSD z_real(FP), X0 + MOVSD z_real+0(FP), X0 MOVSD z_imag+8(FP), X1 MULSD X0, X0 MULSD X1, X1 diff --git a/examples/data/data.s b/examples/data/data.s index 6819c036..7eae0886 100644 --- a/examples/data/data.s +++ b/examples/data/data.s @@ -2,7 +2,7 @@ #include "textflag.h" -DATA bytes<>(SB)/8, $0x0011223344556677 +DATA bytes<>+0(SB)/8, $0x0011223344556677 DATA bytes<>+8(SB)/8, $"strconst" DATA bytes<>+16(SB)/4, $(3.1415927) DATA bytes<>+24(SB)/8, $(3.141592653589793) @@ -14,8 +14,8 @@ GLOBL bytes<>(SB), RODATA|NOPTR, $40 // func DataAt(i int) byte TEXT ·DataAt(SB), NOSPLIT, $0-9 - MOVQ i(FP), AX - LEAQ bytes<>(SB), CX + MOVQ i+0(FP), AX + LEAQ bytes<>+0(SB), CX MOVB (CX)(AX*1), AL MOVB AL, ret+8(FP) RET diff --git a/examples/dot/dot.s b/examples/dot/dot.s index 6dc20955..ac9b2316 100644 --- a/examples/dot/dot.s +++ b/examples/dot/dot.s @@ -4,7 +4,7 @@ // func Dot(x []float32, y []float32) float32 TEXT ·Dot(SB), NOSPLIT, $0-52 - MOVQ x_base(FP), AX + MOVQ x_base+0(FP), AX MOVQ y_base+24(FP), CX MOVQ x_len+8(FP), DX VXORPS Y0, Y0, Y0 diff --git a/examples/fnv1a/fnv1a.s b/examples/fnv1a/fnv1a.s index 85bbd580..29996658 100644 --- a/examples/fnv1a/fnv1a.s +++ b/examples/fnv1a/fnv1a.s @@ -4,7 +4,7 @@ // func Hash64(data []byte) uint64 TEXT ·Hash64(SB), NOSPLIT, $0-32 - MOVQ data_base(FP), CX + MOVQ data_base+0(FP), CX MOVQ data_len+8(FP), BX MOVQ $0xcbf29ce484222325, AX MOVQ $0x00000100000001b3, BP diff --git a/examples/geohash/geohash.s b/examples/geohash/geohash.s index c14d6f51..0344b37b 100644 --- a/examples/geohash/geohash.s +++ b/examples/geohash/geohash.s @@ -4,31 +4,31 @@ // func EncodeInt(lat float64, lng float64) uint64 TEXT ·EncodeInt(SB), NOSPLIT, $0-24 - MOVSD lat(FP), X0 + MOVSD lat+0(FP), X0 MOVSD lng+8(FP), X1 - MULSD reciprocal180<>(SB), X0 - ADDSD onepointfive<>(SB), X0 - MULSD reciprocal360<>(SB), X1 - ADDSD onepointfive<>(SB), X1 + MULSD reciprocal180<>+0(SB), X0 + ADDSD onepointfive<>+0(SB), X0 + MULSD reciprocal360<>+0(SB), X1 + ADDSD onepointfive<>+0(SB), X1 MOVQ X0, CX SHRQ $0x14, CX MOVQ X1, AX SHRQ $0x14, AX - PDEPQ mask<>(SB), CX, CX - PDEPQ mask<>(SB), AX, AX + PDEPQ mask<>+0(SB), CX, CX + PDEPQ mask<>+0(SB), AX, AX SHLQ $0x01, AX XORQ AX, CX MOVQ CX, ret+16(FP) RET -DATA reciprocal180<>(SB)/8, $(0.005555555555555556) +DATA reciprocal180<>+0(SB)/8, $(0.005555555555555556) GLOBL reciprocal180<>(SB), RODATA|NOPTR, $8 -DATA onepointfive<>(SB)/8, $(1.5) +DATA onepointfive<>+0(SB)/8, $(1.5) GLOBL onepointfive<>(SB), RODATA|NOPTR, $8 -DATA reciprocal360<>(SB)/8, $(0.002777777777777778) +DATA reciprocal360<>+0(SB)/8, $(0.002777777777777778) GLOBL reciprocal360<>(SB), RODATA|NOPTR, $8 -DATA mask<>(SB)/8, $0x5555555555555555 +DATA mask<>+0(SB)/8, $0x5555555555555555 GLOBL mask<>(SB), RODATA|NOPTR, $8 diff --git a/examples/returns/returns.s b/examples/returns/returns.s index 23751f28..cd30ca5f 100644 --- a/examples/returns/returns.s +++ b/examples/returns/returns.s @@ -4,7 +4,7 @@ // func Interval(start uint64, size uint64) (uint64, uint64) TEXT ·Interval(SB), NOSPLIT, $0-32 - MOVQ start(FP), AX + MOVQ start+0(FP), AX MOVQ size+8(FP), CX ADDQ AX, CX MOVQ AX, ret+16(FP) @@ -13,7 +13,7 @@ TEXT ·Interval(SB), NOSPLIT, $0-32 // func Butterfly(x0 float64, x1 float64) (y0 float64, y1 float64) TEXT ·Butterfly(SB), NOSPLIT, $0-32 - MOVSD x0(FP), X0 + MOVSD x0+0(FP), X0 MOVSD x1+8(FP), X1 MOVSD X0, X2 ADDSD X1, X2 @@ -25,7 +25,7 @@ TEXT ·Butterfly(SB), NOSPLIT, $0-32 // func Septuple(byte) [7]byte TEXT ·Septuple(SB), NOSPLIT, $0-15 - MOVB arg(FP), AL + MOVB arg+0(FP), AL MOVB AL, ret_0+8(FP) MOVB AL, ret_1+9(FP) MOVB AL, ret_2+10(FP) @@ -37,18 +37,18 @@ TEXT ·Septuple(SB), NOSPLIT, $0-15 // func CriticalLine(t float64) complex128 TEXT ·CriticalLine(SB), NOSPLIT, $0-24 - MOVSD t(FP), X0 - MOVSD half<>(SB), X1 + MOVSD t+0(FP), X0 + MOVSD half<>+0(SB), X1 MOVSD X1, ret_real+8(FP) MOVSD X0, ret_imag+16(FP) RET -DATA half<>(SB)/8, $(0.5) +DATA half<>+0(SB)/8, $(0.5) GLOBL half<>(SB), RODATA|NOPTR, $8 // func NewStruct(w uint16, p [2]float64, q uint64) Struct TEXT ·NewStruct(SB), NOSPLIT, $0-64 - MOVW w(FP), AX + MOVW w+0(FP), AX MOVSD p_0+8(FP), X0 MOVSD p_1+16(FP), X1 MOVQ q+24(FP), CX diff --git a/examples/sha1/sha1.s b/examples/sha1/sha1.s index 518372db..3dbca55c 100644 --- a/examples/sha1/sha1.s +++ b/examples/sha1/sha1.s @@ -2,7 +2,7 @@ // func block(h *[5]uint32, m []byte) TEXT ·block(SB), $64-32 - MOVQ h(FP), AX + MOVQ h+0(FP), AX MOVQ m_base+8(FP), CX // Load initial hash. diff --git a/examples/stadtx/stadtx.s b/examples/stadtx/stadtx.s index c8b542a4..e940d19c 100644 --- a/examples/stadtx/stadtx.s +++ b/examples/stadtx/stadtx.s @@ -4,7 +4,7 @@ // func Hash(state *State, key []byte) uint64 TEXT ·Hash(SB), NOSPLIT, $0-40 - MOVQ state(FP), AX + MOVQ state+0(FP), AX MOVQ key_base+8(FP), CX MOVQ key_len+16(FP), DX MOVQ (AX), BX diff --git a/examples/sum/sum.s b/examples/sum/sum.s index 94cec5bb..fdce40c1 100644 --- a/examples/sum/sum.s +++ b/examples/sum/sum.s @@ -4,7 +4,7 @@ // func Sum(xs []uint64) uint64 TEXT ·Sum(SB), NOSPLIT, $0-32 - MOVQ xs_base(FP), AX + MOVQ xs_base+0(FP), AX MOVQ xs_len+8(FP), CX // Initialize sum register to zero. diff --git a/operand/types.go b/operand/types.go index f8cd9562..3ca07e4b 100644 --- a/operand/types.go +++ b/operand/types.go @@ -87,12 +87,10 @@ func (m Mem) Idx(r reg.Register, s uint8) Mem { // Asm returns an assembly syntax representation of m. func (m Mem) Asm() string { a := m.Symbol.String() - if m.Disp != 0 { - if a == "" { - a += fmt.Sprintf("%d", m.Disp) - } else { - a += fmt.Sprintf("%+d", m.Disp) - } + if a != "" { + a += fmt.Sprintf("%+d", m.Disp) + } else if m.Disp != 0 { + a += fmt.Sprintf("%d", m.Disp) } if m.Base != nil { a += fmt.Sprintf("(%s)", m.Base.Asm()) diff --git a/operand/types_test.go b/operand/types_test.go index 3154fad0..1274e360 100644 --- a/operand/types_test.go +++ b/operand/types_test.go @@ -37,7 +37,7 @@ func TestMemAsm(t *testing.T) { {Mem{Base: reg.R11, Index: reg.RAX}, "(R11)"}, {Mem{Base: reg.R11, Scale: 8}, "(R11)"}, {Mem{Disp: 2048, Base: reg.R11, Index: reg.RAX, Scale: 8}, "2048(R11)(AX*8)"}, - {Mem{Symbol: Symbol{Name: "foo"}, Base: reg.StaticBase}, "foo(SB)"}, + {Mem{Symbol: Symbol{Name: "foo"}, Base: reg.StaticBase}, "foo+0(SB)"}, {Mem{Symbol: Symbol{Name: "foo"}, Base: reg.StaticBase, Disp: 4}, "foo+4(SB)"}, {Mem{Symbol: Symbol{Name: "foo"}, Base: reg.StaticBase, Disp: -7}, "foo-7(SB)"}, {Mem{Symbol: Symbol{Name: "bar", Static: true}, Base: reg.StaticBase, Disp: 4, Index: reg.R11, Scale: 4}, "bar<>+4(SB)(R11*4)"}, diff --git a/printer/goasm_test.go b/printer/goasm_test.go index f03c2860..207a8b23 100644 --- a/printer/goasm_test.go +++ b/printer/goasm_test.go @@ -24,7 +24,7 @@ func TestBasic(t *testing.T) { "", "// func add(x uint64, y uint64) uint64", "TEXT ·add(SB), $0-24", - "\tMOVQ x(FP), AX", + "\tMOVQ x+0(FP), AX", "\tMOVQ y+8(FP), R9", "\tADDQ AX, R9", "\tMOVQ R9, ret+16(FP)", diff --git a/tests/cast/cast.s b/tests/cast/cast.s index 9af73536..7b4e5adf 100644 --- a/tests/cast/cast.s +++ b/tests/cast/cast.s @@ -4,7 +4,7 @@ // func Split(x uint64) (q uint64, l uint32, w uint16, b uint8) TEXT ·Split(SB), NOSPLIT, $0-23 - MOVQ x(FP), AX + MOVQ x+0(FP), AX MOVQ AX, q+8(FP) MOVL AX, l+16(FP) MOVW AX, w+20(FP)