The source files below should be arranged as:
./main.go
./sqrt/sqrt.s
./sqrt/sqrt.go
To run:
>> go build main.go
>> ./main
sqrt(2) = 1.4142135623730951
package main | |
import ("fmt" | |
"./sqrt") | |
func main() { | |
x := 2.0 | |
fmt.Printf("sqrt(%v) = %v\n", x, sqrt.Sqrt(x)); | |
} |
package sqrt | |
/* | |
extern double as_sqrt(double); | |
*/ | |
import "C" | |
func Sqrt(x float64) float64 { | |
return float64(C.as_sqrt(C.double(x))) | |
} |
.text | |
.globl as_sqrt | |
.balign 16 | |
.type as_sqrt, @function | |
as_sqrt: | |
sqrtsd %xmm0, %xmm0 | |
retq | |
.size as_sqrt, .-as_sqrt |