initial commit
[glibc.git] / sysdeps / i386 / fpu / s_frexpf.S
1 /* ix87 specific frexp implementation for float.
2 Copyright (C) 1997-2022 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-float.h>
21
22 .section .rodata
23
24 .align ALIGNARG(4)
25 .type two25,@object
26 two25: .byte 0, 0, 0, 0x4c
27 ASM_SIZE_DIRECTIVE(two25)
28
29 #ifdef PIC
30 #define MO(op) op##@GOTOFF(%edx)
31 #else
32 #define MO(op) op
33 #endif
34
35 #define PARMS 4 /* no space for saved regs */
36 #define VAL PARMS
37 #define EXPP VAL+4
38
39 .text
40 ENTRY (__frexpf)
41
42 movl VAL(%esp), %eax
43 xorl %ecx, %ecx
44 movl %eax, %edx
45 andl $0x7fffffff, %eax
46 jz 1f
47 cmpl $0x7f800000, %eax
48 jae 1f
49
50 cmpl $0x00800000, %eax
51 jae 2f
52
53 flds VAL(%esp)
54 #ifdef PIC
55 LOAD_PIC_REG (dx)
56 #endif
57 fmuls MO(two25)
58 movl $-25, %ecx
59 fstps VAL(%esp)
60 fwait
61 movl VAL(%esp), %eax
62 movl %eax, %edx
63 andl $0x7fffffff, %eax
64
65 2: shrl $23, %eax
66 andl $0x807fffff, %edx
67 subl $126, %eax
68 orl $0x3f000000, %edx
69 addl %eax, %ecx
70 movl %edx, VAL(%esp)
71
72 /* Store %ecx in the variable pointed to by the second argument,
73 get the factor from the stack and return. */
74 1: movl EXPP(%esp), %eax
75 flds VAL(%esp)
76 movl %ecx, (%eax)
77
78 ret
79 END (__frexpf)
80 libm_alias_float (__frexp, frexp)