gitee.com/quant1x/num@v0.3.2/math32/log_amd64.s (about)

     1  // Copyright 2010 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSS-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "textflag.h"
     6  
     7  #define HSqrt2 7.07106781186547524401e-01 // sqrt(2)/2
     8  #define Ln2Hi  6.9313812256e-01   // 0x3f317180
     9  #define Ln2Lo  9.0580006145e-06   // 0x3717f7d1
    10  #define L1     6.6666668653e-01   // 0x3f2aaaab
    11  #define L2     4.0000000596e-01   // 0x3ecccccd
    12  #define L3     2.8571429849e-01   // 0x3e924925
    13  #define L4     2.2222198546e-01   // 0x3e638e29
    14  #define L5     1.8183572590e-01   // 0x3e3a3325
    15  #define L6     1.5313838422e-01   // 0x3e1cd04f
    16  #define L7     1.4798198640e-01   // 0x3e178897
    17  #define NaN    0x7FE00000
    18  #define PosInf 0x7F800000
    19  #define NegInf 0xFF800000
    20  
    21  // func Log(x float64) float64
    22  TEXT ·Log(SB),NOSPLIT,$0
    23  	// test bits for special cases
    24  	MOVL    x+0(FP), BX
    25  	MOVQ    $~(1<<31), AX // sign bit mask
    26  	ANDQ    BX, AX
    27  	JEQ     isZero
    28  	MOVL    $0, AX
    29  	CMPL    AX, BX
    30  	JGT     isNegative
    31  	MOVL    $PosInf, AX
    32  	CMPQ    AX, BX
    33  	JLE     isInfOrNaN
    34  	// f1, ki := math.Frexp(x); k := float64(ki)
    35  	MOVL    BX, X0
    36  	MOVL    $0x007FFFFF, AX
    37  	MOVL    AX, X2
    38  	ANDPS   X0, X2
    39  	MOVSS   $0.5, X0 // 0x3FE0000000000000
    40  	ORPS    X0, X2 // X2= f1
    41  	SHRQ    $23, BX
    42  	ANDL    $0xFF, BX
    43  	SUBL    $0x7E, BX
    44  	CVTSL2SS BX, X1 // x1= k, x2= f1
    45  	// if f1 < math.Sqrt2/2 { k -= 1; f1 *= 2 }
    46  	MOVSS   $HSqrt2, X0 // x0= 0.7071, x1= k, x2= f1
    47  	CMPSS   X2, X0, 5 // cmpnlt; x0= 0 or ^0, x1= k, x2 = f1
    48  	MOVSS   $1.0, X3 // x0= 0 or ^0, x1= k, x2 = f1, x3= 1
    49  	ANDPS   X0, X3 // x0= 0 or ^0, x1= k, x2 = f1, x3= 0 or 1
    50  	SUBSS   X3, X1 // x0= 0 or ^0, x1= k, x2 = f1, x3= 0 or 1
    51  	MOVSS   $1.0, X0 // x0= 1, x1= k, x2= f1, x3= 0 or 1
    52  	ADDSS   X0, X3 // x0= 1, x1= k, x2= f1, x3= 1 or 2
    53  	MULSS   X3, X2 // x0= 1, x1= k, x2= f1
    54  	// f := f1 - 1
    55  	SUBSS   X0, X2 // x1= k, x2= f
    56  	// s := f / (2 + f)
    57  	MOVSS   $2.0, X0
    58  	ADDSS   X2, X0
    59  	MOVUPS  X2, X3
    60  	DIVSS   X0, X3 // x1=k, x2= f, x3= s
    61  	// s2 := s * s
    62  	MOVUPS  X3, X4 // x1= k, x2= f, x3= s
    63  	MULSS   X4, X4 // x1= k, x2= f, x3= s, x4= s2
    64  	// s4 := s2 * s2
    65  	MOVUPS  X4, X5 // x1= k, x2= f, x3= s, x4= s2
    66  	MULSS   X5, X5 // x1= k, x2= f, x3= s, x4= s2, x5= s4
    67  	// t1 := s2 * (L1 + s4*(L3+s4*(L5+s4*L7)))
    68  	MOVSS   $L7, X6
    69  	MULSS   X5, X6
    70  	ADDSS   $L5, X6
    71  	MULSS   X5, X6
    72  	ADDSS   $L3, X6
    73  	MULSS   X5, X6
    74  	ADDSS   $L1, X6
    75  	MULSS   X6, X4 // x1= k, x2= f, x3= s, x4= t1, x5= s4
    76  	// t2 := s4 * (L2 + s4*(L4+s4*L6))
    77  	MOVSS   $L6, X6
    78  	MULSS   X5, X6
    79  	ADDSS   $L4, X6
    80  	MULSS   X5, X6
    81  	ADDSS   $L2, X6
    82  	MULSS   X6, X5 // x1= k, x2= f, x3= s, x4= t1, x5= t2
    83  	// R := t1 + t2
    84  	ADDSS   X5, X4 // x1= k, x2= f, x3= s, x4= R
    85  	// hfsq := 0.5 * f * f
    86  	MOVSS   $0.5, X0
    87  	MULSS   X2, X0
    88  	MULSS   X2, X0 // x0= hfsq, x1= k, x2= f, x3= s, x4= R
    89  	// return k*Ln2Hi - ((hfsq - (s*(hfsq+R) + k*Ln2Lo)) - f)
    90  	ADDSS   X0, X4 // x0= hfsq, x1= k, x2= f, x3= s, x4= hfsq+R
    91  	MULSS   X4, X3 // x0= hfsq, x1= k, x2= f, x3= s*(hfsq+R)
    92  	MOVSS   $Ln2Lo, X4
    93  	MULSS   X1, X4 // x4= k*Ln2Lo
    94  	ADDSS   X4, X3 // x0= hfsq, x1= k, x2= f, x3= s*(hfsq+R)+k*Ln2Lo
    95  	SUBSS   X3, X0 // x0= hfsq-(s*(hfsq+R)+k*Ln2Lo), x1= k, x2= f
    96  	SUBSS   X2, X0 // x0= (hfsq-(s*(hfsq+R)+k*Ln2Lo))-f, x1= k
    97  	MULSS   $Ln2Hi, X1 // x0= (hfsq-(s*(hfsq+R)+k*Ln2Lo))-f, x1= k*Ln2Hi
    98  	SUBSS   X0, X1 // x1= k*Ln2Hi-((hfsq-(s*(hfsq+R)+k*Ln2Lo))-f)
    99    	MOVSS   X1, ret+8(FP)
   100  	RET
   101  isInfOrNaN:
   102  	MOVL    BX, ret+8(FP) // +Inf or NaN, return x
   103  	RET
   104  isNegative:
   105  	MOVL    $NaN, AX
   106  	MOVL    AX, ret+8(FP) // return NaN
   107  	RET
   108  isZero:
   109  	MOVL    $NegInf, AX
   110  	MOVL    AX, ret+8(FP) // return -Inf
   111  	RET