]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/fpu/s_expm1l.S
Replace FSF snail mail address with URLs.
[thirdparty/glibc.git] / sysdeps / x86_64 / fpu / s_expm1l.S
1 /* ix87 specific implementation of exp(x)-1.
2 Copyright (C) 1996,1997,2001,2002,2008,2009,2012 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
5 Based on code by John C. Bowman <bowman@ipp-garching.mpg.de>.
6 Corrections by H.J. Lu (hjl@gnu.ai.mit.edu), 1997.
7
8 The GNU C Library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 The GNU C Library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with the GNU C Library; if not, see
20 <http://www.gnu.org/licenses/>. */
21
22 /* Using: e^x - 1 = 2^(x * log2(e)) - 1 */
23
24 #include <machine/asm.h>
25
26 .section .rodata
27
28 .align ALIGNARG(4)
29 ASM_TYPE_DIRECTIVE(minus1,@object)
30 minus1: .double -1.0
31 ASM_SIZE_DIRECTIVE(minus1)
32 ASM_TYPE_DIRECTIVE(one,@object)
33 one: .double 1.0
34 ASM_SIZE_DIRECTIVE(one)
35 ASM_TYPE_DIRECTIVE(l2e,@object)
36 l2e: .tfloat 1.442695040888963407359924681002
37 ASM_SIZE_DIRECTIVE(l2e)
38
39 #ifdef PIC
40 #define MO(op) op##(%rip)
41 #else
42 #define MO(op) op
43 #endif
44
45 .text
46 ENTRY(__expm1l)
47 movzwl 8+8(%rsp), %eax // load sign bit and 15-bit exponent
48 xorb $0x80, %ah // invert sign bit (now 1 is "positive")
49 cmpl $0xc006, %eax // is num positive and exp >= 6 (number is >= 128.0)?
50 jae __expl // (if num is denormal, it is at least >= 64.0)
51
52 fldt 8(%rsp) // x
53 fxam // Is NaN or +-Inf?
54 fstsw %ax
55 movb $0x45, %ch
56 andb %ah, %ch
57 cmpb $0x40, %ch
58 je 3f // If +-0, jump.
59 cmpb $0x05, %ch
60 je 2f // If +-Inf, jump.
61
62 fldt MO(l2e) // log2(e) : x
63 fmulp // log2(e)*x
64 fld %st // log2(e)*x : log2(e)*x
65 frndint // int(log2(e)*x) : log2(e)*x
66 fsubr %st, %st(1) // int(log2(e)*x) : fract(log2(e)*x)
67 fxch // fract(log2(e)*x) : int(log2(e)*x)
68 f2xm1 // 2^fract(log2(e)*x)-1 : int(log2(e)*x)
69 fscale // 2^(log2(e)*x)-2^int(log2(e)*x) : int(log2(e)*x)
70 fxch // int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
71 fldl MO(one) // 1 : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
72 fscale // 2^int(log2(e)*x) : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
73 fsubrl MO(one) // 1-2^int(log2(e)*x) : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
74 fstp %st(1) // 1-2^int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
75 fsubrp %st, %st(1) // 2^(log2(e)*x)-1
76 ret
77
78 2: testl $0x200, %eax // Test sign.
79 jz 3f // If positive, jump.
80 fstp %st
81 fldl MO(minus1) // Set result to -1.0.
82 3: ret
83 END(__expm1l)
84 libm_hidden_def (__expm1l)
85 weak_alias (__expm1l, expm1l)