2019-01-01 15:56:17 -08:00
# complex
Demonstrates how to access complex types in `avo` .
The `Real()` and `Imag()` parameter methods may be used to load the sub-components of complex arguments. The following function uses these to implement the [complex norm ](http://mathworld.wolfram.com/ComplexModulus.html ).
[embedmd]:# (asm.go go /.*TEXT.*Norm/ /RET.*/)
```go
2019-01-06 20:16:26 -08:00
TEXT("Norm", NOSPLIT, "func(z complex128) float64")
2019-01-01 15:56:17 -08:00
Doc("Norm returns the complex norm of z.")
2019-01-04 18:23:44 -08:00
r = Load(Param("z").Real(), XMM())
i = Load(Param("z").Imag(), XMM())
2019-01-01 15:56:17 -08:00
MULSD(r, r)
MULSD(i, i)
ADDSD(i, r)
2019-01-04 18:23:44 -08:00
n := XMM()
2019-01-01 15:56:17 -08:00
SQRTSD(r, n)
Store(n, ReturnIndex(0))
RET()
```
Generated assembly:
[embedmd]:# (complex.s s /.*func Norm/ /RET/)
```s
// func Norm(z complex128) float64
2020-01-19 16:45:09 -08:00
// Requires: SSE2
2019-01-06 20:16:26 -08:00
TEXT ·Norm(SB), NOSPLIT, $0-24
2019-01-13 11:59:14 -08:00
MOVSD z_real+0(FP), X0
2019-01-10 21:21:41 -08:00
MOVSD z_imag+8(FP), X1
MULSD X0, X0
MULSD X1, X1
ADDSD X1, X0
SQRTSD X0, X2
MOVSD X2, ret+16(FP)
2019-01-01 15:56:17 -08:00
RET
```