]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/fpu/s_expm1.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / i386 / fpu / s_expm1.S
1 /* ix87 specific implementation of exp(x)-1.
2 Copyright (C) 1996-2017 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 <sysdep.h>
25 #include <machine/asm.h>
26 #include <i386-math-asm.h>
27
28 .section .rodata
29
30 .align ALIGNARG(4)
31 .type minus1,@object
32 minus1: .double -1.0
33 ASM_SIZE_DIRECTIVE(minus1)
34 .type one,@object
35 one: .double 1.0
36 ASM_SIZE_DIRECTIVE(one)
37 .type l2e,@object
38 l2e: .tfloat 1.442695040888963407359924681002
39 ASM_SIZE_DIRECTIVE(l2e)
40
41 DEFINE_DBL_MIN
42
43 #ifdef PIC
44 #define MO(op) op##@GOTOFF(%edx)
45 #else
46 #define MO(op) op
47 #endif
48
49 .text
50 ENTRY(__expm1)
51 movzwl 4+6(%esp), %eax
52 xorb $0x80, %ah // invert sign bit (now 1 is "positive")
53 cmpl $0xc086, %eax // is num >= 704?
54 jae HIDDEN_JUMPTARGET (__exp)
55
56 fldl 4(%esp) // x
57 fxam // Is NaN, +-Inf or +-0?
58 xorb $0x80, %ah
59 cmpl $0xc043, %eax // is num <= -38.0?
60 fstsw %ax
61 movb $0x45, %ch
62 jb 4f
63
64 // Below -38.0 (may be -NaN or -Inf).
65 andb %ah, %ch
66 #ifdef PIC
67 LOAD_PIC_REG (dx)
68 #endif
69 cmpb $0x01, %ch
70 je 5f // If -NaN, jump.
71 jmp 2f // -large, possibly -Inf.
72
73 4: // In range -38.0 to 704.0 (may be +-0 but not NaN or +-Inf).
74 andb %ah, %ch
75 cmpb $0x40, %ch
76 je 3f // If +-0, jump.
77 #ifdef PIC
78 LOAD_PIC_REG (dx)
79 #endif
80
81 5: fldt MO(l2e) // log2(e) : x
82 fmulp // log2(e)*x
83 fld %st // log2(e)*x : log2(e)*x
84 // Set round-to-nearest temporarily.
85 subl $8, %esp
86 cfi_adjust_cfa_offset (8)
87 fstcw 4(%esp)
88 movl $0xf3ff, %ecx
89 andl 4(%esp), %ecx
90 movl %ecx, (%esp)
91 fldcw (%esp)
92 frndint // int(log2(e)*x) : log2(e)*x
93 fldcw 4(%esp)
94 addl $8, %esp
95 cfi_adjust_cfa_offset (-8)
96 fsubr %st, %st(1) // int(log2(e)*x) : fract(log2(e)*x)
97 fxch // fract(log2(e)*x) : int(log2(e)*x)
98 f2xm1 // 2^fract(log2(e)*x)-1 : int(log2(e)*x)
99 fscale // 2^(log2(e)*x)-2^int(log2(e)*x) : int(log2(e)*x)
100 fxch // int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
101 fldl MO(one) // 1 : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
102 fscale // 2^int(log2(e)*x) : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
103 fsubrl MO(one) // 1-2^int(log2(e)*x) : int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
104 fstp %st(1) // 1-2^int(log2(e)*x) : 2^(log2(e)*x)-2^int(log2(e)*x)
105 fsubrp %st, %st(1) // 2^(log2(e)*x)
106 DBL_CHECK_FORCE_UFLOW
107 ret
108
109 2: fstp %st
110 fldl MO(minus1) // Set result to -1.0.
111 3: ret
112 END(__expm1)
113 weak_alias (__expm1, expm1)