diff --git a/examples/components/asm.go b/examples/components/asm.go index e968a14..c5d5597 100644 --- a/examples/components/asm.go +++ b/examples/components/asm.go @@ -9,6 +9,26 @@ import ( func main() { Package("github.com/mmcloughlin/avo/examples/components") + TEXT("StringLen", "func(s string) int") + strlen := Load(Param("s").Len(), GP64v()) + Store(strlen, ReturnIndex(0)) + RET() + + TEXT("SliceLen", "func(s []int) int") + slicelen := Load(Param("s").Len(), GP64v()) + Store(slicelen, ReturnIndex(0)) + RET() + + TEXT("SliceCap", "func(s []int) int") + slicecap := Load(Param("s").Cap(), GP64v()) + Store(slicecap, ReturnIndex(0)) + RET() + + TEXT("ArrayThree", "func(a [7]uint64) uint64") + a3 := Load(Param("a").Index(3), GP64v()) + Store(a3, ReturnIndex(0)) + RET() + TEXT("FieldByte", "func(s Struct) byte") b := Load(Param("s").Field("Byte"), GP8v()) Store(b, ReturnIndex(0)) diff --git a/examples/components/components.s b/examples/components/components.s index 65e5313..80e4d6c 100644 --- a/examples/components/components.s +++ b/examples/components/components.s @@ -2,6 +2,30 @@ #include "textflag.h" +// func StringLen(s string) int +TEXT ·StringLen(SB),0,$0-24 + MOVQ s_len+8(FP), AX + MOVQ AX, ret+16(FP) + RET + +// func SliceLen(s []int) int +TEXT ·SliceLen(SB),0,$0-32 + MOVQ s_len+8(FP), AX + MOVQ AX, ret+24(FP) + RET + +// func SliceCap(s []int) int +TEXT ·SliceCap(SB),0,$0-32 + MOVQ s_cap+16(FP), AX + MOVQ AX, ret+24(FP) + RET + +// func ArrayThree(a [7]uint64) uint64 +TEXT ·ArrayThree(SB),0,$0-64 + MOVQ a_3+24(FP), AX + MOVQ AX, ret+56(FP) + RET + // func FieldByte(s Struct) byte TEXT ·FieldByte(SB),0,$0-184 MOVB s_Byte(FP), AL diff --git a/examples/components/components_test.go b/examples/components/components_test.go index bffaead..4287ef1 100644 --- a/examples/components/components_test.go +++ b/examples/components/components_test.go @@ -11,6 +11,10 @@ func TestFunctionsEqual(t *testing.T) { cases := []struct { f, g interface{} }{ + {StringLen, func(s string) int { return len(s) }}, + {SliceLen, func(s []int) int { return len(s) }}, + {SliceCap, func(s []int) int { return cap(s) }}, + {ArrayThree, func(a [7]uint64) uint64 { return a[3] }}, {FieldByte, func(s Struct) byte { return s.Byte }}, {FieldInt8, func(s Struct) int8 { return s.Int8 }}, {FieldUint16, func(s Struct) uint16 { return s.Uint16 }}, diff --git a/examples/components/stub.go b/examples/components/stub.go index 9991c74..6036ddb 100644 --- a/examples/components/stub.go +++ b/examples/components/stub.go @@ -2,6 +2,14 @@ package components +func StringLen(s string) int + +func SliceLen(s []int) int + +func SliceCap(s []int) int + +func ArrayThree(a [7]uint64) uint64 + func FieldByte(s Struct) byte func FieldInt8(s Struct) int8