1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 #include "textflag.h" 6 7 // Minimax polynomial approximations 8 DATA logrodataL21<> + 0(SB)/8, $-.499999999999999778E+00 9 DATA logrodataL21<> + 8(SB)/8, $0.333333333333343751E+00 10 DATA logrodataL21<> + 16(SB)/8, $-.250000000001606881E+00 11 DATA logrodataL21<> + 24(SB)/8, $0.199999999971603032E+00 12 DATA logrodataL21<> + 32(SB)/8, $-.166666663114122038E+00 13 DATA logrodataL21<> + 40(SB)/8, $-.125002923782692399E+00 14 DATA logrodataL21<> + 48(SB)/8, $0.111142014580396256E+00 15 DATA logrodataL21<> + 56(SB)/8, $0.759438932618934220E-01 16 DATA logrodataL21<> + 64(SB)/8, $0.142857144267212549E+00 17 DATA logrodataL21<> + 72(SB)/8, $-.993038938793590759E-01 18 DATA logrodataL21<> + 80(SB)/8, $-1.0 19 GLOBL logrodataL21<> + 0(SB), RODATA, $88 20 21 // Constants 22 DATA logxminf<> + 0(SB)/8, $0xfff0000000000000 23 GLOBL logxminf<> + 0(SB), RODATA, $8 24 DATA logxnan<> + 0(SB)/8, $0x7ff8000000000000 25 GLOBL logxnan<> + 0(SB), RODATA, $8 26 DATA logx43f<> + 0(SB)/8, $0x43f0000000000000 27 GLOBL logx43f<> + 0(SB), RODATA, $8 28 DATA logxl2<> + 0(SB)/8, $0x3fda7aecbeba4e46 29 GLOBL logxl2<> + 0(SB), RODATA, $8 30 DATA logxl1<> + 0(SB)/8, $0x3ffacde700000000 31 GLOBL logxl1<> + 0(SB), RODATA, $8 32 33 /* Input transform scale and add constants */ 34 DATA logxm<> + 0(SB)/8, $0x3fc77604e63c84b1 35 DATA logxm<> + 8(SB)/8, $0x40fb39456ab53250 36 DATA logxm<> + 16(SB)/8, $0x3fc9ee358b945f3f 37 DATA logxm<> + 24(SB)/8, $0x40fb39418bf3b137 38 DATA logxm<> + 32(SB)/8, $0x3fccfb2e1304f4b6 39 DATA logxm<> + 40(SB)/8, $0x40fb393d3eda3022 40 DATA logxm<> + 48(SB)/8, $0x3fd0000000000000 41 DATA logxm<> + 56(SB)/8, $0x40fb393969e70000 42 DATA logxm<> + 64(SB)/8, $0x3fd11117aafbfe04 43 DATA logxm<> + 72(SB)/8, $0x40fb3936eaefafcf 44 DATA logxm<> + 80(SB)/8, $0x3fd2492af5e658b2 45 DATA logxm<> + 88(SB)/8, $0x40fb39343ff01715 46 DATA logxm<> + 96(SB)/8, $0x3fd3b50c622a43dd 47 DATA logxm<> + 104(SB)/8, $0x40fb39315adae2f3 48 DATA logxm<> + 112(SB)/8, $0x3fd56bbeea918777 49 DATA logxm<> + 120(SB)/8, $0x40fb392e21698552 50 GLOBL logxm<> + 0(SB), RODATA, $128 51 52 // Log returns the natural logarithm of the argument. 53 // 54 // Special cases are: 55 // Log(+Inf) = +Inf 56 // Log(0) = -Inf 57 // Log(x < 0) = NaN 58 // Log(NaN) = NaN 59 // The algorithm used is minimax polynomial approximation using a table of 60 // polynomial coefficients determined with a Remez exchange algorithm. 61 62 TEXT logAsm(SB), NOSPLIT, $0-16 63 FMOVD x+0(FP), F0 64 MOVD $logrodataL21<>+0(SB), R9 65 MOVH $0x8006, R4 66 WORD $0xB3CD0010 //lgdr %r1,%f0 67 MOVD $0x3FF0000000000000, R6 68 SRAD $48, R1, R1 69 MOVD $0x40F03E8000000000, R8 70 SUBW R1, R4 71 WORD $0xEC2420BB //risbg %r2,%r4,32,128+59,0 72 BYTE $0x00 73 BYTE $0x55 74 WORD $0xEC62000F //risbgn %r6,%r2,64-64+0,64-64+0+16-1,64-0-16 75 BYTE $0x30 76 BYTE $0x59 77 WORD $0xEC82101F //risbgn %r8,%r2,64-64+16,64-64+16+16-1,64-16-16 78 BYTE $0x20 79 BYTE $0x59 80 MOVW R1, R7 81 CMPBGT R7, $22, L17 82 WORD $0xB3120000 //ltdbr %f0,%f0 83 MOVD $logx43f<>+0(SB), R1 84 FMOVD 0(R1), F2 85 BLEU L3 86 MOVH $0x8005, R12 87 MOVH $0x8405, R0 88 BR L15 89 L7: 90 WORD $0xB3120000 //ltdbr %f0,%f0 91 BLEU L3 92 L15: 93 FMUL F2, F0 94 WORD $0xB3CD0010 //lgdr %r1,%f0 95 SRAD $48, R1, R1 96 SUBW R1, R0, R2 97 SUBW R1, R12, R3 98 BYTE $0x18 //lr %r4,%r2 99 BYTE $0x42 100 ANDW $0xFFFFFFF0, R3 101 ANDW $0xFFFFFFF0, R2 102 BYTE $0x18 //lr %r5,%r1 103 BYTE $0x51 104 MOVW R1, R7 105 CMPBLE R7, $22, L7 106 WORD $0xEC63000F //risbgn %r6,%r3,64-64+0,64-64+0+16-1,64-0-16 107 BYTE $0x30 108 BYTE $0x59 109 WORD $0xEC82101F //risbgn %r8,%r2,64-64+16,64-64+16+16-1,64-16-16 110 BYTE $0x20 111 BYTE $0x59 112 L2: 113 MOVH R5, R5 114 MOVH $0x7FEF, R1 115 CMPW R5, R1 116 BGT L1 117 WORD $0xB3C10026 //ldgr %f2,%r6 118 FMUL F2, F0 119 WORD $0xEC4439BB //risbg %r4,%r4,57,128+59,3 120 BYTE $0x03 121 BYTE $0x55 122 FMOVD 80(R9), F2 123 MOVD $logxm<>+0(SB), R7 124 ADD R7, R4 125 FMOVD 72(R9), F4 126 WORD $0xED004000 //madb %f2,%f0,0(%r4) 127 BYTE $0x20 128 BYTE $0x1E 129 FMOVD 64(R9), F1 130 FMOVD F2, F0 131 FMOVD 56(R9), F2 132 WFMADB V0, V2, V4, V2 133 WFMDB V0, V0, V6 134 FMOVD 48(R9), F4 135 WFMADB V0, V2, V4, V2 136 FMOVD 40(R9), F4 137 WFMADB V2, V6, V1, V2 138 FMOVD 32(R9), F1 139 WFMADB V6, V4, V1, V4 140 FMOVD 24(R9), F1 141 WFMADB V6, V2, V1, V2 142 FMOVD 16(R9), F1 143 WFMADB V6, V4, V1, V4 144 MOVD $logxl1<>+0(SB), R1 145 FMOVD 8(R9), F1 146 WFMADB V6, V2, V1, V2 147 FMOVD 0(R9), F1 148 WFMADB V6, V4, V1, V4 149 FMOVD 8(R4), F1 150 WFMADB V0, V2, V4, V2 151 WORD $0xB3C10048 //ldgr %f4,%r8 152 WFMADB V6, V2, V0, V2 153 WORD $0xED401000 //msdb %f1,%f4,0(%r1) 154 BYTE $0x10 155 BYTE $0x1F 156 MOVD logxl2<>+0(SB), R1 157 WORD $0xB3130001 //lcdbr %f0,%f1 158 WORD $0xB3C10041 //ldgr %f4,%r1 159 WFMADB V0, V4, V2, V0 160 L1: 161 FMOVD F0, ret+8(FP) 162 RET 163 L3: 164 WORD $0xB3120000 //ltdbr %f0,%f0 165 BEQ L20 166 BGE L1 167 BVS L1 168 169 MOVD $logxnan<>+0(SB), R1 170 FMOVD 0(R1), F0 171 BR L1 172 L20: 173 MOVD $logxminf<>+0(SB), R1 174 FMOVD 0(R1), F0 175 FMOVD F0, ret+8(FP) 176 RET 177 L17: 178 BYTE $0x18 //lr %r5,%r1 179 BYTE $0x51 180 BR L2 181