Files
avo/examples/complex/asm.go

34 lines
708 B
Go
Raw Normal View History

2018-12-12 00:02:22 -08:00
// +build ignore
package main
import . "github.com/mmcloughlin/avo/build"
2018-12-12 00:02:22 -08:00
func main() {
TEXT("Real", NOSPLIT, "func(z complex128) float64")
2018-12-27 23:09:44 -08:00
Doc("Real returns the real part of z.")
r := Load(Param("z").Real(), XMM())
2018-12-12 00:02:22 -08:00
Store(r, ReturnIndex(0))
RET()
TEXT("Imag", NOSPLIT, "func(z complex128) float64")
2018-12-27 23:09:44 -08:00
Doc("Imag returns the imaginary part of z.")
i := Load(Param("z").Imag(), XMM())
2018-12-12 00:02:22 -08:00
Store(i, ReturnIndex(0))
RET()
TEXT("Norm", NOSPLIT, "func(z complex128) float64")
2018-12-27 23:09:44 -08:00
Doc("Norm returns the complex norm of z.")
r = Load(Param("z").Real(), XMM())
i = Load(Param("z").Imag(), XMM())
2018-12-12 00:02:22 -08:00
MULSD(r, r)
MULSD(i, i)
ADDSD(i, r)
n := XMM()
2018-12-12 00:02:22 -08:00
SQRTSD(r, n)
Store(n, ReturnIndex(0))
RET()
Generate()
}