1
0
mirror of https://github.com/golang/go synced 2024-11-22 01:04:40 -07:00

math: 386 FPU functions

sin, cos, tan, asin, acos, atan, exp, log, log10,
floor, ceil, and fabs

R=rsc
CC=golang-dev
https://golang.org/cl/189083
This commit is contained in:
Charles L. Dorian 2010-01-15 13:21:36 -08:00 committed by Russ Cox
parent ff68f96df0
commit 7f11db5ea9
17 changed files with 278 additions and 0 deletions

View 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))

28
src/pkg/math/asin_386.s Normal file
View File

@ -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

View File

@ -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

11
src/pkg/math/atan_386.s Normal file
View File

@ -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

View File

@ -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

40
src/pkg/math/exp_386.s Normal file
View File

@ -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

7
src/pkg/math/exp_decl.go Normal file
View File

@ -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

10
src/pkg/math/fabs_386.s Normal file
View File

@ -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

View File

@ -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

31
src/pkg/math/floor_386.s Normal file
View File

@ -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

View File

@ -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

19
src/pkg/math/log_386.s Normal file
View File

@ -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

8
src/pkg/math/log_decl.go Normal file
View File

@ -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

45
src/pkg/math/sin_386.s Normal file
View File

@ -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

8
src/pkg/math/sin_decl.go Normal file
View File

@ -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

26
src/pkg/math/tan_386.s Normal file
View File

@ -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

7
src/pkg/math/tan_decl.go Normal file
View File

@ -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