Skip to content

Commit

Permalink
operand: include '+0' in named symbol references
Browse files Browse the repository at this point in the history
Intended to address an asmdecl error.

  [amd64] Butterfly: use of unnamed argument 0(FP); offset 0 is x0+0(FP)

Updates mmcloughlin#24
  • Loading branch information
mmcloughlin committed Jan 13, 2019
1 parent 16c602d commit 475a241
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 43 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/add/add.s
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/args/args.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/complex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/complex/complex.s
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions examples/data/data.s
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion examples/dot/dot.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/fnv1a/fnv1a.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions examples/geohash/geohash.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions examples/returns/returns.s
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/sha1/sha1.s
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/stadtx/stadtx.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/sum/sum.s
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 4 additions & 6 deletions operand/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion operand/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"},
Expand Down
2 changes: 1 addition & 1 deletion printer/goasm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
2 changes: 1 addition & 1 deletion tests/cast/cast.s
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 475a241

Please sign in to comment.