Home | History | Annotate | Download | only in math
      1 // Copyright 2010 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 // func Expm1(x float64) float64
      8 TEXT Expm1(SB),NOSPLIT,$0
      9 	FLDLN2               // F0=log(2) = 1/log2(e) ~ 0.693147
     10 	FMOVD   x+0(FP), F0  // F0=x, F1=1/log2(e)
     11 	FABS                 // F0=|x|, F1=1/log2(e)
     12 	FUCOMPP F0, F1       // compare F0 to F1
     13 	FSTSW   AX
     14 	SAHF
     15 	JCC     use_exp      // jump if F0 >= F1
     16 	FLDL2E                // F0=log2(e)
     17 	FMULD   x+0(FP), F0   // F0=x*log2(e) (-1<F0<1)
     18 	F2XM1                 // F0=e**x-1 = 2**(x*log2(e))-1
     19 	FMOVDP  F0, ret+8(FP)
     20 	RET
     21 use_exp:
     22 // test bits for not-finite
     23 	MOVL    x_hi+4(FP), AX
     24 	ANDL    $0x7ff00000, AX
     25 	CMPL    AX, $0x7ff00000
     26 	JEQ     not_finite
     27 	FLDL2E                // F0=log2(e)
     28 	FMULD   x+0(FP), F0   // F0=x*log2(e)
     29 	FMOVD   F0, F1        // F0=x*log2(e), F1=x*log2(e)
     30 	FRNDINT               // F0=int(x*log2(e)), F1=x*log2(e)
     31 	FSUBD   F0, F1        // F0=int(x*log2(e)), F1=x*log2(e)-int(x*log2(e))
     32 	FXCHD   F0, F1        // F0=x*log2(e)-int(x*log2(e)), F1=int(x*log2(e))
     33 	F2XM1                 // F0=2**(x*log2(e)-int(x*log2(e)))-1, F1=int(x*log2(e))
     34 	FLD1                  // F0=1, F1=2**(x*log2(e)-int(x*log2(e)))-1, F2=int(x*log2(e))
     35 	FADDDP  F0, F1        // F0=2**(x*log2(e)-int(x*log2(e))), F1=int(x*log2(e))
     36 	FSCALE                // F0=e**x, F1=int(x*log2(e))
     37 	FMOVDP  F0, F1        // F0=e**x
     38 	FLD1                  // F0=1, F1=e**x
     39 	FSUBDP  F0, F1        // F0=e**x-1
     40 	FMOVDP  F0, ret+8(FP)
     41 	RET
     42 not_finite:
     43 // test bits for -Inf
     44 	MOVL    x_hi+4(FP), BX
     45 	MOVL    x_lo+0(FP), CX
     46 	CMPL    BX, $0xfff00000
     47 	JNE     not_neginf
     48 	CMPL    CX, $0
     49 	JNE     not_neginf
     50 	FLD1                 // F0=1
     51 	FCHS                 // F0=-1
     52 	FMOVDP  F0, ret+8(FP)
     53 	RET
     54 not_neginf:
     55 	MOVL    CX, ret_lo+8(FP)
     56 	MOVL    BX, ret_hi+12(FP)
     57 	RET
     58