• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * This file has no copyright assigned and is placed in the Public Domain.
3 * This file is part of the mingw-w64 runtime package.
4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
5 */
6#include <_mingw_mac.h>
7
8	.file	"ilogb.S"
9	.text
10	.p2align 4,,15
11.globl __MINGW_USYMBOL(ilogb)
12	.def	__MINGW_USYMBOL(ilogb);	.scl	2;	.type	32;	.endef
13#ifdef __x86_64__
14	.seh_proc __MINGW_USYMBOL(ilogb)
15#endif
16__MINGW_USYMBOL(ilogb):
17#ifdef __x86_64__
18/* Generated code by:
19int
20ilogb (double x)
21{
22  __mingw_dbl_type_t hlp;
23  int hx, lx, ix;
24
25  hlp.x = x;
26  hx = hpl.lh.high & 0x7fffffff;
27  if (hx < 0x100000)
28    {
29      lx = hlp.lh.low;
30      if ((hx | lx) == 0)
31        return 0x80000000;      // ilogb(0) = FP_ILOGB0
32      // subnormal x
33      if (hx == 0)
34        {
35          for (ix = -1043; lx > 0; lx <<= 1)
36            ix -=1;
37        }
38      else
39        {
40          for (ix = -1022,hx <<= 11; hx > 0; hx <<= 1)
41            ix -=1;
42        }
43      return ix;
44    }
45  if (hx < 0x7ff00000)
46    return (hx >> 20) - 1023;
47  lx = hlp.lh.low;
48  return 0x7fffffff;
49} */
50        subq    $24, %rsp
51        .seh_stackalloc 24
52        .seh_endprologue
53        movsd   %xmm0, 8(%rsp)
54        movq    8(%rsp), %rdx
55        shrq    $32, %rdx
56        andl    $2147483647, %edx
57        cmpl    $1048575, %edx
58        jg      .L2
59        movq    8(%rsp), %rcx
60        movl    %edx, %eax
61        orl     %ecx, %eax
62        je      .L8
63        testl   %edx, %edx
64        jne     .L4
65        testl   %ecx, %ecx
66        movl    %ecx, %edx
67        movl    $-1043, %eax
68        jle     .L3
69        .p2align 4,,10
70.L5:
71        addl    %edx, %edx
72        subl    $1, %eax
73        testl   %edx, %edx
74        jg      .L5
75        addq    $24, %rsp
76        ret
77        .p2align 4,,10
78.L2:
79        cmpl    $2146435071, %edx
80        jle     .L13
81        movl    $2147483647, %eax
82.L3:
83        addq    $24, %rsp
84        ret
85        .p2align 4,,10
86.L4:
87        sall    $11, %edx
88        movl    $-1022, %eax
89        testl   %edx, %edx
90        jle     .L3
91        .p2align 4,,10
92.L6:
93        addl    %edx, %edx
94        subl    $1, %eax
95        testl   %edx, %edx
96        jg      .L6
97        addq    $24, %rsp
98        ret
99        .p2align 4,,10
100.L13:
101        sarl    $20, %edx
102        leal    -1023(%rdx), %eax
103        addq    $24, %rsp
104        ret
105.L8:
106        movl    $-2147483648, %eax
107        jmp     .L3
108        .seh_endproc
109#else
110
111	fldl	4(%esp)
112/* I added the following ugly construct because ilogb(+-Inf) is
113   required to return INT_MAX in ISO C99.
114   -- jakub@redhat.com.  */
115	fxam			/* Is NaN or +-Inf?  */
116	fstsw   %ax
117	movb    $0x45, %dh
118	andb    %ah, %dh
119	cmpb    $0x05, %dh
120	je      1f		/* Is +-Inf, jump.  */
121	cmpb    $0x01, %dh
122	je      1f		/* Is NaN, jump.  */
123
124	fxtract
125	pushl	%eax
126	fstp	%st
127
128	fistpl	(%esp)
129	fwait
130	popl	%eax
131
132	ret
133
1341:	fstp	%st
135	movl	$0x7fffffff, %eax
136	ret
137#endif
138