]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/fpu/s_ilogbl.S
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / s_ilogbl.S
1 .file "ilogbl.s"
2
3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 //
6 // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
7 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
12 //
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
15 //
16 // * Redistributions in binary form must reproduce the above copyright
17 // notice, this list of conditions and the following disclaimer in the
18 // documentation and/or other materials provided with the distribution.
19 //
20 // * The name of Intel Corporation may not be used to endorse or promote
21 // products derived from this software without specific prior written
22 // permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
28 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
32 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
33 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // Intel Corporation is the author of this code, and requests that all
37 // problem reports or change requests be submitted to it directly at
38 // http://developer.intel.com/opensource.
39 //
40 // History
41 //==============================================================
42 // 2/03/00 Initial version
43 // 5/26/00 Fix bug when x a double-extended denormal;
44 // if x=0 call error routine, per C9X
45 // 8/15/00 Bundle added after call to __libm_error_support to properly
46 // set [the previously overwritten] GR_Parameter_RESULT.
47 // 1/20/01 Fixed result for x=0
48
49 .align 32
50 .global ilogbl#
51
52 .section .text
53 .proc ilogbl#
54 .align 32
55
56 // API
57 //==============================================================
58 // int = ilogbl(double_extended)
59
60 // Overview of operation
61 //==============================================================
62 // ilogbl computes log2(x) as an int
63 // and returns it in r8
64
65 // ilogbl is similar to logbl but differs in the following ways:
66 // +-inf
67 // ilogbl: returns INT_MAX
68 // logbl: returns +inf
69 // Nan returns FP_ILOGBNAN (which is either INT_MAX or INT_MIN)
70 // ilogbl: returns INT_MAX (7fffffff)
71 // logbl: returns QNAN (quieted SNAN)
72 // 0 returns FP_ILOGB0 (which is either INT_MIN or -INT_MAX)
73 // ilogbl: returns INT_MIN (80000000)
74 // logbl: returns -inf
75
76 // Registers used
77 //==============================================================
78
79 // general local registers:
80 // ar.pfs r32
81 // r33 -> r37
82 // r38 -> r41 used as parameters to error path
83
84 // predicate registers used:
85 // p6 - x nan, inf
86 // p7 - x 0
87 // p8 - x norm, unorm
88 // p9 - x unorm
89
90 // floating-point registers used:
91 // f8 - f10
92
93 #include "libm_support.h"
94
95 GR_SAVE_PFS = r32
96 GR_SAVE_B0 = r34
97 GR_SAVE_GP = r35
98 GR_Parameter_X = r38
99 GR_Parameter_Y = r39
100 GR_Parameter_RESULT = r40
101 GR_Parameter_TAG = r41
102
103 FR_X = f8
104 FR_Y = f0
105 FR_RESULT = f0
106
107
108 ilogbl:
109
110 // Form signexp of 2^64 in case need to scale denormal
111 { .mmf
112 alloc r32=ar.pfs,1,5,4,0
113 (p0) mov r37 = 0x1003f
114 (p0) fnorm f9 = f8 ;;
115 }
116
117 // Form 2^64 in case need to scale denormal
118 { .mfi
119 (p0) setf.exp f10 = r37
120 (p0) fclass.m.unc p7, p8 = f8, 0xe3
121 (p0) mov r34 = 0xffff ;;
122 }
123
124 // qnan snan inf norm unorm 0 -+
125 // 1 1 1 0 0 0 11
126 // e 3
127 // X ZERO, returns INT_MIN
128 // X INF or NAN, returns INT_MAX
129
130 { .mfi
131 (p0) mov r35 = 0x1ffff
132 (p8) fclass.m.unc p6, p8 = f8, 0x07
133 nop.i 999 ;;
134 }
135 { .mlx
136 nop.m 999
137 (p7) movl r8 = 0x000000007fffffff ;;
138 }
139
140 { .mib
141 nop.m 999
142 nop.i 999
143 (p6) br.cond.spnt L(ILOGB_ZERO) ;;
144 }
145
146 // Test for denormal
147 { .mfi
148 nop.m 999
149 (p8) fclass.m.unc p9, p0 = f9, 0x0b
150 nop.i 999 ;;
151 }
152
153 L(ILOGB_COMMON):
154 // X NORMAL returns true exponent
155 { .mmi
156 nop.m 999
157 (p8) getf.exp r33 = f9
158 nop.i 999 ;;
159 }
160
161 // If denormal add 64 to exponent bias for scaling
162 { .mfb
163 (p9) add r34 = 64, r34
164 nop.f 999
165 (p9) br.cond.spnt L(ILOGB_DENORM) ;;
166 }
167
168 { .mmi
169 (p8) and r36 = r35, r33
170 nop.m 999
171 nop.i 999 ;;
172 }
173
174 { .mib
175 (p8) sub r8 = r36, r34
176 nop.i 999
177 (p0) br.ret.sptk b0 ;;
178 }
179
180 L(ILOGB_DENORM):
181 // Here if x denormal
182 // Form x * 2^64 which is normal
183 // Return to common code
184 { .mfb
185 cmp.eq p8,p9 = r0,r0
186 fmpy f9 = f9, f10
187 br.cond.sptk L(ILOGB_COMMON) ;;
188 }
189
190 // X ZERO
191 // return INT_MIN, call error support
192 L(ILOGB_ZERO):
193 {.mlx
194 mov GR_Parameter_TAG = 156
195 (p6) movl r33 = 0x0000000080000000 ;;
196 };;
197 .endp ilogbl
198 ASM_SIZE_DIRECTIVE(ilogbl)
199
200 .proc __libm_error_region
201 __libm_error_region:
202 .prologue
203 { .mfi
204 add GR_Parameter_Y=-32,sp // Parameter 2 value
205 nop.f 0
206 .save ar.pfs,GR_SAVE_PFS
207 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
208 }
209 { .mfi
210 .fframe 64
211 add sp=-64,sp // Create new stack
212 nop.f 0
213 mov GR_SAVE_GP=gp // Save gp
214 };;
215 { .mmi
216 stfe [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
217 add GR_Parameter_X = 16,sp // Parameter 1 address
218 .save b0, GR_SAVE_B0
219 mov GR_SAVE_B0=b0 // Save b0
220 };;
221 .body
222 { .mib
223 stfe [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
224 add GR_Parameter_RESULT = 0,GR_Parameter_Y
225 nop.b 0 // Parameter 3 address
226 }
227 { .mib
228 stfe [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
229 add GR_Parameter_Y = -16,GR_Parameter_Y
230 br.call.sptk b0=__libm_error_support# // Call error handling function
231 };;
232 { .mmi
233 nop.m 0
234 nop.m 0
235 add GR_Parameter_RESULT = 48,sp
236 };;
237 { .mmi
238 mov r8 = r33 // Store result
239 .restore sp
240 add sp = 64,sp // Restore stack pointer
241 mov b0 = GR_SAVE_B0 // Restore return address
242 };;
243 { .mib
244 mov gp = GR_SAVE_GP // Restore gp
245 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
246 br.ret.sptk b0 // Return
247 };;
248
249 .endp __libm_error_region
250 ASM_SIZE_DIRECTIVE(__libm_error_region)
251
252 .type __libm_error_support#,@function
253 .global __libm_error_support#