]> Cypherpunks repositories - gostls13.git/commitdiff
math: 386 FPU functions
authorCharles L. Dorian <cldorian@gmail.com>
Fri, 15 Jan 2010 21:21:36 +0000 (13:21 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 15 Jan 2010 21:21:36 +0000 (13:21 -0800)
sin, cos, tan, asin, acos, atan, exp, log, log10,
floor, ceil, and fabs

R=rsc
CC=golang-dev
https://golang.org/cl/189083

17 files changed:
src/pkg/math/Makefile
src/pkg/math/asin_386.s [new file with mode: 0644]
src/pkg/math/asin_decl.go [new file with mode: 0644]
src/pkg/math/atan_386.s [new file with mode: 0644]
src/pkg/math/atan_decl.go [new file with mode: 0644]
src/pkg/math/exp_386.s [new file with mode: 0644]
src/pkg/math/exp_decl.go [new file with mode: 0644]
src/pkg/math/fabs_386.s [new file with mode: 0644]
src/pkg/math/fabs_decl.go [new file with mode: 0644]
src/pkg/math/floor_386.s [new file with mode: 0644]
src/pkg/math/floor_decl.go [new file with mode: 0644]
src/pkg/math/log_386.s [new file with mode: 0644]
src/pkg/math/log_decl.go [new file with mode: 0644]
src/pkg/math/sin_386.s [new file with mode: 0644]
src/pkg/math/sin_decl.go [new file with mode: 0644]
src/pkg/math/tan_386.s [new file with mode: 0644]
src/pkg/math/tan_decl.go [new file with mode: 0644]

index 7a3808976aac4a56b05d1dc7cd913fcbcbfc9220..be9b6ff639bf64101507957eff7ae298b31460eb 100644 (file)
@@ -10,7 +10,15 @@ OFILES_amd64=\
        sqrt_amd64.$O\
 
 OFILES_386=\
+       asin_386.$O\
+       atan_386.$O\
+       exp_386.$O\
+       fabs_386.$O\
+       floor_386.$O\
+       log_386.$O\
+       sin_386.$O\
        sqrt_386.$O\
+       tan_386.$O\
 
 OFILES=\
        $(OFILES_$(GOARCH))
diff --git a/src/pkg/math/asin_386.s b/src/pkg/math/asin_386.s
new file mode 100644 (file)
index 0000000..0b52bcd
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Asin(x float64) float64
+TEXT math·Asin(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=sin(x)
+       FMOVD   F0, F1       // F0=sin(x), F1=sin(x)
+       FMULD   F0, F0       // F0=sin(x)*sin(x), F1=sin(x)
+       FLD1                 // F0=1, F1=sin(x)*sin(x), F2=sin(x)
+       FSUBRDP F0, F1       // F0=1-sin(x)*sin(x) (=cos(x)*cos(x)), F1=sin(x)
+       FSQRT                // F0=cos(x), F1=sin(x)
+       FPATAN               // F0=arcsin(sin(x))=x
+       FMOVDP  F0, r+8(FP)
+       RET
+
+// func Acos(x float64) float64
+TEXT math·Acos(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=cos(x)
+       FMOVD   F0, F1       // F0=cos(x), F1=cos(x)
+       FMULD   F0, F0       // F0=cos(x)*cos(x), F1=cos(x)
+       FLD1                 // F0=1, F1=cos(x)*cos(x), F2=cos(x)
+       FSUBRDP F0, F1       // F0=1-cos(x)*cos(x) (=sin(x)*sin(x)), F1=cos(x)
+       FSQRT                // F0=sin(x), F1=cos(x)
+       FXCHD   F0, F1       // F0=cos(x), F1=sin(x)
+       FPATAN               // F0=arccos(cos(x))=x
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/asin_decl.go b/src/pkg/math/asin_decl.go
new file mode 100644 (file)
index 0000000..63a55dc
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Acos(x float64) float64
+func Asin(x float64) float64
diff --git a/src/pkg/math/atan_386.s b/src/pkg/math/atan_386.s
new file mode 100644 (file)
index 0000000..8212e28
--- /dev/null
@@ -0,0 +1,11 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Atan(x float64) float64
+TEXT math·Atan(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FLD1                 // F0=1, F1=x
+       FPATAN               // F0=atan(F1/F0)
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/atan_decl.go b/src/pkg/math/atan_decl.go
new file mode 100644 (file)
index 0000000..14d3fc0
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Atan(x float64) float64
diff --git a/src/pkg/math/exp_386.s b/src/pkg/math/exp_386.s
new file mode 100644 (file)
index 0000000..2ac45fa
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Exp(x float64) float64
+TEXT math·Exp(SB),7,$0
+// test bits for not-finite
+       MOVL    x+4(FP), AX
+       ANDL    $0x7ff00000, AX
+       CMPL    AX, $0x7ff00000
+       JEQ     not_finite
+       FLDL2E                // F0=log2(e)
+       FMOVD   x+0(FP), F0   // F0=x, F1=log2(e)
+       FMULDP  F0, F1        // F0=x*log2(e)
+       FMOVD   F0, F1        // F0=x*log2(e), F1=x*log2(e)
+       FRNDINT               // F0=int(x*log2(e)), F1=x*log2(e)
+       FSUBD   F0, F1        // F0=int(x*log2(e)), F1=x*log2(e)-int(x*log2(e))
+       FXCHD   F0, F1        // F0=x*log2(e)-int(x*log2(e)), F1=int(x*log2(e))
+       F2XM1                 // F0=2**(x*log2(e)-int(x*log2(e)))-1, F1=int(x*log2(e))
+       FLD1                  // F0=1, F1=2**(x*log2(e)-int(x*log2(e)))-1, F2=int(x*log2(e))
+       FADDDP  F0, F1        // F0=2**(x*log2(e)-int(x*log2(e))), F1=int(x*log2(e))
+       FSCALE                // F0=e**x, F1=int(x*log2(e))
+       FMOVDP  F0, F1        // F0=e**x
+       FMOVDP  F0, r+8(FP)
+       RET
+not_finite:
+// test bits for -Inf
+       MOVL    x+4(FP), BX
+       MOVL    x+0(FP), CX
+       CMPL    BX, $0xfff00000
+       JNE     not_neginf
+       CMPL    CX, $0
+       JNE     not_neginf
+       MOVL    $0, r+8(FP)
+       MOVL    $0, r+12(FP)
+       RET
+not_neginf:
+       MOVL    CX, r+8(FP)
+       MOVL    BX, r+12(FP)
+       RET
diff --git a/src/pkg/math/exp_decl.go b/src/pkg/math/exp_decl.go
new file mode 100644 (file)
index 0000000..dc8404c
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Exp(x float64) float64
diff --git a/src/pkg/math/fabs_386.s b/src/pkg/math/fabs_386.s
new file mode 100644 (file)
index 0000000..93d6101
--- /dev/null
@@ -0,0 +1,10 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Fabs(x float64) float64
+TEXT math·Fabs(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FABS                 // F0=|x|
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/fabs_decl.go b/src/pkg/math/fabs_decl.go
new file mode 100644 (file)
index 0000000..9071f49
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Fabs(x float64) float64
diff --git a/src/pkg/math/floor_386.s b/src/pkg/math/floor_386.s
new file mode 100644 (file)
index 0000000..3a21820
--- /dev/null
@@ -0,0 +1,31 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Ceil(x float64) float64
+TEXT math·Ceil(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FSTCW   -2(SP)       // save old Control Word
+       MOVW    -2(SP), AX
+       ANDW    $0xf3ff, AX
+       ORW         $0x0800, AX  // Rounding Control set to +Inf
+       MOVW    AX, -4(SP)   // store new Control Word
+       FLDCW   -4(SP)       // load new Control Word
+       FRNDINT              // F0=Ceil(x)
+       FLDCW   -2(SP)       // load old Control Word
+       FMOVDP  F0, r+8(FP)
+       RET
+
+// func Floor(x float64) float64
+TEXT math·Floor(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FSTCW   -2(SP)       // save old Control Word
+       MOVW    -2(SP), AX
+       ANDW    $0xf3ff, AX
+       ORW         $0x0400, AX  // Rounding Control set to -Inf
+       MOVW    AX, -4(SP)   // store new Control Word
+       FLDCW   -4(SP)       // load new Control Word
+       FRNDINT              // F0=floor(x)
+       FLDCW   -2(SP)       // load old Control Word
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/floor_decl.go b/src/pkg/math/floor_decl.go
new file mode 100644 (file)
index 0000000..09f5646
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Ceil(x float64) float64
+func Floor(x float64) float64
diff --git a/src/pkg/math/log_386.s b/src/pkg/math/log_386.s
new file mode 100644 (file)
index 0000000..56eaa6e
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Log(x float64) float64
+TEXT math·Log(SB),7,$0
+       FLDLN2               // F0=log(2)
+       FMOVD   x+0(FP), F0  // F0=x, F1=log(2)
+       FYL2X                // F0=log(x)=log2(x)*log(2)
+       FMOVDP  F0, r+8(FP)
+       RET
+       
+// func Log10(x float64) float64
+TEXT math·Log10(SB),7,$0
+       FLDLG2               // F0=log10(2)
+       FMOVD   x+0(FP), F0  // F0=x, F1=log10(2)
+       FYL2X                // F0=log10(x)=log2(x)*log10(2)
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/log_decl.go b/src/pkg/math/log_decl.go
new file mode 100644 (file)
index 0000000..ddae436
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Log(x float64) float64
+func Log10(x float64) float64
diff --git a/src/pkg/math/sin_386.s b/src/pkg/math/sin_386.s
new file mode 100644 (file)
index 0000000..16edc7a
--- /dev/null
@@ -0,0 +1,45 @@
+// Copyright 2009 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Cos(x float64) float64
+TEXT math·Cos(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FCOS                 // F0=cos(x) if -2**63 < x < 2**63
+       FSTSW   AX           // AX=status word
+       ANDW    $0x0400, AX
+       JNE     3(PC)        // jump if x outside range
+       FMOVDP  F0, r+8(FP)
+       RET
+       FLDPI                // F0=Pi, F1=x
+       FADDD   F0, F0       // F0=2*Pi, F1=x
+       FXCHD   F0, F1       // F0=x, F1=2*Pi
+       FPREM1               // F0=reduced_x, F1=2*Pi
+       FSTSW   AX           // AX=status word
+       ANDW    $0x0400, AX
+       JNE     -3(PC)       // jump if reduction incomplete
+       FMOVDP  F0, F1       // F0=reduced_x
+       FCOS                 // F0=cos(reduced_x)
+       FMOVDP  F0, r+8(FP)
+       RET
+       
+// func Sin(x float64) float64
+TEXT math·Sin(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FSIN                 // F0=sin(x) if -2**63 < x < 2**63
+       FSTSW   AX           // AX=status word
+       ANDW    $0x0400, AX
+       JNE     3(PC)        // jump if x outside range
+       FMOVDP  F0, r+8(FP)
+       RET
+       FLDPI                // F0=Pi, F1=x
+       FADDD   F0, F0       // F0=2*Pi, F1=x
+       FXCHD   F0, F1       // F0=x, F1=2*Pi
+       FPREM1               // F0=reduced_x, F1=2*Pi
+       FSTSW   AX           // AX=status word
+       ANDW    $0x0400, AX
+       JNE     -3(PC)       // jump if reduction incomplete
+       FMOVDP  F0, F1       // F0=reduced_x
+       FSIN                 // F0=sin(reduced_x)
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/sin_decl.go b/src/pkg/math/sin_decl.go
new file mode 100644 (file)
index 0000000..fc37b03
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2009 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Cos(x float64) float64
+func Sin(x float64) float64
diff --git a/src/pkg/math/tan_386.s b/src/pkg/math/tan_386.s
new file mode 100644 (file)
index 0000000..f37b89e
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// func Tan(x float64) float64
+TEXT math·Tan(SB),7,$0
+       FMOVD   x+0(FP), F0  // F0=x
+       FPTAN                // F0=1, F1=tan(x) if -2**63 < x < 2**63
+       FSTSW   AX           // AX=status word
+       ANDW    $0x0400, AX
+       JNE     4(PC)        // jump if x outside range
+       FMOVDP  F0, F0       // F0=tan(x)
+       FMOVDP  F0, r+8(FP)
+       RET
+       FLDPI                // F0=Pi, F1=x
+       FADDD   F0, F0       // F0=2*Pi, F1=x
+       FXCHD   F0, F1       // F0=x, F1=2*Pi
+       FPREM1               // F0=reduced_x, F1=2*Pi
+       FSTSW   AX           // AX=status word
+       ANDW    $0x0400, AX
+       JNE     -3(PC)       // jump if reduction incomplete
+       FMOVDP  F0, F1       // F0=reduced_x
+       FPTAN                // F0=1, F1=tan(reduced_x)
+       FMOVDP  F0, F0       // F0=tan(reduced_x)
+       FMOVDP  F0, r+8(FP)
+       RET
diff --git a/src/pkg/math/tan_decl.go b/src/pkg/math/tan_decl.go
new file mode 100644 (file)
index 0000000..2796b35
--- /dev/null
@@ -0,0 +1,7 @@
+// Copyright 2010 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package math
+
+func Tan(x float64) float64