Skip to content

Commit

Permalink
doc: forgot to regenerate on last commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcloughlin committed Jan 7, 2019
1 parent 304c742 commit 4f73a6e
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 30 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,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 All @@ -65,8 +65,10 @@ After running `go generate` the [`add.s`](examples/add/add.s) file will contain
```s
// 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 Expand Up @@ -99,7 +101,7 @@ Sum a slice of `uint64`s:
[embedmd]:# (examples/sum/asm.go /func main/ /^}/)
```go
func main() {
TEXT("Sum", "func(xs []uint64) uint64")
TEXT("Sum", NOSPLIT, "func(xs []uint64) uint64")
Doc("Sum returns the sum of the elements in xs.")
ptr := Load(Param("xs").Base(), GP64())
n := Load(Param("xs").Len(), GP64())
Expand Down Expand Up @@ -135,8 +137,10 @@ The result from this code generator is:
```s
// Code generated by command: go run asm.go -out sum.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func Sum(xs []uint64) uint64
TEXT ·Sum(SB), $0-32
TEXT ·Sum(SB), NOSPLIT, $0-32
MOVQ xs_base(FP), AX
MOVQ xs_len+8(FP), CX
XORQ DX, DX
Expand All @@ -160,31 +164,31 @@ Full example at [`examples/sum`](examples/sum).

[embedmd]:# (examples/args/asm.go go /.*TEXT.*StringLen/ /Load.*/)
```go
TEXT("StringLen", "func(s string) int")
TEXT("StringLen", NOSPLIT, "func(s string) int")
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")
TEXT("ArrayThree", NOSPLIT, "func(a [7]uint64) uint64")
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")
TEXT("FieldFloat64", NOSPLIT, "func(s Struct) float64")
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")
TEXT("FieldArrayTwoBTwo", NOSPLIT, "func(s Struct) byte")
b2 := Load(Param("s").Field("Array").Index(2).Field("B").Index(2), GP8())
```

Expand All @@ -197,7 +201,7 @@ Very similar techniques apply to writing return values. See [`examples/args`](ex
[embedmd]:# (examples/sha1/asm.go /func main/ /^}/)
```go
func main() {
TEXT("block", "func(h *[5]uint32, m []byte)")
TEXT("block", 0, "func(h *[5]uint32, m []byte)")
Doc("block SHA-1 hashes the 64-byte message m into the running state h.")
h := Mem{Base: Load(Param("h"), GP64())}
m := Mem{Base: Load(Param("m").Base(), GP64())}
Expand Down
6 changes: 4 additions & 2 deletions examples/add/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 All @@ -39,8 +39,10 @@ This produces [`add.s`](add.s) as follows:
```s
// 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
14 changes: 7 additions & 7 deletions examples/args/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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")
TEXT("Second", NOSPLIT, "func(x, y int32) int32")
y := Load(Param("y"), GP32())
Store(y, ReturnIndex(0))
RET()
Expand All @@ -19,7 +19,7 @@ This `avo` code will generate the following assembly. Note that parameter refere
[embedmd]:# (args.s s /.*func Second/ /RET/)
```s
// 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
Expand All @@ -33,7 +33,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")
TEXT("StringLen", NOSPLIT, "func(s string) int")
strlen := Load(Param("s").Len(), GP64())
Store(strlen, ReturnIndex(0))
RET()
Expand All @@ -47,7 +47,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")
TEXT("ArrayThree", NOSPLIT, "func(a [7]uint64) uint64")
a3 := Load(Param("a").Index(3), GP64())
Store(a3, ReturnIndex(0))
RET()
Expand Down Expand Up @@ -86,7 +86,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")
TEXT("FieldFloat64", NOSPLIT, "func(s Struct) float64")
f64 := Load(Param("s").Field("Float64"), XMM())
Store(f64, ReturnIndex(0))
RET()
Expand All @@ -98,7 +98,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")
TEXT("FieldComplex64Imag", NOSPLIT, "func(s Struct) float32")
c64i := Load(Param("s").Field("Complex64").Imag(), XMM())
Store(c64i, ReturnIndex(0))
RET()
Expand All @@ -110,7 +110,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")
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()
Expand Down
4 changes: 2 additions & 2 deletions examples/complex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The `Real()` and `Imag()` parameter methods may be used to load the sub-componen

[embedmd]:# (asm.go go /.*TEXT.*Norm/ /RET.*/)
```go
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 All @@ -24,7 +24,7 @@ Generated assembly:
[embedmd]:# (complex.s s /.*func Norm/ /RET/)
```s
// 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
2 changes: 1 addition & 1 deletion examples/data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ The `GLOBL` function returns a reference which may be used in assembly code. The

[embedmd]:# (asm.go go /.*TEXT.*DataAt/ /RET.*/)
```go
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/fnv1a/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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
2 changes: 1 addition & 1 deletion examples/geohash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Refer to ["Geohash in Golang Assembly"](https://mmcloughlin.com/posts/geohash-as
[embedmd]:# (asm.go /func main/ $)
```go
func main() {
TEXT("EncodeInt", "func(lat, lng float64) uint64")
TEXT("EncodeInt", NOSPLIT, "func(lat, lng float64) uint64")
Doc("EncodeInt computes the 64-bit integer geohash of (lat, lng).")
lat := Load(Param("lat"), XMM())
lng := Load(Param("lng"), XMM())
Expand Down
10 changes: 5 additions & 5 deletions examples/returns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Use `ReturnIndex` to reference unnamed return values. For example, the following

[embedmd]:# (asm.go go /.*TEXT.*Interval/ /RET.*/)
```go
TEXT("Interval", "func(start, size uint64) (uint64, uint64)")
TEXT("Interval", NOSPLIT, "func(start, size uint64) (uint64, uint64)")
Doc(
"Interval returns the (start, end) of an interval with the given start and size.",
"Demonstrates multiple unnamed return values.",
Expand All @@ -28,7 +28,7 @@ Named return values are referenced much the same as arguments. For example, the

[embedmd]:# (asm.go go /.*TEXT.*Butterfly/ /RET.*/)
```go
TEXT("Butterfly", "func(x0, x1 float64) (y0, y1 float64)")
TEXT("Butterfly", NOSPLIT, "func(x0, x1 float64) (y0, y1 float64)")
Doc(
"Butterfly performs a 2-dimensional butterfly operation: computes (x0+x1, x0-x1).",
"Demonstrates multiple named return values.",
Expand All @@ -53,7 +53,7 @@ The following code returns an array type.

[embedmd]:# (asm.go go /.*TEXT.*Septuple/ /RET.*/)
```go
TEXT("Septuple", "func(byte) [7]byte")
TEXT("Septuple", NOSPLIT, "func(byte) [7]byte")
Doc(
"Septuple returns an array of seven of the given byte.",
"Demonstrates returning array values.",
Expand All @@ -69,7 +69,7 @@ Or a complex type:

[embedmd]:# (asm.go go /.*TEXT.*CriticalLine/ /RET.*/)
```go
TEXT("CriticalLine", "func(t float64) complex128")
TEXT("CriticalLine", NOSPLIT, "func(t float64) complex128")
Doc(
"CriticalLine returns the complex value 0.5 + it on Riemann's critical line.",
"Demonstrates returning complex values.",
Expand All @@ -86,7 +86,7 @@ You can even build a struct:

[embedmd]:# (asm.go go /.*TEXT.*NewStruct/ /RET.*/)
```go
TEXT("NewStruct", "func(w uint16, p [2]float64, q uint64) Struct")
TEXT("NewStruct", NOSPLIT, "func(w uint16, p [2]float64, q uint64) Struct")
Doc(
"NewStruct initializes a Struct value.",
"Demonstrates returning struct values.",
Expand Down
2 changes: 1 addition & 1 deletion examples/sha1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Compare to the [`crypto/sha1`](https://github.com/golang/go/blob/204a8f55dc2e0ac
[embedmd]:# (asm.go /func main/ /^}/)
```go
func main() {
TEXT("block", "func(h *[5]uint32, m []byte)")
TEXT("block", 0, "func(h *[5]uint32, m []byte)")
Doc("block SHA-1 hashes the 64-byte message m into the running state h.")
h := Mem{Base: Load(Param("h"), GP64())}
m := Mem{Base: Load(Param("m").Base(), GP64())}
Expand Down
2 changes: 1 addition & 1 deletion examples/sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Sum a slice of `uint64`s.
[embedmd]:# (asm.go go /func main/ /^}/)
```go
func main() {
TEXT("Sum", "func(xs []uint64) uint64")
TEXT("Sum", NOSPLIT, "func(xs []uint64) uint64")
Doc("Sum returns the sum of the elements in xs.")
ptr := Load(Param("xs").Base(), GP64())
n := Load(Param("xs").Len(), GP64())
Expand Down

0 comments on commit 4f73a6e

Please sign in to comment.