1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 *
5 * Adapted for `long double' by Ulrich Drepper <drepper@cygnus.com>.
6 * Adapted for x86-64 by Andreas Jaeger <aj@suse.de>
7 *
8 * Correct handling of y==-inf <drepper@gnu>
9 */
10
11#include <machine/asm.h>
12
13 .section .rodata
14
15 .align ALIGNARG(4)
16 .type zero_nan,@object
17zero_nan:
18 .double 0.0
19nan: .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
20 .byte 0, 0, 0, 0, 0, 0, 0, 0x80
21 .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
22 ASM_SIZE_DIRECTIVE(zero_nan)
23
24
25#ifdef PIC
26# define MO(op) op##(%rip)
27#else
28# define MO(op) op
29#endif
30
31 .text
32ENTRY(__ieee754_scalbl)
33 fldt 24(%rsp)
34 fxam
35 fnstsw
36 fldt 8(%rsp)
37 andl $0x4700, %eax
38 cmpl $0x0700, %eax
39 je 1f
40 andl $0x4500, %eax
41 cmpl $0x0100, %eax
42 je 2f
43 fxam
44 fnstsw
45 andl $0x4500, %eax
46 cmpl $0x0100, %eax
47 je 2f
48 fld %st(1)
49 frndint
50 fcomip %st(2), %st
51 jne 4f
52 fscale
53 fstp %st(1)
54 ret
55
56 /* y is -inf */
571: fxam
58 fnstsw
59 movl 16(%rsp), %edx
60 shrl $5, %eax
61 fstp %st
62 fstp %st
63 andl $0x8000, %edx
64 andl $0x0228, %eax
65 cmpl $0x0028, %eax
66 je 4f
67 andl $8, %eax
68 shrl $11, %edx
69 addl %edx, %eax
70#ifdef PIC
71 lea zero_nan(%rip),%rdx
72 fldl (%rdx,%rax,1)
73#else
74 fldl zero_nan(%rax, 1)
75#endif
76 ret
77
78 /* The result is NaN; raise an exception for sNaN arguments. */
792: faddp
80 ret
81
82 /* Return NaN and raise the invalid exception. */
834: fstp %st
84 fstp %st
85 fldz
86 fdiv %st
87 ret
88END(__ieee754_scalbl)
89strong_alias (__ieee754_scalbl, __scalbl_finite)
90