1/* ix87 specific implementation of arctanh function.
2 Copyright (C) 1996-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#include <machine/asm.h>
20#include <libm-alias-finite.h>
21
22 .section .rodata
23
24 .align ALIGNARG(4)
25 /* Please note that we use double values for 0.5 and 1.0. These
26 numbers have exact representations and so we don't get accuracy
27 problems. The advantage is that the code is simpler. */
28 .type half,@object
29half: .double 0.5
30 ASM_SIZE_DIRECTIVE(half)
31 .type one,@object
32one: .double 1.0
33 ASM_SIZE_DIRECTIVE(one)
34 /* It is not important that this constant is precise. It is only
35 a value which is known to be on the safe side for using the
36 fyl2xp1 instruction. */
37 .type limit,@object
38limit: .double 0.29
39 ASM_SIZE_DIRECTIVE(limit)
40 .align ALIGNARG(4)
41 .type ln2_2,@object
42ln2_2: .quad 0xb17217f7d1cf79ac /* 0.3465735902799726547086160 */
43 .short 0x3ffd
44 ASM_SIZE_DIRECTIVE(ln2_2)
45
46#ifdef PIC
47#define MO(op) op##@GOTOFF(%edx)
48#else
49#define MO(op) op
50#endif
51
52 .text
53ENTRY(__ieee754_atanhl)
54 movl 12(%esp), %ecx
55
56 movl %ecx, %eax
57 andl $0x7fff, %eax
58 cmpl $0x7fff, %eax
59 je 5f
60 cmpl $0x3fdf, %eax
61 jge 7f
62 // Exponent below -32; return x, with underflow if subnormal.
63 fldt 4(%esp)
64 cmpl $0, %eax
65 jne 8f
66 fld %st(0)
67 fmul %st(0)
68 fstp %st(0)
698: ret
707:
71
72#ifdef PIC
73 LOAD_PIC_REG (dx)
74#endif
75
76 andl $0x8000, %ecx // ECX == 0 iff X >= 0
77
78 fldt MO(ln2_2) // 0.5*ln2
79 xorl %ecx, 12(%esp)
80 fldt 4(%esp) // |x| : 0.5*ln2
81 fcoml MO(half) // |x| : 0.5*ln2
82 fld %st(0) // |x| : |x| : 0.5*ln2
83 fnstsw // |x| : |x| : 0.5*ln2
84 sahf
85 jae 2f
86 fadd %st, %st(1) // |x| : 2*|x| : 0.5*ln2
87 fld %st // |x| : |x| : 2*|x| : 0.5*ln2
88 fsubrl MO(one) // 1-|x| : |x| : 2*|x| : 0.5*ln2
89 fxch // |x| : 1-|x| : 2*|x| : 0.5*ln2
90 fmul %st(2) // 2*|x|^2 : 1-|x| : 2*|x| : 0.5*ln2
91 fdivp // (2*|x|^2)/(1-|x|) : 2*|x| : 0.5*ln2
92 faddp // 2*|x|+(2*|x|^2)/(1-|x|) : 0.5*ln2
93 fcoml MO(limit) // 2*|x|+(2*|x|^2)/(1-|x|) : 0.5*ln2
94 fnstsw // 2*|x|+(2*|x|^2)/(1-|x|) : 0.5*ln2
95 sahf
96 jae 4f
97 fyl2xp1 // 0.5*ln2*ld(1+2*|x|+(2*|x|^2)/(1-|x|))
98 jecxz 3f
99 fchs // 0.5*ln2*ld(1+2*x+(2*x^2)/(1-x))
1003: ret
101
102 .align ALIGNARG(4)
1034: faddl MO(one) // 1+2*|x|+(2*|x|^2)/(1-|x|) : 0.5*ln2
104 fyl2x // 0.5*ln2*ld(1+2*|x|+(2*|x|^2)/(1-|x|))
105 jecxz 3f
106 fchs // 0.5*ln2*ld(1+2*x+(2*x^2)/(1-x))
1073: ret
108
109 .align ALIGNARG(4)
1102: faddl MO(one) // 1+|x| : |x| : 0.5*ln2
111 fxch // |x| : 1+|x| : 0.5*ln2
112 fsubrl MO(one) // 1-|x| : 1+|x| : 0.5*ln2
113 fdivrp // (1+|x|)/(1-|x|) : 0.5*ln2
114 fyl2x // 0.5*ln2*ld((1+|x|)/(1-|x|))
115 jecxz 3f
116 fchs // 0.5*ln2*ld((1+x)/(1-x))
1173: ret
118
119 // x == NaN or ħInf
1205: cmpl $0x80000000, 8(%esp)
121 ja 6f
122 cmpl $0, 4(%esp)
123 je 7b
1246: fldt 4(%esp)
125 fadd %st(0)
126 ret
127END(__ieee754_atanhl)
128libm_alias_finite (__ieee754_atanhl, __atanhl)
129

source code of glibc/sysdeps/i386/fpu/e_atanhl.S