| 1 |
|
| 2 |
|
| 3 |
package main |
| 4 |
|
| 5 |
import ( |
| 6 |
. "github.com/mmcloughlin/avo/build" |
| 7 |
. "github.com/mmcloughlin/avo/operand" |
| 8 |
) |
| 9 |
|
| 10 |
func main() { |
| 11 |
Package("github.com/mmcloughlin/avo/examples/returns") |
| 12 |
|
| 13 |
TEXT("Interval", NOSPLIT, "func(start, size uint64) (uint64, uint64)") |
| 14 |
Doc( |
| 15 |
"Interval returns the (start, end) of an interval with the given start and size.", |
| 16 |
"Demonstrates multiple unnamed return values.", |
| 17 |
) |
| 18 |
start := Load(Param("start"), GP64()) |
| 19 |
size := Load(Param("size"), GP64()) |
| 20 |
end := size |
| 21 |
ADDQ(start, end) |
| 22 |
Store(start, ReturnIndex(0)) |
| 23 |
Store(end, ReturnIndex(1)) |
| 24 |
RET() |
| 25 |
|
| 26 |
TEXT("Butterfly", NOSPLIT, "func(x0, x1 float64) (y0, y1 float64)") |
| 27 |
Doc( |
| 28 |
"Butterfly performs a 2-dimensional butterfly operation: computes (x0+x1, x0-x1).", |
| 29 |
"Demonstrates multiple named return values.", |
| 30 |
) |
| 31 |
x0 := Load(Param("x0"), XMM()) |
| 32 |
x1 := Load(Param("x1"), XMM()) |
| 33 |
y0, y1 := XMM(), XMM() |
| 34 |
MOVSD(x0, y0) |
| 35 |
ADDSD(x1, y0) |
| 36 |
MOVSD(x0, y1) |
| 37 |
SUBSD(x1, y1) |
| 38 |
Store(y0, Return("y0")) |
| 39 |
Store(y1, Return("y1")) |
| 40 |
RET() |
| 41 |
|
| 42 |
TEXT("Septuple", NOSPLIT, "func(byte) [7]byte") |
| 43 |
Doc( |
| 44 |
"Septuple returns an array of seven of the given byte.", |
| 45 |
"Demonstrates returning array values.", |
| 46 |
) |
| 47 |
b := Load(ParamIndex(0), GP8()) |
| 48 |
for i := 0; i < 7; i++ { |
| 49 |
Store(b, ReturnIndex(0).Index(i)) |
| 50 |
} |
| 51 |
RET() |
| 52 |
|
| 53 |
TEXT("CriticalLine", NOSPLIT, "func(t float64) complex128") |
| 54 |
Doc( |
| 55 |
"CriticalLine returns the complex value 0.5 + it on Riemann's critical line.", |
| 56 |
"Demonstrates returning complex values.", |
| 57 |
) |
| 58 |
t := Load(Param("t"), XMM()) |
| 59 |
half := XMM() |
| 60 |
MOVSD(ConstData("half", F64(0.5)), half) |
| 61 |
Store(half, ReturnIndex(0).Real()) |
| 62 |
Store(t, ReturnIndex(0).Imag()) |
| 63 |
RET() |
| 64 |
|
| 65 |
TEXT("NewStruct", NOSPLIT, "func(w uint16, p [2]float64, q uint64) Struct") |
| 66 |
Doc( |
| 67 |
"NewStruct initializes a Struct value.", |
| 68 |
"Demonstrates returning struct values.", |
| 69 |
) |
| 70 |
w := Load(Param("w"), GP16()) |
| 71 |
x := Load(Param("p").Index(0), XMM()) |
| 72 |
y := Load(Param("p").Index(1), XMM()) |
| 73 |
q := Load(Param("q"), GP64()) |
| 74 |
Store(w, ReturnIndex(0).Field("Word")) |
| 75 |
Store(x, ReturnIndex(0).Field("Point").Index(0)) |
| 76 |
Store(y, ReturnIndex(0).Field("Point").Index(1)) |
| 77 |
Store(q, ReturnIndex(0).Field("Quad")) |
| 78 |
RET() |
| 79 |
|
| 80 |
Generate() |
| 81 |
} |