Skip to content

Commit

Permalink
reg,build: remove "v" from virtual register ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Jan 5, 2019
1 parent 05cfa80 commit 672b77a
Show file tree
Hide file tree
Showing 26 changed files with 155 additions and 155 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ import (
func main() {
TEXT("Add", "func(x, y uint64) uint64")
Doc("Add adds x and y.")
x := Load(Param("x"), GP64v())
y := Load(Param("y"), GP64v())
x := Load(Param("x"), GP64())
y := Load(Param("y"), GP64())
ADDQ(x, y)
Store(y, ReturnIndex(0))
RET()
Expand Down Expand Up @@ -101,9 +101,9 @@ Sum a slice of `uint64`s:
func main() {
TEXT("Sum", "func(xs []uint64) uint64")
Doc("Sum returns the sum of the elements in xs.")
ptr := Load(Param("xs").Base(), GP64v())
n := Load(Param("xs").Len(), GP64v())
s := GP64v()
ptr := Load(Param("xs").Base(), GP64())
n := Load(Param("xs").Len(), GP64())
s := GP64()
XORQ(s, s)
LABEL("loop")
CMPQ(n, operand.Imm(0))
Expand All @@ -126,31 +126,31 @@ func main() {
[embedmd]:# (examples/args/asm.go go /.*TEXT.*StringLen/ /Load.*/)
```go
TEXT("StringLen", "func(s string) int")
strlen := Load(Param("s").Len(), GP64v())
strlen := Load(Param("s").Len(), GP64())
```

Index an array:

[embedmd]:# (examples/args/asm.go go /.*TEXT.*ArrayThree/ /Load.*/)
```go
TEXT("ArrayThree", "func(a [7]uint64) uint64")
a3 := Load(Param("a").Index(3), GP64v())
a3 := Load(Param("a").Index(3), GP64())
```

Access a struct field (provided you have loaded your package with the `Package` function):

[embedmd]:# (examples/args/asm.go go /.*TEXT.*FieldFloat64/ /Load.*/)
```go
TEXT("FieldFloat64", "func(s Struct) float64")
f64 := Load(Param("s").Field("Float64"), Xv())
f64 := Load(Param("s").Field("Float64"), XMM())
```

Component accesses can be arbitrarily nested:

[embedmd]:# (examples/args/asm.go go /.*TEXT.*FieldArrayTwoBTwo/ /Load.*/)
```go
TEXT("FieldArrayTwoBTwo", "func(s Struct) byte")
b2 := Load(Param("s").Field("Array").Index(2).Field("B").Index(2), GP8v())
b2 := Load(Param("s").Field("Array").Index(2).Field("B").Index(2), GP8())
```

Very similar techniques apply to writing return values. See [`examples/args`](examples/args) and [`examples/returns`](examples/returns) for more.
Expand Down
14 changes: 7 additions & 7 deletions build/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ func Constraints(t buildtags.ConstraintsConvertable) { ctx.Constraints(t) }
func Constraint(t buildtags.ConstraintConvertable) { ctx.Constraint(t) }
func ConstraintExpr(expr string) { ctx.ConstraintExpr(expr) }

func GP8v() reg.GPVirtual { return ctx.GP8v() }
func GP16v() reg.GPVirtual { return ctx.GP16v() }
func GP32v() reg.GPVirtual { return ctx.GP32v() }
func GP64v() reg.GPVirtual { return ctx.GP64v() }
func Xv() reg.VecVirtual { return ctx.Xv() }
func Yv() reg.VecVirtual { return ctx.Yv() }
func Zv() reg.VecVirtual { return ctx.Zv() }
func GP8() reg.GPVirtual { return ctx.GP8() }
func GP16() reg.GPVirtual { return ctx.GP16() }
func GP32() reg.GPVirtual { return ctx.GP32() }
func GP64() reg.GPVirtual { return ctx.GP64() }
func XMM() reg.VecVirtual { return ctx.XMM() }
func YMM() reg.VecVirtual { return ctx.YMM() }
func ZMM() reg.VecVirtual { return ctx.ZMM() }

func Param(name string) gotypes.Component { return ctx.Param(name) }
func ParamIndex(i int) gotypes.Component { return ctx.ParamIndex(i) }
Expand Down
4 changes: 2 additions & 2 deletions examples/add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
func main() {
TEXT("Add", "func(x, y uint64) uint64")
Doc("Add adds x and y.")
x := Load(Param("x"), GP64v())
y := Load(Param("y"), GP64v())
x := Load(Param("x"), GP64())
y := Load(Param("y"), GP64())
ADDQ(x, y)
Store(y, ReturnIndex(0))
RET()
Expand Down
4 changes: 2 additions & 2 deletions examples/add/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
func main() {
TEXT("Add", "func(x, y uint64) uint64")
Doc("Add adds x and y.")
x := Load(Param("x"), GP64v())
y := Load(Param("y"), GP64v())
x := Load(Param("x"), GP64())
y := Load(Param("y"), GP64())
ADDQ(x, y)
Store(y, ReturnIndex(0))
RET()
Expand Down
12 changes: 6 additions & 6 deletions examples/args/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Use `Param()` to reference arguments by name. The `Load()` function can be used
[embedmd]:# (asm.go go /.*TEXT.*Second/ /RET.*/)
```go
TEXT("Second", "func(x, y int32) int32")
y := Load(Param("y"), GP32v())
y := Load(Param("y"), GP32())
Store(y, ReturnIndex(0))
RET()
```
Expand All @@ -34,7 +34,7 @@ Strings and slices actually consist of multiple components under the hood: see [
[embedmd]:# (asm.go go /.*TEXT.*StringLen/ /RET.*/)
```go
TEXT("StringLen", "func(s string) int")
strlen := Load(Param("s").Len(), GP64v())
strlen := Load(Param("s").Len(), GP64())
Store(strlen, ReturnIndex(0))
RET()
```
Expand All @@ -48,7 +48,7 @@ Arrays can be indexed with the `Index()` method. For example, the following retu
[embedmd]:# (asm.go go /.*TEXT.*ArrayThree/ /RET.*/)
```go
TEXT("ArrayThree", "func(a [7]uint64) uint64")
a3 := Load(Param("a").Index(3), GP64v())
a3 := Load(Param("a").Index(3), GP64())
Store(a3, ReturnIndex(0))
RET()
```
Expand Down Expand Up @@ -87,7 +87,7 @@ The following function will return the `Float64` field from this struct.
[embedmd]:# (asm.go go /.*TEXT.*FieldFloat64/ /RET.*/)
```go
TEXT("FieldFloat64", "func(s Struct) float64")
f64 := Load(Param("s").Field("Float64"), Xv())
f64 := Load(Param("s").Field("Float64"), XMM())
Store(f64, ReturnIndex(0))
RET()
```
Expand All @@ -99,7 +99,7 @@ Complex types `complex{64,128}` are actually just pairs of `float{32,64}` values
[embedmd]:# (asm.go go /.*TEXT.*FieldComplex64Imag/ /RET.*/)
```go
TEXT("FieldComplex64Imag", "func(s Struct) float32")
c64i := Load(Param("s").Field("Complex64").Imag(), Xv())
c64i := Load(Param("s").Field("Complex64").Imag(), XMM())
Store(c64i, ReturnIndex(0))
RET()
```
Expand All @@ -111,7 +111,7 @@ The above methods may be composed to reference arbitrarily nested data structure
[embedmd]:# (asm.go go /.*TEXT.*FieldArrayTwoBTwo/ /RET.*/)
```go
TEXT("FieldArrayTwoBTwo", "func(s Struct) byte")
b2 := Load(Param("s").Field("Array").Index(2).Field("B").Index(2), GP8v())
b2 := Load(Param("s").Field("Array").Index(2).Field("B").Index(2), GP8())
Store(b2, ReturnIndex(0))
RET()
```
36 changes: 18 additions & 18 deletions examples/args/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,92 +10,92 @@ func main() {
Package("github.com/mmcloughlin/avo/examples/args")

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

TEXT("FieldComplex128Real", "func(s Struct) float64")
c128r := Load(Param("s").Field("Complex128").Real(), Xv())
c128r := Load(Param("s").Field("Complex128").Real(), XMM())
Store(c128r, ReturnIndex(0))
RET()

Expand Down
6 changes: 3 additions & 3 deletions examples/complex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ The `Real()` and `Imag()` parameter methods may be used to load the sub-componen
```go
TEXT("Norm", "func(z complex128) float64")
Doc("Norm returns the complex norm of z.")
r = Load(Param("z").Real(), Xv())
i = Load(Param("z").Imag(), Xv())
r = Load(Param("z").Real(), XMM())
i = Load(Param("z").Imag(), XMM())
MULSD(r, r)
MULSD(i, i)
ADDSD(i, r)
n := Xv()
n := XMM()
SQRTSD(r, n)
Store(n, ReturnIndex(0))
RET()
Expand Down
10 changes: 5 additions & 5 deletions examples/complex/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import (
func main() {
TEXT("Real", "func(z complex128) float64")
Doc("Real returns the real part of z.")
r := Load(Param("z").Real(), Xv())
r := Load(Param("z").Real(), XMM())
Store(r, ReturnIndex(0))
RET()

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

TEXT("Norm", "func(z complex128) float64")
Doc("Norm returns the complex norm of z.")
r = Load(Param("z").Real(), Xv())
i = Load(Param("z").Imag(), Xv())
r = Load(Param("z").Real(), XMM())
i = Load(Param("z").Imag(), XMM())
MULSD(r, r)
MULSD(i, i)
ADDSD(i, r)
n := Xv()
n := XMM()
SQRTSD(r, n)
Store(n, ReturnIndex(0))
RET()
Expand Down
6 changes: 3 additions & 3 deletions examples/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ The `GLOBL` function returns a reference which may be used in assembly code. The
```go
TEXT("DataAt", "func(i int) byte")
Doc("DataAt returns byte i in the 'bytes' global data section.")
i := Load(Param("i"), GP64v())
ptr := Mem{Base: GP64v()}
i := Load(Param("i"), GP64())
ptr := Mem{Base: GP64()}
LEAQ(bytes, ptr.Base)
b := GP8v()
b := GP8()
MOVB(ptr.Idx(i, 1), b)
Store(b, ReturnIndex(0))
RET()
Expand Down
6 changes: 3 additions & 3 deletions examples/data/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func main() {

TEXT("DataAt", "func(i int) byte")
Doc("DataAt returns byte i in the 'bytes' global data section.")
i := Load(Param("i"), GP64v())
ptr := Mem{Base: GP64v()}
i := Load(Param("i"), GP64())
ptr := Mem{Base: GP64()}
LEAQ(bytes, ptr.Base)
b := GP8v()
b := GP8()
MOVB(ptr.Idx(i, 1), b)
Store(b, ReturnIndex(0))
RET()
Expand Down
16 changes: 8 additions & 8 deletions examples/dot/asm.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var unroll = 6

func main() {
TEXT("Dot", "func(x, y []float32) float32")
x := Mem{Base: Load(Param("x").Base(), GP64v())}
y := Mem{Base: Load(Param("y").Base(), GP64v())}
n := Load(Param("x").Len(), GP64v())
x := Mem{Base: Load(Param("x").Base(), GP64())}
y := Mem{Base: Load(Param("y").Base(), GP64())}
n := Load(Param("x").Len(), GP64())

// Allocate accumulation registers.
acc := make([]VecVirtual, unroll)
for i := 0; i < unroll; i++ {
acc[i] = Yv()
acc[i] = YMM()
}

// Zero initialization.
Expand All @@ -37,7 +37,7 @@ func main() {
// Load x.
xs := make([]VecVirtual, unroll)
for i := 0; i < unroll; i++ {
xs[i] = Yv()
xs[i] = YMM()
}

for i := 0; i < unroll; i++ {
Expand All @@ -56,14 +56,14 @@ func main() {

// Process any trailing entries.
LABEL("tail")
tail := Xv()
tail := XMM()
VXORPS(tail, tail, tail)

LABEL("tailloop")
CMPQ(n, U32(0))
JE(LabelRef("reduce"))

xt := Xv()
xt := XMM()
VMOVSS(x, xt)
VFMADD231SS(y, xt, tail)

Expand All @@ -79,7 +79,7 @@ func main() {
}

result := acc[0].AsX()
top := Xv()
top := XMM()
VEXTRACTF128(U8(1), acc[0], top)
VADDPS(result, top, result)
VADDPS(result, tail, result)
Expand Down
Loading

0 comments on commit 672b77a

Please sign in to comment.