mirror of
https://github.com/golang/go
synced 2024-11-14 15:00:27 -07:00
88672de7af
As necessary, math functions were structured to use stubs, so that they can be accelerated with assembly on any platform. Technique used was minimax polynomial approximation using tables of polynomial coefficients, with argument range reduction. Benchmark New Old Speedup BenchmarkAcos 12.2 47.5 3.89 BenchmarkAcosh 18.5 56.2 3.04 BenchmarkAsin 13.1 40.6 3.10 BenchmarkAsinh 19.4 62.8 3.24 BenchmarkAtan 10.1 23 2.28 BenchmarkAtanh 19.1 53.2 2.79 BenchmarkAtan2 16.5 33.9 2.05 BenchmarkCbrt 14.8 58 3.92 BenchmarkErf 10.8 20.1 1.86 BenchmarkErfc 11.2 23.5 2.10 BenchmarkExp 8.77 53.8 6.13 BenchmarkExpm1 10.1 38.3 3.79 BenchmarkLog 13.1 40.1 3.06 BenchmarkLog1p 12.7 38.3 3.02 BenchmarkPowInt 31.7 40.5 1.28 BenchmarkPowFrac 33.1 141 4.26 BenchmarkTan 11.5 30 2.61 Accuracy was tested against a high precision reference function to determine maximum error. Note: ulperr is error in "units in the last place" max ulperr Acos 1.15 Acosh 1.07 Asin 2.22 Asinh 1.72 Atan 1.41 Atanh 3.00 Atan2 1.45 Cbrt 1.18 Erf 1.29 Erfc 4.82 Exp 1.00 Expm1 2.26 Log 0.94 Log1p 2.39 Tan 3.14 Pow will have 99.99% correctly rounded results with reasonable inputs producing numeric (non Inf or NaN) results Change-Id: I850e8cf7b70426e8b54ec49d74acd4cddc8c6cb2 Reviewed-on: https://go-review.googlesource.com/38585 Reviewed-by: Michael Munday <munday@ca.ibm.com> Run-TryBot: Michael Munday <munday@ca.ibm.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
186 lines
5.0 KiB
ArmAsm
186 lines
5.0 KiB
ArmAsm
// Copyright 2017 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.
|
|
|
|
#include "textflag.h"
|
|
|
|
// Minimax polynomial approximation and other constants
|
|
DATA ·exprodataL22<> + 0(SB)/8, $800.0E+00
|
|
DATA ·exprodataL22<> + 8(SB)/8, $1.0000000000000022e+00
|
|
DATA ·exprodataL22<> + 16(SB)/8, $0.500000000000004237e+00
|
|
DATA ·exprodataL22<> + 24(SB)/8, $0.166666666630345592e+00
|
|
DATA ·exprodataL22<> + 32(SB)/8, $0.138926439368309441e-02
|
|
DATA ·exprodataL22<> + 40(SB)/8, $0.833349307718286047e-02
|
|
DATA ·exprodataL22<> + 48(SB)/8, $0.416666664838056960e-01
|
|
DATA ·exprodataL22<> + 56(SB)/8, $-.231904681384629956E-16
|
|
DATA ·exprodataL22<> + 64(SB)/8, $-.693147180559945286E+00
|
|
DATA ·exprodataL22<> + 72(SB)/8, $0.144269504088896339E+01
|
|
DATA ·exprodataL22<> + 80(SB)/8, $704.0E+00
|
|
GLOBL ·exprodataL22<> + 0(SB), RODATA, $88
|
|
|
|
DATA ·expxinf<> + 0(SB)/8, $0x7ff0000000000000
|
|
GLOBL ·expxinf<> + 0(SB), RODATA, $8
|
|
DATA ·expx4ff<> + 0(SB)/8, $0x4ff0000000000000
|
|
GLOBL ·expx4ff<> + 0(SB), RODATA, $8
|
|
DATA ·expx2ff<> + 0(SB)/8, $0x2ff0000000000000
|
|
GLOBL ·expx2ff<> + 0(SB), RODATA, $8
|
|
DATA ·expxaddexp<> + 0(SB)/8, $0xc2f0000100003fef
|
|
GLOBL ·expxaddexp<> + 0(SB), RODATA, $8
|
|
|
|
// Log multipliers table
|
|
DATA ·exptexp<> + 0(SB)/8, $0.442737824274138381E-01
|
|
DATA ·exptexp<> + 8(SB)/8, $0.263602189790660309E-01
|
|
DATA ·exptexp<> + 16(SB)/8, $0.122565642281703586E-01
|
|
DATA ·exptexp<> + 24(SB)/8, $0.143757052860721398E-02
|
|
DATA ·exptexp<> + 32(SB)/8, $-.651375034121276075E-02
|
|
DATA ·exptexp<> + 40(SB)/8, $-.119317678849450159E-01
|
|
DATA ·exptexp<> + 48(SB)/8, $-.150868749549871069E-01
|
|
DATA ·exptexp<> + 56(SB)/8, $-.161992609578469234E-01
|
|
DATA ·exptexp<> + 64(SB)/8, $-.154492360403337917E-01
|
|
DATA ·exptexp<> + 72(SB)/8, $-.129850717389178721E-01
|
|
DATA ·exptexp<> + 80(SB)/8, $-.892902649276657891E-02
|
|
DATA ·exptexp<> + 88(SB)/8, $-.338202636596794887E-02
|
|
DATA ·exptexp<> + 96(SB)/8, $0.357266307045684762E-02
|
|
DATA ·exptexp<> + 104(SB)/8, $0.118665304327406698E-01
|
|
DATA ·exptexp<> + 112(SB)/8, $0.214434994118118914E-01
|
|
DATA ·exptexp<> + 120(SB)/8, $0.322580645161290314E-01
|
|
GLOBL ·exptexp<> + 0(SB), RODATA, $128
|
|
|
|
// Exp returns e**x, the base-e exponential of x.
|
|
//
|
|
// Special cases are:
|
|
// Exp(+Inf) = +Inf
|
|
// Exp(NaN) = NaN
|
|
// Very large values overflow to 0 or +Inf.
|
|
// Very small values underflow to 1.
|
|
// The algorithm used is minimax polynomial approximation using a table of
|
|
// polynomial coefficients determined with a Remez exchange algorithm.
|
|
|
|
TEXT ·expAsm(SB), NOSPLIT, $0-16
|
|
FMOVD x+0(FP), F0
|
|
MOVD $·exprodataL22<>+0(SB), R5
|
|
WORD $0xB3120000 //ltdbr %f0,%f0
|
|
BLTU L20
|
|
FMOVD F0, F2
|
|
L2:
|
|
WORD $0xED205050 //cdb %f2,.L23-.L22(%r5)
|
|
BYTE $0x00
|
|
BYTE $0x19
|
|
BGE L16
|
|
BVS L16
|
|
WFCEDBS V2, V2, V2
|
|
BVS LEXITTAGexp
|
|
MOVD $·expxaddexp<>+0(SB), R1
|
|
FMOVD 72(R5), F6
|
|
FMOVD 0(R1), F2
|
|
WFMSDB V0, V6, V2, V6
|
|
FMOVD 64(R5), F4
|
|
FADD F6, F2
|
|
FMOVD 56(R5), F1
|
|
FMADD F4, F2, F0
|
|
FMOVD 48(R5), F3
|
|
WFMADB V2, V1, V0, V2
|
|
FMOVD 40(R5), F1
|
|
FMOVD 32(R5), F4
|
|
FMUL F0, F0
|
|
WFMADB V2, V4, V1, V4
|
|
WORD $0xB3CD0016 //lgdr %r1,%f6
|
|
FMOVD 24(R5), F1
|
|
WFMADB V2, V3, V1, V3
|
|
FMOVD 16(R5), F1
|
|
WFMADB V0, V4, V3, V4
|
|
FMOVD 8(R5), F3
|
|
WFMADB V2, V1, V3, V1
|
|
WORD $0xEC3139BC //risbg %r3,%r1,57,128+60,3
|
|
BYTE $0x03
|
|
BYTE $0x55
|
|
WFMADB V0, V4, V1, V0
|
|
MOVD $·exptexp<>+0(SB), R2
|
|
WORD $0x68432000 //ld %f4,0(%r3,%r2)
|
|
FMADD F4, F2, F2
|
|
SLD $48, R1, R2
|
|
WFMADB V2, V0, V4, V2
|
|
WORD $0xB3C10002 //ldgr %f0,%r2
|
|
FMADD F0, F2, F0
|
|
FMOVD F0, ret+8(FP)
|
|
RET
|
|
L16:
|
|
WFCEDBS V2, V2, V4
|
|
BVS LEXITTAGexp
|
|
WORD $0xED205000 //cdb %f2,.L33-.L22(%r5)
|
|
BYTE $0x00
|
|
BYTE $0x19
|
|
BLT L6
|
|
WFCEDBS V2, V0, V0
|
|
BVS L13
|
|
MOVD $·expxinf<>+0(SB), R1
|
|
FMOVD 0(R1), F0
|
|
FMOVD F0, ret+8(FP)
|
|
RET
|
|
L20:
|
|
WORD $0xB3130020 //lcdbr %f2,%f0
|
|
BR L2
|
|
L6:
|
|
MOVD $·expxaddexp<>+0(SB), R1
|
|
FMOVD 72(R5), F3
|
|
FMOVD 0(R1), F4
|
|
WFMSDB V0, V3, V4, V3
|
|
FMOVD 64(R5), F6
|
|
FADD F3, F4
|
|
FMOVD 56(R5), F5
|
|
WFMADB V4, V6, V0, V6
|
|
FMOVD 32(R5), F1
|
|
WFMADB V4, V5, V6, V4
|
|
FMOVD 40(R5), F5
|
|
FMUL F6, F6
|
|
WFMADB V4, V1, V5, V1
|
|
FMOVD 48(R5), F7
|
|
WORD $0xB3CD0013 //lgdr %r1,%f3
|
|
FMOVD 24(R5), F5
|
|
WFMADB V4, V7, V5, V7
|
|
FMOVD 16(R5), F5
|
|
WFMADB V6, V1, V7, V1
|
|
FMOVD 8(R5), F7
|
|
WFMADB V4, V5, V7, V5
|
|
WORD $0xEC3139BC //risbg %r3,%r1,57,128+60,3
|
|
BYTE $0x03
|
|
BYTE $0x55
|
|
WFMADB V6, V1, V5, V6
|
|
MOVD $·exptexp<>+0(SB), R2
|
|
WFCHDBS V2, V0, V0
|
|
WORD $0x68132000 //ld %f1,0(%r3,%r2)
|
|
FMADD F1, F4, F4
|
|
MOVD $0x4086000000000000, R2
|
|
WFMADB V4, V6, V1, V4
|
|
BEQ L21
|
|
ADDW $0xF000, R1
|
|
WORD $0xEC21000F //risbgn %r2,%r1,64-64+0,64-64+0+16-1,64-0-16
|
|
BYTE $0x30
|
|
BYTE $0x59
|
|
WORD $0xB3C10002 //ldgr %f0,%r2
|
|
FMADD F0, F4, F0
|
|
MOVD $·expx4ff<>+0(SB), R3
|
|
FMOVD 0(R3), F2
|
|
FMUL F2, F0
|
|
FMOVD F0, ret+8(FP)
|
|
RET
|
|
L13:
|
|
FMOVD $0, F0
|
|
FMOVD F0, ret+8(FP)
|
|
RET
|
|
L21:
|
|
ADDW $0x1000, R1
|
|
WORD $0xEC21000F //risbgn %r2,%r1,64-64+0,64-64+0+16-1,64-0-16
|
|
BYTE $0x30
|
|
BYTE $0x59
|
|
WORD $0xB3C10002 //ldgr %f0,%r2
|
|
FMADD F0, F4, F0
|
|
MOVD $·expx2ff<>+0(SB), R3
|
|
FMOVD 0(R3), F2
|
|
FMUL F2, F0
|
|
FMOVD F0, ret+8(FP)
|
|
RET
|
|
LEXITTAGexp:
|
|
FMOVD F0, ret+8(FP)
|
|
RET
|