forked from mmcloughlin/avo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2189d38
commit b89d211
Showing
12 changed files
with
179 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
. "github.com/mmcloughlin/avo/build" | ||
) | ||
|
||
func main() { | ||
TEXT("Real", "func(x complex128) float64") | ||
r := Load(Param("x").Real(), Xv()) | ||
Store(r, ReturnIndex(0)) | ||
RET() | ||
|
||
TEXT("Imag", "func(x complex128) float64") | ||
i := Load(Param("x").Imag(), Xv()) | ||
Store(i, ReturnIndex(0)) | ||
RET() | ||
|
||
TEXT("Norm", "func(x complex128) float64") | ||
r = Load(Param("x").Real(), Xv()) | ||
i = Load(Param("x").Imag(), Xv()) | ||
MULSD(r, r) | ||
MULSD(i, i) | ||
ADDSD(i, r) | ||
n := Xv() | ||
SQRTSD(r, n) | ||
Store(n, ReturnIndex(0)) | ||
RET() | ||
|
||
Generate() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
#include "textflag.h" | ||
|
||
// func Real(x complex128) float64 | ||
TEXT ·Real(SB),0,$0-24 | ||
MOVSD x_real(FP), X0 | ||
MOVSD X0, ret+16(FP) | ||
RET | ||
// func Imag(x complex128) float64 | ||
TEXT ·Imag(SB),0,$0-24 | ||
MOVSD x_imag+8(FP), X0 | ||
MOVSD X0, ret+16(FP) | ||
RET | ||
// func Norm(x complex128) float64 | ||
TEXT ·Norm(SB),0,$0-24 | ||
MOVSD x_real(FP), X0 | ||
MOVSD x_imag+8(FP), X1 | ||
MULSD X0, X0 | ||
MULSD X1, X1 | ||
ADDSD X1, X0 | ||
SQRTSD X0, X2 | ||
MOVSD X2, ret+16(FP) | ||
RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package complex | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
"testing/quick" | ||
) | ||
|
||
//go:generate go run asm.go -out complex.s -stubs stub.go | ||
|
||
func TestReal(t *testing.T) { | ||
expect := func(x complex128) float64 { | ||
return real(x) | ||
} | ||
if err := quick.CheckEqual(Real, expect, nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestImag(t *testing.T) { | ||
expect := func(x complex128) float64 { | ||
return imag(x) | ||
} | ||
if err := quick.CheckEqual(Imag, expect, nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestNorm(t *testing.T) { | ||
expect := func(x complex128) float64 { | ||
return math.Sqrt(real(x)*real(x) + imag(x)*imag(x)) | ||
} | ||
if err := quick.CheckEqual(Norm, expect, nil); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package complex | ||
|
||
func Real(x complex128) float64 | ||
func Imag(x complex128) float64 | ||
func Norm(x complex128) float64 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters