From 7f11db5ea9862d2c09e5984109f3092cb3f006fc Mon Sep 17 00:00:00 2001 From: "Charles L. Dorian" Date: Fri, 15 Jan 2010 13:21:36 -0800 Subject: [PATCH] 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 --- src/pkg/math/Makefile | 8 +++++++ src/pkg/math/asin_386.s | 28 ++++++++++++++++++++++++ src/pkg/math/asin_decl.go | 8 +++++++ src/pkg/math/atan_386.s | 11 ++++++++++ src/pkg/math/atan_decl.go | 7 ++++++ src/pkg/math/exp_386.s | 40 +++++++++++++++++++++++++++++++++ src/pkg/math/exp_decl.go | 7 ++++++ src/pkg/math/fabs_386.s | 10 +++++++++ src/pkg/math/fabs_decl.go | 7 ++++++ src/pkg/math/floor_386.s | 31 ++++++++++++++++++++++++++ src/pkg/math/floor_decl.go | 8 +++++++ src/pkg/math/log_386.s | 19 ++++++++++++++++ src/pkg/math/log_decl.go | 8 +++++++ src/pkg/math/sin_386.s | 45 ++++++++++++++++++++++++++++++++++++++ src/pkg/math/sin_decl.go | 8 +++++++ src/pkg/math/tan_386.s | 26 ++++++++++++++++++++++ src/pkg/math/tan_decl.go | 7 ++++++ 17 files changed, 278 insertions(+) create mode 100644 src/pkg/math/asin_386.s create mode 100644 src/pkg/math/asin_decl.go create mode 100644 src/pkg/math/atan_386.s create mode 100644 src/pkg/math/atan_decl.go create mode 100644 src/pkg/math/exp_386.s create mode 100644 src/pkg/math/exp_decl.go create mode 100644 src/pkg/math/fabs_386.s create mode 100644 src/pkg/math/fabs_decl.go create mode 100644 src/pkg/math/floor_386.s create mode 100644 src/pkg/math/floor_decl.go create mode 100644 src/pkg/math/log_386.s create mode 100644 src/pkg/math/log_decl.go create mode 100644 src/pkg/math/sin_386.s create mode 100644 src/pkg/math/sin_decl.go create mode 100644 src/pkg/math/tan_386.s create mode 100644 src/pkg/math/tan_decl.go diff --git a/src/pkg/math/Makefile b/src/pkg/math/Makefile index 7a3808976a..be9b6ff639 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 0000000000..0b52bcd514 --- /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 0000000000..63a55dce9a --- /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 0000000000..8212e28e4d --- /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 0000000000..14d3fc0149 --- /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 0000000000..2ac45fa7be --- /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 0000000000..dc8404c4fe --- /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 0000000000..93d6101b55 --- /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 0000000000..9071f49d8c --- /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 0000000000..3a21820f07 --- /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 0000000000..09f5646e3e --- /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 0000000000..56eaa6ec55 --- /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 0000000000..ddae43642e --- /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 0000000000..16edc7a1b2 --- /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 0000000000..fc37b032c9 --- /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 0000000000..f37b89ece3 --- /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 0000000000..2796b35010 --- /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 -- 2.50.0