summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles L. Dorian <cldorian@gmail.com>2010-01-15 13:21:36 -0800
committerCharles L. Dorian <cldorian@gmail.com>2010-01-15 13:21:36 -0800
commit684702af5f19ede4de2a5b69fd1ba9cbe64a68d6 (patch)
treed5e9ac14182710fe2509dde989fd99c914659f48 /src
parent2085acf537cda6556399b5a24c721f40a09acb60 (diff)
downloadgolang-684702af5f19ede4de2a5b69fd1ba9cbe64a68d6.tar.gz
math: 386 FPU functions
sin, cos, tan, asin, acos, atan, exp, log, log10, floor, ceil, and fabs R=rsc CC=golang-dev http://codereview.appspot.com/189083 Committer: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/pkg/math/Makefile8
-rw-r--r--src/pkg/math/asin_386.s28
-rw-r--r--src/pkg/math/asin_decl.go8
-rw-r--r--src/pkg/math/atan_386.s11
-rw-r--r--src/pkg/math/atan_decl.go7
-rw-r--r--src/pkg/math/exp_386.s40
-rw-r--r--src/pkg/math/exp_decl.go7
-rw-r--r--src/pkg/math/fabs_386.s10
-rw-r--r--src/pkg/math/fabs_decl.go7
-rw-r--r--src/pkg/math/floor_386.s31
-rw-r--r--src/pkg/math/floor_decl.go8
-rw-r--r--src/pkg/math/log_386.s19
-rw-r--r--src/pkg/math/log_decl.go8
-rw-r--r--src/pkg/math/sin_386.s45
-rw-r--r--src/pkg/math/sin_decl.go8
-rw-r--r--src/pkg/math/tan_386.s26
-rw-r--r--src/pkg/math/tan_decl.go7
17 files changed, 278 insertions, 0 deletions
diff --git a/src/pkg/math/Makefile b/src/pkg/math/Makefile
index 7a3808976..be9b6ff63 100644
--- a/src/pkg/math/Makefile
+++ b/src/pkg/math/Makefile
@@ -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
index 000000000..0b52bcd51
--- /dev/null
+++ b/src/pkg/math/asin_386.s
@@ -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
index 000000000..63a55dce9
--- /dev/null
+++ b/src/pkg/math/asin_decl.go
@@ -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
index 000000000..8212e28e4
--- /dev/null
+++ b/src/pkg/math/atan_386.s
@@ -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
index 000000000..14d3fc014
--- /dev/null
+++ b/src/pkg/math/atan_decl.go
@@ -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
index 000000000..2ac45fa7b
--- /dev/null
+++ b/src/pkg/math/exp_386.s
@@ -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
index 000000000..dc8404c4f
--- /dev/null
+++ b/src/pkg/math/exp_decl.go
@@ -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
index 000000000..93d6101b5
--- /dev/null
+++ b/src/pkg/math/fabs_386.s
@@ -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
index 000000000..9071f49d8
--- /dev/null
+++ b/src/pkg/math/fabs_decl.go
@@ -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
index 000000000..3a21820f0
--- /dev/null
+++ b/src/pkg/math/floor_386.s
@@ -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
index 000000000..09f5646e3
--- /dev/null
+++ b/src/pkg/math/floor_decl.go
@@ -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
index 000000000..56eaa6ec5
--- /dev/null
+++ b/src/pkg/math/log_386.s
@@ -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
index 000000000..ddae43642
--- /dev/null
+++ b/src/pkg/math/log_decl.go
@@ -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
index 000000000..16edc7a1b
--- /dev/null
+++ b/src/pkg/math/sin_386.s
@@ -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
index 000000000..fc37b032c
--- /dev/null
+++ b/src/pkg/math/sin_decl.go
@@ -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
index 000000000..f37b89ece
--- /dev/null
+++ b/src/pkg/math/tan_386.s
@@ -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
index 000000000..2796b3501
--- /dev/null
+++ b/src/pkg/math/tan_decl.go
@@ -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