2.9
[glibc/nacl-glibc.git] / sysdeps / i386 / fpu / e_scalb.S
blob7e334a361167b245081d6fcc9a215512e443a481
1 /*
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  *
5  * Correct handling of y==-inf <drepper@gnu>
6  */
8 #include <machine/asm.h>
10 RCSID("$NetBSD: e_scalb.S,v 1.4 1995/05/08 23:49:52 jtc Exp $")
12 #ifdef __ELF__
13         .section .rodata
14 #else
15         .text
16 #endif
18         .align ALIGNARG(4)
19         ASM_TYPE_DIRECTIVE(zero_nan,@object)
20 zero_nan:
21         .double 0.0
22 nan:    .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
23 minus_zero:
24         .byte 0, 0, 0, 0, 0, 0, 0, 0x80
25         .byte 0, 0, 0, 0, 0, 0, 0xff, 0x7f
26         ASM_SIZE_DIRECTIVE(zero_nan)
29 #ifdef PIC
30 #define MO(op) op##@GOTOFF(%ecx)
31 #define MOX(op,x,f) op##@GOTOFF(%ecx,x,f)
32 #else
33 #define MO(op) op
34 #define MOX(op,x,f) op(,x,f)
35 #endif
37         .text
38 ENTRY(__ieee754_scalb)
39         fldl    12(%esp)
40         fxam
41         fnstsw
42         fldl    4(%esp)
43         andl    $0x4700, %eax
44         cmpl    $0x0700, %eax
45         je      1f
46         andl    $0x4500, %eax
47         cmpl    $0x0100, %eax
48         je      2f
49         fxam
50         fnstsw
51         andl    $0x4500, %eax
52         cmpl    $0x0100, %eax
53         je      3f
54         fld     %st(1)
55         frndint
56         fcomp   %st(2)
57         fnstsw
58         sahf
59         jne     4f
60         fscale
61         fstp    %st(1)
62         ret
64         /* y is -inf */
65 1:      fxam
66 #ifdef  PIC
67         LOAD_PIC_REG (cx)
68 #endif
69         fnstsw
70         movl    8(%esp), %edx
71         shrl    $5, %eax
72         fstp    %st
73         fstp    %st
74         andl    $0x80000000, %edx
75         andl    $8, %eax
76         jnz     4f
77         shrl    $27, %edx
78         addl    %edx, %eax
79         fldl    MOX(zero_nan, %eax, 1)
80         ret
82         /* The result is NaN, but we must not raise an exception.
83            So use a variable.  */
84 2:      fstp    %st
85         fstp    %st
86 #ifdef  PIC
87         LOAD_PIC_REG (cx)
88 #endif
89         fldl    MO(nan)
90         ret
92         /* The first parameter is a NaN.  Return it.  */
93 3:      fstp    %st(1)
94         ret
96         /* Return NaN and raise the invalid exception.  */
97 4:      fstp    %st
98         fstp    %st
99         fldz
100         fdiv    %st
101         ret
102 END(__ieee754_scalb)