Skip to content

Commit

Permalink
build: add attributes argument to TEXT
Browse files Browse the repository at this point in the history
Brings the TEXT() function signature closer to how the directive works
in assembly.

Also update almost all examples to use NOSPLIT.

Closes mmcloughlin#11
  • Loading branch information
mmcloughlin committed Jan 7, 2019
1 parent 76db5bb commit 304c742
Show file tree
Hide file tree
Showing 25 changed files with 105 additions and 72 deletions.
17 changes: 17 additions & 0 deletions build/attr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package build

import "github.com/mmcloughlin/avo/attr"

// TEXT and DATA attribute values included for convenience.
var (
NOPROF = attr.NOPROF
DUPOK = attr.DUPOK
NOSPLIT = attr.NOSPLIT
RODATA = attr.RODATA
NOPTR = attr.NOPTR
WRAPPER = attr.WRAPPER
NEEDCTXT = attr.NEEDCTXT
TLSBSS = attr.TLSBSS
NOFRAME = attr.NOFRAME
REFLECTMETHOD = attr.REFLECTMETHOD
)
5 changes: 3 additions & 2 deletions build/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import (
// ctx provides a global build context.
var ctx = NewContext()

// TEXT starts building a new function called name and sets its signature (see SignatureExpr).
func TEXT(name, signature string) {
// TEXT starts building a new function called name, with attributes a, and sets its signature (see SignatureExpr).
func TEXT(name string, a attr.Attribute, signature string) {
ctx.Function(name)
ctx.Attributes(a)
ctx.SignatureExpr(signature)
}

Expand Down
4 changes: 3 additions & 1 deletion examples/add/add.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Code generated by command: go run asm.go -out add.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Add(x uint64, y uint64) uint64
TEXT ·Add(SB), $0-24
TEXT ·Add(SB), NOSPLIT, $0-24
MOVQ x(FP), AX
MOVQ y+8(FP), CX
ADDQ AX, CX
Expand Down
2 changes: 1 addition & 1 deletion examples/add/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func main() {
TEXT("Add", "func(x, y uint64) uint64")
TEXT("Add", NOSPLIT, "func(x, y uint64) uint64")
Doc("Add adds x and y.")
x := Load(Param("x"), GP64())
y := Load(Param("y"), GP64())
Expand Down
38 changes: 20 additions & 18 deletions examples/args/args.s
Original file line number Diff line number Diff line change
@@ -1,109 +1,111 @@
// Code generated by command: go run asm.go -out args.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Second(x int32, y int32) int32
TEXT ·Second(SB), $0-12
TEXT ·Second(SB), NOSPLIT, $0-12
MOVL y+4(FP), AX
MOVL AX, ret+8(FP)
RET

// func StringLen(s string) int
TEXT ·StringLen(SB), $0-24
TEXT ·StringLen(SB), NOSPLIT, $0-24
MOVQ s_len+8(FP), AX
MOVQ AX, ret+16(FP)
RET

// func SliceLen(s []int) int
TEXT ·SliceLen(SB), $0-32
TEXT ·SliceLen(SB), NOSPLIT, $0-32
MOVQ s_len+8(FP), AX
MOVQ AX, ret+24(FP)
RET

// func SliceCap(s []int) int
TEXT ·SliceCap(SB), $0-32
TEXT ·SliceCap(SB), NOSPLIT, $0-32
MOVQ s_cap+16(FP), AX
MOVQ AX, ret+24(FP)
RET

// func ArrayThree(a [7]uint64) uint64
TEXT ·ArrayThree(SB), $0-64
TEXT ·ArrayThree(SB), NOSPLIT, $0-64
MOVQ a_3+24(FP), AX
MOVQ AX, ret+56(FP)
RET

// func FieldByte(s Struct) byte
TEXT ·FieldByte(SB), $0-177
TEXT ·FieldByte(SB), NOSPLIT, $0-177
MOVB s_Byte(FP), AL
MOVB AL, ret+176(FP)
RET

// func FieldInt8(s Struct) int8
TEXT ·FieldInt8(SB), $0-177
TEXT ·FieldInt8(SB), NOSPLIT, $0-177
MOVB s_Int8+1(FP), AL
MOVB AL, ret+176(FP)
RET

// func FieldUint16(s Struct) uint16
TEXT ·FieldUint16(SB), $0-178
TEXT ·FieldUint16(SB), NOSPLIT, $0-178
MOVW s_Uint16+2(FP), AX
MOVW AX, ret+176(FP)
RET

// func FieldInt32(s Struct) int32
TEXT ·FieldInt32(SB), $0-180
TEXT ·FieldInt32(SB), NOSPLIT, $0-180
MOVL s_Int32+4(FP), AX
MOVL AX, ret+176(FP)
RET

// func FieldUint64(s Struct) uint64
TEXT ·FieldUint64(SB), $0-184
TEXT ·FieldUint64(SB), NOSPLIT, $0-184
MOVQ s_Uint64+8(FP), AX
MOVQ AX, ret+176(FP)
RET

// func FieldFloat32(s Struct) float32
TEXT ·FieldFloat32(SB), $0-180
TEXT ·FieldFloat32(SB), NOSPLIT, $0-180
MOVSS s_Float32+16(FP), X0
MOVSS X0, ret+176(FP)
RET

// func FieldFloat64(s Struct) float64
TEXT ·FieldFloat64(SB), $0-184
TEXT ·FieldFloat64(SB), NOSPLIT, $0-184
MOVSD s_Float64+24(FP), X0
MOVSD X0, ret+176(FP)
RET

// func FieldStringLen(s Struct) int
TEXT ·FieldStringLen(SB), $0-184
TEXT ·FieldStringLen(SB), NOSPLIT, $0-184
MOVQ s_String_len+40(FP), AX
MOVQ AX, ret+176(FP)
RET

// func FieldSliceCap(s Struct) int
TEXT ·FieldSliceCap(SB), $0-184
TEXT ·FieldSliceCap(SB), NOSPLIT, $0-184
MOVQ s_Slice_cap+64(FP), AX
MOVQ AX, ret+176(FP)
RET

// func FieldArrayTwoBTwo(s Struct) byte
TEXT ·FieldArrayTwoBTwo(SB), $0-177
TEXT ·FieldArrayTwoBTwo(SB), NOSPLIT, $0-177
MOVB s_Array_2_B_2+114(FP), AL
MOVB AL, ret+176(FP)
RET

// func FieldArrayOneC(s Struct) uint16
TEXT ·FieldArrayOneC(SB), $0-178
TEXT ·FieldArrayOneC(SB), NOSPLIT, $0-178
MOVW s_Array_1_C+100(FP), AX
MOVW AX, ret+176(FP)
RET

// func FieldComplex64Imag(s Struct) float32
TEXT ·FieldComplex64Imag(SB), $0-180
TEXT ·FieldComplex64Imag(SB), NOSPLIT, $0-180
MOVSS s_Complex64_imag+156(FP), X0
MOVSS X0, ret+176(FP)
RET

// func FieldComplex128Real(s Struct) float64
TEXT ·FieldComplex128Real(SB), $0-184
TEXT ·FieldComplex128Real(SB), NOSPLIT, $0-184
MOVSD s_Complex128_real+160(FP), X0
MOVSD X0, ret+176(FP)
RET
36 changes: 18 additions & 18 deletions examples/args/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,92 +9,92 @@ import (
func main() {
Package("github.com/mmcloughlin/avo/examples/args")

TEXT("Second", "func(x, y int32) int32")
TEXT("Second", NOSPLIT, "func(x, y int32) int32")
y := Load(Param("y"), GP32())
Store(y, ReturnIndex(0))
RET()

TEXT("StringLen", "func(s string) int")
TEXT("StringLen", NOSPLIT, "func(s string) int")
strlen := Load(Param("s").Len(), GP64())
Store(strlen, ReturnIndex(0))
RET()

TEXT("SliceLen", "func(s []int) int")
TEXT("SliceLen", NOSPLIT, "func(s []int) int")
slicelen := Load(Param("s").Len(), GP64())
Store(slicelen, ReturnIndex(0))
RET()

TEXT("SliceCap", "func(s []int) int")
TEXT("SliceCap", NOSPLIT, "func(s []int) int")
slicecap := Load(Param("s").Cap(), GP64())
Store(slicecap, ReturnIndex(0))
RET()

TEXT("ArrayThree", "func(a [7]uint64) uint64")
TEXT("ArrayThree", NOSPLIT, "func(a [7]uint64) uint64")
a3 := Load(Param("a").Index(3), GP64())
Store(a3, ReturnIndex(0))
RET()

TEXT("FieldByte", "func(s Struct) byte")
TEXT("FieldByte", NOSPLIT, "func(s Struct) byte")
b := Load(Param("s").Field("Byte"), GP8())
Store(b, ReturnIndex(0))
RET()

TEXT("FieldInt8", "func(s Struct) int8")
TEXT("FieldInt8", NOSPLIT, "func(s Struct) int8")
i8 := Load(Param("s").Field("Int8"), GP8())
Store(i8, ReturnIndex(0))
RET()

TEXT("FieldUint16", "func(s Struct) uint16")
TEXT("FieldUint16", NOSPLIT, "func(s Struct) uint16")
u16 := Load(Param("s").Field("Uint16"), GP16())
Store(u16, ReturnIndex(0))
RET()

TEXT("FieldInt32", "func(s Struct) int32")
TEXT("FieldInt32", NOSPLIT, "func(s Struct) int32")
i32 := Load(Param("s").Field("Int32"), GP32())
Store(i32, ReturnIndex(0))
RET()

TEXT("FieldUint64", "func(s Struct) uint64")
TEXT("FieldUint64", NOSPLIT, "func(s Struct) uint64")
u64 := Load(Param("s").Field("Uint64"), GP64())
Store(u64, ReturnIndex(0))
RET()

TEXT("FieldFloat32", "func(s Struct) float32")
TEXT("FieldFloat32", NOSPLIT, "func(s Struct) float32")
f32 := Load(Param("s").Field("Float32"), XMM())
Store(f32, ReturnIndex(0))
RET()

TEXT("FieldFloat64", "func(s Struct) float64")
TEXT("FieldFloat64", NOSPLIT, "func(s Struct) float64")
f64 := Load(Param("s").Field("Float64"), XMM())
Store(f64, ReturnIndex(0))
RET()

TEXT("FieldStringLen", "func(s Struct) int")
TEXT("FieldStringLen", NOSPLIT, "func(s Struct) int")
l := Load(Param("s").Field("String").Len(), GP64())
Store(l, ReturnIndex(0))
RET()

TEXT("FieldSliceCap", "func(s Struct) int")
TEXT("FieldSliceCap", NOSPLIT, "func(s Struct) int")
c := Load(Param("s").Field("Slice").Cap(), GP64())
Store(c, ReturnIndex(0))
RET()

TEXT("FieldArrayTwoBTwo", "func(s Struct) byte")
TEXT("FieldArrayTwoBTwo", NOSPLIT, "func(s Struct) byte")
b2 := Load(Param("s").Field("Array").Index(2).Field("B").Index(2), GP8())
Store(b2, ReturnIndex(0))
RET()

TEXT("FieldArrayOneC", "func(s Struct) uint16")
TEXT("FieldArrayOneC", NOSPLIT, "func(s Struct) uint16")
c1 := Load(Param("s").Field("Array").Index(1).Field("C"), GP16())
Store(c1, ReturnIndex(0))
RET()

TEXT("FieldComplex64Imag", "func(s Struct) float32")
TEXT("FieldComplex64Imag", NOSPLIT, "func(s Struct) float32")
c64i := Load(Param("s").Field("Complex64").Imag(), XMM())
Store(c64i, ReturnIndex(0))
RET()

TEXT("FieldComplex128Real", "func(s Struct) float64")
TEXT("FieldComplex128Real", NOSPLIT, "func(s Struct) float64")
c128r := Load(Param("s").Field("Complex128").Real(), XMM())
Store(c128r, ReturnIndex(0))
RET()
Expand Down
6 changes: 3 additions & 3 deletions examples/complex/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import (
)

func main() {
TEXT("Real", "func(z complex128) float64")
TEXT("Real", NOSPLIT, "func(z complex128) float64")
Doc("Real returns the real part of z.")
r := Load(Param("z").Real(), XMM())
Store(r, ReturnIndex(0))
RET()

TEXT("Imag", "func(z complex128) float64")
TEXT("Imag", NOSPLIT, "func(z complex128) float64")
Doc("Imag returns the imaginary part of z.")
i := Load(Param("z").Imag(), XMM())
Store(i, ReturnIndex(0))
RET()

TEXT("Norm", "func(z complex128) float64")
TEXT("Norm", NOSPLIT, "func(z complex128) float64")
Doc("Norm returns the complex norm of z.")
r = Load(Param("z").Real(), XMM())
i = Load(Param("z").Imag(), XMM())
Expand Down
8 changes: 5 additions & 3 deletions examples/complex/complex.s
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// Code generated by command: go run asm.go -out complex.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Real(z complex128) float64
TEXT ·Real(SB), $0-24
TEXT ·Real(SB), NOSPLIT, $0-24
MOVSD z_real(FP), X0
MOVSD X0, ret+16(FP)
RET

// func Imag(z complex128) float64
TEXT ·Imag(SB), $0-24
TEXT ·Imag(SB), NOSPLIT, $0-24
MOVSD z_imag+8(FP), X0
MOVSD X0, ret+16(FP)
RET

// func Norm(z complex128) float64
TEXT ·Norm(SB), $0-24
TEXT ·Norm(SB), NOSPLIT, $0-24
MOVSD z_real(FP), X0
MOVSD z_imag+8(FP), X1
MULSD X0, X0
Expand Down
3 changes: 1 addition & 2 deletions examples/data/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package main
import (
"math"

. "github.com/mmcloughlin/avo/attr"
. "github.com/mmcloughlin/avo/build"
. "github.com/mmcloughlin/avo/operand"
)
Expand All @@ -21,7 +20,7 @@ func main() {
DATA(38, U8(0x66))
DATA(39, U8(0x77))

TEXT("DataAt", "func(i int) byte")
TEXT("DataAt", NOSPLIT, "func(i int) byte")
Doc("DataAt returns byte i in the 'bytes' global data section.")
i := Load(Param("i"), GP64())
ptr := Mem{Base: GP64()}
Expand Down
2 changes: 1 addition & 1 deletion examples/data/data.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DATA bytes<>+39(SB)/1, $0x77
GLOBL bytes<>(SB), RODATA|NOPTR, $40

// func DataAt(i int) byte
TEXT ·DataAt(SB), $0-9
TEXT ·DataAt(SB), NOSPLIT, $0-9
MOVQ i(FP), AX
LEAQ bytes<>(SB), CX
MOVB (CX)(AX*1), AL
Expand Down
2 changes: 1 addition & 1 deletion examples/dot/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var unroll = 6

func main() {
TEXT("Dot", "func(x, y []float32) float32")
TEXT("Dot", NOSPLIT, "func(x, y []float32) float32")
x := Mem{Base: Load(Param("x").Base(), GP64())}
y := Mem{Base: Load(Param("y").Base(), GP64())}
n := Load(Param("x").Len(), GP64())
Expand Down
4 changes: 3 additions & 1 deletion examples/dot/dot.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Code generated by command: go run asm.go -out dot.s -stubs stub.go. DO NOT EDIT.

#include "textflag.h"

// func Dot(x []float32, y []float32) float32
TEXT ·Dot(SB), $0-52
TEXT ·Dot(SB), NOSPLIT, $0-52
MOVQ x_base(FP), AX
MOVQ y_base+24(FP), CX
MOVQ x_len+8(FP), DX
Expand Down
2 changes: 1 addition & 1 deletion examples/fnv1a/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
)

func main() {
TEXT("Hash64", "func(data []byte) uint64")
TEXT("Hash64", NOSPLIT, "func(data []byte) uint64")
Doc("Hash64 computes the FNV-1a hash of data.")
ptr := Load(Param("data").Base(), GP64())
n := Load(Param("data").Len(), GP64())
Expand Down
Loading

0 comments on commit 304c742

Please sign in to comment.