2.5-18.1
[glibc.git] / sysdeps / ia64 / fpu / e_log2.S
blob660a9526b6a6a7d2b7698ea8521a7dacce565b15
1 .file "log2.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, 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:
13 // * Redistributions of source code must retain the above copyright
14 // notice, this list of conditions and the following disclaimer.
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.
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.
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://www.intel.com/software/products/opensource/libraries/num.htm.
40 // History
41 //=================================================================
42 // 09/11/00 Initial version 
43 // 03/19/01 Added one polynomial coefficient, to improve accuracy
44 // 05/20/02 Cleaned up namespace and sf0 syntax
45 // 02/10/03 Reordered header: .section, .global, .proc, .align
46 // 04/18/03 Reformatted T[255]
48 // API
49 //=================================================================
50 // double log2(double)
52 // Overview of operation
53 //=================================================================
54 // Background
56 // Implementation
58 // Let x = 2^l * m, where     m=1.b1 b2 ... b8 b9 ... b52
59 //     y=frcpa(m),   r=m*y-1, f=b1 b2 .. b8 (table index)
60 // j=0 if f<128; j=1 if f>=128
61 // T is a table that stores log2(1/y) (in entries 1..255) rounded to
62 //   double extended precision; f is used as an index; T[255]=0
63 // 
64 // If f=0 and b9=0, r is set to 2^{-8}* 0.b9 b10 ... b52 = m-1 (fractional part of m),
65 //                  and 0 is used instead of T[0] 
66 //                  (polynomial evaluation only, for m=1+r, 0<=r<2^{-9})
67 // If f=255, r is set to (m-2)/2  (T[255]=0, and only polynomial evaluation is used
68 //                                 for m=2(1-r'), 0<=r'<2^{-9})
70 // log2(x) is approximated as
71 //     (l-j) + T[f] + (c1*r+c2*r^2+...+c7*r^7), if f>0
72 // 
75 // Special values 
76 //=================================================================
77 //  log2(0)=-inf, raises Divide by Zero
78 //  log2(+inf)=inf
79 //  log2(x)=NaN,  raises Invalid if x<0
83 // Registers used
84 //==============================================================
85 //   f6-f15, f32-f33
86 //   r2-r3, r23-r30
87 //   p6,p7,p8,p12
91 GR_SAVE_B0                    = r33
92 GR_SAVE_PFS                   = r34
93 GR_SAVE_GP                    = r35 // This reg. can safely be used 
94 GR_SAVE_SP                    = r36
96 GR_Parameter_X                = r37
97 GR_Parameter_Y                = r38
98 GR_Parameter_RESULT           = r39
99 GR_Parameter_TAG              = r40
101 FR_X             = f10
102 FR_Y             = f1
103 FR_RESULT        = f8
108 // Data tables
109 //==============================================================
111 RODATA
113 .align 16
115 LOCAL_OBJECT_START(poly_coeffs)
117 data8 0xbfd0000000000000, 0x3fc999999999999a //C_4, C_5
118 data8 0xbfc5555555555555, 0x3fc2492492492492 //C_6, C_7
119 data8 0xb8aa3b295c17f0bc, 0x00003fff  // C_1
120 data8 0xaaaaaaaaaaaaaaab, 0x00003ffd  // C_3=1/3
121 LOCAL_OBJECT_END(poly_coeffs)
124 LOCAL_OBJECT_START(T_table)
126 data8 0xb8d8752172fed131, 0x00003ff6
127 data8 0x8ae7f475764180a3, 0x00003ff8
128 data8 0xe7f73862e72ee35d, 0x00003ff8
129 data8 0xa2b25310c941a2f2, 0x00003ff9
130 data8 0xcbb91d671abb2e85, 0x00003ff9
131 data8 0xfac91e34daa50483, 0x00003ff9
132 data8 0x9504a5042eb495c5, 0x00003ffa
133 data8 0xa9c4a0bbb580ee02, 0x00003ffa
134 data8 0xc19264dc8a5e3bf9, 0x00003ffa
135 data8 0xd67aa6703ebf4a77, 0x00003ffa
136 data8 0xee76cac6d6e08ce7, 0x00003ffa
137 data8 0x81c3f7de5434ed04, 0x00003ffb
138 data8 0x8c563033a3ce01e4, 0x00003ffb
139 data8 0x9876e9f09a98661c, 0x00003ffb
140 data8 0xa31e0ac9b2326ce2, 0x00003ffb
141 data8 0xadcf09e1fd10e4a5, 0x00003ffb
142 data8 0xb889f992cf03cdb6, 0x00003ffb
143 data8 0xc34eec68d901a714, 0x00003ffb
144 data8 0xce1df524e9909ed9, 0x00003ffb
145 data8 0xd8f726bcb0b80ad0, 0x00003ffb
146 data8 0xe3da945b878e27d1, 0x00003ffb
147 data8 0xeec851633b76a320, 0x00003ffb
148 data8 0xf82ea4bb6101421a, 0x00003ffb
149 data8 0x8197ddd7736b2864, 0x00003ffc
150 data8 0x871dad4f994253f0, 0x00003ffc
151 data8 0x8ca8cae3e892d549, 0x00003ffc
152 data8 0x916d6e1559a4b697, 0x00003ffc
153 data8 0x97028118efabeb7d, 0x00003ffc
154 data8 0x9bcfbce1592ad5d5, 0x00003ffc
155 data8 0xa16ee95d0da54a91, 0x00003ffc
156 data8 0xa644dcf3403fa5d0, 0x00003ffc
157 data8 0xab1ee14ffd659064, 0x00003ffc
158 data8 0xb0cd12faebcc6757, 0x00003ffc
159 data8 0xb5affdf9b3b221e0, 0x00003ffc
160 data8 0xba970fb307c6ade1, 0x00003ffc
161 data8 0xbf824f3a9f3e7561, 0x00003ffc
162 data8 0xc544c055fde99333, 0x00003ffc
163 data8 0xca39266532bdf26c, 0x00003ffc
164 data8 0xcf31d124b8fa2f56, 0x00003ffc
165 data8 0xd42ec7f59017b6ab, 0x00003ffc
166 data8 0xd930124bea9a2c67, 0x00003ffc
167 data8 0xde35b7af70e4dab3, 0x00003ffc
168 data8 0xe33fbfbb8533ef03, 0x00003ffc
169 data8 0xe77625911a7dcef3, 0x00003ffc
170 data8 0xec884bd689cc12e3, 0x00003ffc
171 data8 0xf19eeabf9e99a40a, 0x00003ffc
172 data8 0xf6ba0a35e3d88051, 0x00003ffc
173 data8 0xfbd9b237f7b4192b, 0x00003ffc
174 data8 0x80111d4a1ee0c79e, 0x00003ffd
175 data8 0x82a523a5f875bbfc, 0x00003ffd
176 data8 0x84ccecdc92cd0815, 0x00003ffd
177 data8 0x87653369d92c057a, 0x00003ffd
178 data8 0x89ffd1742da3aa21, 0x00003ffd
179 data8 0x8c2d2227d053d9b6, 0x00003ffd
180 data8 0x8e5c189793f7f798, 0x00003ffd
181 data8 0x90fd0a20e72f3c96, 0x00003ffd
182 data8 0x932fa937301e59ae, 0x00003ffd
183 data8 0x95d5061a5f0f5f7f, 0x00003ffd
184 data8 0x980b5a2ef10e7023, 0x00003ffd
185 data8 0x9a4361c5514d3c27, 0x00003ffd
186 data8 0x9c7d1f7d541313fd, 0x00003ffd
187 data8 0x9f2b16040b500d04, 0x00003ffd
188 data8 0xa168a0fa9db22c98, 0x00003ffd
189 data8 0xa3a7eaa1f9116293, 0x00003ffd
190 data8 0xa5e8f5b4072a3d44, 0x00003ffd
191 data8 0xa82bc4f11a5e88aa, 0x00003ffd
192 data8 0xaa705b2001db8317, 0x00003ffd
193 data8 0xacb6bb0e1e0f8005, 0x00003ffd
194 data8 0xaefee78f75707221, 0x00003ffd
195 data8 0xb148e37ec994dd99, 0x00003ffd
196 data8 0xb394b1bdaca0bc17, 0x00003ffd
197 data8 0xb5e255349707e496, 0x00003ffd
198 data8 0xb831d0d2fda791cc, 0x00003ffd
199 data8 0xba83278f6838ab20, 0x00003ffd
200 data8 0xbcd65c67881c7d47, 0x00003ffd
201 data8 0xbeb3e0f21d72dc92, 0x00003ffd
202 data8 0xc10a7a03457d35dc, 0x00003ffd
203 data8 0xc362f9b6f51eddd3, 0x00003ffd
204 data8 0xc5bd6326ebfce656, 0x00003ffd
205 data8 0xc7a0b3d0637c8f97, 0x00003ffd
206 data8 0xc9fe96af0df8e4b5, 0x00003ffd
207 data8 0xcc5e6c214b4a2cd7, 0x00003ffd
208 data8 0xce46199f374d29cf, 0x00003ffd
209 data8 0xd0a978a14c0d9ebe, 0x00003ffd
210 data8 0xd293fecafec7f9b5, 0x00003ffd
211 data8 0xd4faf1f6f5cf32e6, 0x00003ffd
212 data8 0xd6e8595abaad34d1, 0x00003ffd
213 data8 0xd952eb7a8ffc1593, 0x00003ffd
214 data8 0xdb433ccd805f171e, 0x00003ffd
215 data8 0xddb178dc43e6bd84, 0x00003ffd
216 data8 0xdfa4bcfb333342a4, 0x00003ffd
217 data8 0xe19953741ccea015, 0x00003ffd
218 data8 0xe40cee16a2ff21c5, 0x00003ffd
219 data8 0xe6048470cdbde8ea, 0x00003ffd
220 data8 0xe7fd7308d6895b14, 0x00003ffd
221 data8 0xe9f7bbb6a1ff9f87, 0x00003ffd
222 data8 0xec7280138809433d, 0x00003ffd
223 data8 0xee6fda4365cd051f, 0x00003ffd
224 data8 0xf06e94a122ff1f12, 0x00003ffd
225 data8 0xf26eb1151441fce5, 0x00003ffd
226 data8 0xf470318b88a77e2f, 0x00003ffd
227 data8 0xf67317f4d4c8aa58, 0x00003ffd
228 data8 0xf8f8b250a9c4cde6, 0x00003ffd
229 data8 0xfafec54831f1a484, 0x00003ffd
230 data8 0xfd06449bf3eaea1e, 0x00003ffd
231 data8 0xff0f324ddb19ab67, 0x00003ffd
232 data8 0x808cc8320a9acf15, 0x00003ffe
233 data8 0x8192b0748f2cef06, 0x00003ffe
234 data8 0x829952f5e6a24ee5, 0x00003ffe
235 data8 0x83a0b0bfafe1424e, 0x00003ffe
236 data8 0x8466b29f9c41caea, 0x00003ffe
237 data8 0x856f5aae0881d857, 0x00003ffe
238 data8 0x8678c0eae8ee8190, 0x00003ffe
239 data8 0x8782e6685676b9d7, 0x00003ffe
240 data8 0x888dcc3abc4554ec, 0x00003ffe
241 data8 0x89997378de7b98b8, 0x00003ffe
242 data8 0x8aa5dd3be1044279, 0x00003ffe
243 data8 0x8b6facdfd0360ab8, 0x00003ffe
244 data8 0x8c7d6db7169e0cdb, 0x00003ffe
245 data8 0x8d8bf424d6e130b2, 0x00003ffe
246 data8 0x8e575b506f409fa6, 0x00003ffe
247 data8 0x8f673e418776492c, 0x00003ffe
248 data8 0x9077e9ed700ef9ba, 0x00003ffe
249 data8 0x9144ef1baec80b20, 0x00003ffe
250 data8 0x9256fcdb537f035f, 0x00003ffe
251 data8 0x9369d68d75e7e1d6, 0x00003ffe
252 data8 0x943880613b8f9f1e, 0x00003ffe
253 data8 0x954cc1d9e0d94206, 0x00003ffe
254 data8 0xd3c70a37bdf7a294, 0x0000bffd
255 data8 0xd19bb053fb0284ec, 0x0000bffd
256 data8 0xcffa1a3b7dafb8bf, 0x0000bffd
257 data8 0xcdcbe1e2776479ee, 0x0000bffd
258 data8 0xcc282218b8bfdda2, 0x0000bffd
259 data8 0xc9f703a9afcb38ac, 0x0000bffd
260 data8 0xc851146ab89593c6, 0x0000bffd
261 data8 0xc61d08265927a860, 0x0000bffd
262 data8 0xc474e39705912d26, 0x0000bffd
263 data8 0xc23de19ec30c6e3e, 0x0000bffd
264 data8 0xc09381cc45db45b4, 0x0000bffd
265 data8 0xbee82b4e025ff90c, 0x0000bffd
266 data8 0xbcace101149788ec, 0x0000bffd
267 data8 0xbaff46962ea47964, 0x0000bffd
268 data8 0xb950b1be5e0c14a2, 0x0000bffd
269 data8 0xb7110e6ce866f2bc, 0x0000bffd
270 data8 0xb5602ccc2a81db52, 0x0000bffd
271 data8 0xb3ae4ce740fc8ef1, 0x0000bffd
272 data8 0xb1fb6d92c8240ccc, 0x0000bffd
273 data8 0xafb609c09b244abc, 0x0000bffd
274 data8 0xae00d1cfdeb43cfd, 0x0000bffd
275 data8 0xac4a967a8c8c9bd0, 0x0000bffd
276 data8 0xaa93568c249e6c52, 0x0000bffd
277 data8 0xa8db10cdff375343, 0x0000bffd
278 data8 0xa68e6fc5a42376e3, 0x0000bffd
279 data8 0xa4d3c25e68dc57f2, 0x0000bffd
280 data8 0xa3180b0c192a3816, 0x0000bffd
281 data8 0xa15b488e7aa329a0, 0x0000bffd
282 data8 0x9f9d79a30f0e1d5f, 0x0000bffd
283 data8 0x9dde9d050ee7d4ac, 0x0000bffd
284 data8 0x9c1eb16d63d7356c, 0x0000bffd
285 data8 0x9a5db592a310c36a, 0x0000bffd
286 data8 0x989ba82907a9016f, 0x0000bffd
287 data8 0x96d887e26cd57b79, 0x0000bffd
288 data8 0x9514536e481c3a4f, 0x0000bffd
289 data8 0x934f0979a3715fc9, 0x0000bffd
290 data8 0x9188a8af1742a9d5, 0x0000bffd
291 data8 0x8fc12fb6c470995f, 0x0000bffd
292 data8 0x8df89d364e34f8f1, 0x0000bffd
293 data8 0x8c2eefd0d3f67dd6, 0x0000bffd
294 data8 0x8a642626eb093d54, 0x0000bffd
295 data8 0x88983ed6985bae58, 0x0000bffd
296 data8 0x86cb387b4a0feec6, 0x0000bffd
297 data8 0x84fd11add101024b, 0x0000bffd
298 data8 0x83c856dd81804b78, 0x0000bffd
299 data8 0x81f84c2c62afd6f1, 0x0000bffd
300 data8 0x80271d3e4be5ea5a, 0x0000bffd
301 data8 0xfca991447e7b485d, 0x0000bffc
302 data8 0xf90299c904793a3c, 0x0000bffc
303 data8 0xf559511d2dc1ed69, 0x0000bffc
304 data8 0xf2e72afee9bd2aee, 0x0000bffc
305 data8 0xef39ff1d8a40770e, 0x0000bffc
306 data8 0xeb8a7a2311c935dc, 0x0000bffc
307 data8 0xe7d8990dc620012f, 0x0000bffc
308 data8 0xe560b1e3b86e44b6, 0x0000bffc
309 data8 0xe1aadb38caee80c4, 0x0000bffc
310 data8 0xddf2a051f81b76a4, 0x0000bffc
311 data8 0xdb7678bafcaf4b5f, 0x0000bffc
312 data8 0xd7ba3a8f0df19bfc, 0x0000bffc
313 data8 0xd3fb8fdbdd5cebdb, 0x0000bffc
314 data8 0xd17b191905c35652, 0x0000bffc
315 data8 0xcdb85d29cefd7121, 0x0000bffc
316 data8 0xc9f32c3c88221ef6, 0x0000bffc
317 data8 0xc76e5741a95b5dae, 0x0000bffc
318 data8 0xc3a506d80d38c718, 0x0000bffc
319 data8 0xbfd938ccef8b68c1, 0x0000bffc
320 data8 0xbd4ff63e82eef78c, 0x0000bffc
321 data8 0xb97ffa2b563865bd, 0x0000bffc
322 data8 0xb6f3eb3011eddcea, 0x0000bffc
323 data8 0xb31fb7d64898b3e6, 0x0000bffc
324 data8 0xb090d63a409e7880, 0x0000bffc
325 data8 0xacb8623c7ffa4f39, 0x0000bffc
326 data8 0xa8dd5c83d2e45246, 0x0000bffc
327 data8 0xa649e998a8d91f2e, 0x0000bffc
328 data8 0xa26a93fed6faa94f, 0x0000bffc
329 data8 0x9fd43df079d0db1f, 0x0000bffc
330 data8 0x9d3cbe69aecac4c2, 0x0000bffc
331 data8 0x99574f13c570d0fb, 0x0000bffc
332 data8 0x96bce349bf7ee6c7, 0x0000bffc
333 data8 0x92d30c9b86cee18e, 0x0000bffc
334 data8 0x9035adef17c5bd5c, 0x0000bffc
335 data8 0x8c4765e8e8b5f251, 0x0000bffc
336 data8 0x89a70da448316ffa, 0x0000bffc
337 data8 0x85b44a24474af78a, 0x0000bffc
338 data8 0x8310f17aab5adf70, 0x0000bffc
339 data8 0x806c6388d0965f29, 0x0000bffc
340 data8 0xf8e69092bf0c5ead, 0x0000bffb
341 data8 0xf397608bfd2d90e6, 0x0000bffb
342 data8 0xee45be24d0eedbc4, 0x0000bffb
343 data8 0xe646af233db881e9, 0x0000bffb
344 data8 0xe0eee4e1ce3d06fb, 0x0000bffb
345 data8 0xdb94a049e6e87a4f, 0x0000bffb
346 data8 0xd3888ef9a4249f5a, 0x0000bffb
347 data8 0xce280e6fbac39194, 0x0000bffb
348 data8 0xc8c50b72319ad574, 0x0000bffb
349 data8 0xc0abcd39f41e329b, 0x0000bffb
350 data8 0xbb4279cfa7f9667b, 0x0000bffb
351 data8 0xb5d69bac77ec398a, 0x0000bffb
352 data8 0xb068306bf20d6233, 0x0000bffb
353 data8 0xa83dc1b019ddb6a8, 0x0000bffb
354 data8 0xa2c8eb1886c2d024, 0x0000bffb
355 data8 0x9d517ee93f8e16c0, 0x0000bffb
356 data8 0x97d77aae659b92fb, 0x0000bffb
357 data8 0x8f9b91da5736d415, 0x0000bffb
358 data8 0x8a1b06b09b7fd1d1, 0x0000bffb
359 data8 0x8497daca0a2e077a, 0x0000bffb
360 data8 0xfe241745a453f10c, 0x0000bffa
361 data8 0xf3132d6708d723c5, 0x0000bffa
362 data8 0xe7fcf2e21a0e7d77, 0x0000bffa
363 data8 0xd75198b04afb8da9, 0x0000bffa
364 data8 0xcc2dfe1a4a8ca305, 0x0000bffa
365 data8 0xc10500d63aa65882, 0x0000bffa
366 data8 0xb5d69bac77ec398a, 0x0000bffa
367 data8 0xaaa2c95dc66abcde, 0x0000bffa
368 data8 0x9f6984a342d13101, 0x0000bffa
369 data8 0x942ac82e5387ac51, 0x0000bffa
370 data8 0x88e68ea899a0976c, 0x0000bffa
371 data8 0xefebc4409ccf872e, 0x0000bff9
372 data8 0xd947b0c6642ef69e, 0x0000bff9
373 data8 0xc2987d51e043d407, 0x0000bff9
374 data8 0xabde1eeee6bfd257, 0x0000bff9
375 data8 0x95188a9917cf2e01, 0x0000bff9
376 data8 0xfc8f6a777c1b7f1e, 0x0000bff8
377 data8 0xced727635c59725c, 0x0000bff8
378 data8 0xa108358a4c904615, 0x0000bff8
379 data8 0xe644fcbeb3ac9c90, 0x0000bff7
380 data8 0x8a4bd667bf08e7de, 0x0000bff7
381 data8 0x0000000000000000 // T[255] Low
382 data8 0x0000000000000000 // T[255] High
383 LOCAL_OBJECT_END(T_table)
387 .section .text
388 GLOBAL_LIBM_ENTRY(log2)
390 { .mfi
391   alloc r32=ar.pfs,1,4,4,0     
392   // y=frcpa(x)  
393   frcpa.s1 f6,p0=f1,f8
394   // will form significand of 1.5 (to test whether the index is 128 or above) 
395   mov r24=0xc
397 {.mfi
398   nop.m 0
399   // normalize x 
400   fma.s1 f7=f8,f1,f0
401   // r2 = pointer to C_1...C_6 followed by T_table
402   addl r2 = @ltoff(poly_coeffs), gp;;
404 {.mfi
405   // get significand
406   getf.sig r25=f8
407   // f8 denormal ?
408   fclass.m p8,p10=f8,0x9
409   // will form significand of 1.5 (to test whether the index is 128 or above) 
410   shl r24=r24,60
412 {.mfi
413   mov r26=0x804
414   nop.f 0
415   // r23=bias-1
416   mov r23=0xfffe;;
419 {.mmf
420   getf.exp r29=f8
421   // load start address for C_1...C_6 followed by T_table
422   ld8 r2=[r2]
423   // will continue only for positive normal/denormal numbers          
424   fclass.nm.unc p12,p7 = f8, 0x19 ;;
427 .pred.rel "mutex",p8,p10
428 {.mfi
429   // denormal input, repeat get significand (after normalization)
430   (p8) getf.sig r25=f7
431   // x=1 ?
432   fcmp.eq.s0 p6,p0=f8,f1
433   // get T_index
434   (p10) shr.u r28=r25,63-8
436 {.mfi
437   // f32=0.5
438   setf.exp f32=r23
439   nop.f 0
440   // r27=bias
441   mov r27=0xffff;;
444 {.mmi
445   // denormal input, repeat get exponent (after normalization)
446   (p8) getf.exp r29=f7
447   mov r23=0xff
448   // r26=0x80400...0 (threshold for using polynomial approximation)
449   shl r26=r26,64-12;;
452 {.mfb
453   add r3=48,r2
454   // r=1-x*y
455   fms.s1 f6=f6,f8,f1
456   (p12) br.cond.spnt SPECIAL_LOG2
458 {.mfi
459   // load C_4, C_5
460   ldfpd f10,f11=[r2],16
461   nop.f 0
462   cmp.geu p12,p0=r25,r24;;
465 {.mmi
466   // load C_6, C_7
467   ldfpd f12,f13=[r2],16
468   // r27=bias-1 (if index >=128, will add exponent+1) 
469   (p12) mov r27=0xfffe
470   (p8) shr.u r28=r25,63-8;;
474 {.mfi
475   // load C_1
476   ldfe f14=[r2],32
477   fmerge.se f7=f1,f7
478   // if first 9 bits after leading 1 are all zero, then p8=1
479   cmp.ltu p8,p12=r25,r26
481 {.mfi
482   // load C_3
483   ldfe f15=[r3]
484   nop.f 0
485   // get T_index
486   and r28=r28,r23;;
488 {.mfi
489   // r29=exponent-bias
490   sub r29=r29,r27
491   // x=1, return 0
492   (p6) fma.d.s0 f8=f0,f0,f0
493   // get T address
494   shladd r2=r28,4,r2
496 {.mfb
497   // first 8 bits after leading 1 are all ones ?
498   cmp.eq p10,p0=r23,r28
499   // if first 8 bits after leading bit are 0, use polynomial approx. only
500   (p8) fms.s1 f6=f7,f1,f1
501   // x=1, return
502   (p6) br.ret.spnt b0;;
504 {.mfi
505   // r26=1
506   mov r26=1
507   // if first 8 bits after leading 1 are all ones, use polynomial approx. only
508   (p10) fms.s1 f6=f7,f32,f1
509   nop.i 0;;
512 .pred.rel "mutex",p8,p12
513 {.mmf
514   // load T (unless first 9 bits after leading 1 are 0)
515   (p12) ldfe f33=[r2]
516   // f8=expon - bias 
517   setf.sig f8=r29
518   // set T=0 (if first 9 bits after leading 1 are 0)
519   (p8) fma.s1 f33=f0,f0,f0;;
522 {.mfi
523   nop.m 0
524   // P12=1-0.5*r
525   fnma.s1 f32=f32,f6,f1
526   // r26=2^{63}
527   shl r26=r26,63
529 {.mfi
530   nop.m 0
531   // r2=r*r
532   fma.s1 f7=f6,f6,f0
533   nop.i 0;;
535 {.mfi
536   // significand(x)=1 ?
537   cmp.eq p0,p6=r26,r25
538   // P67=C_6+C_7*r
539   fma.s1 f13=f13,f6,f12
540   nop.i 0
542 {.mfi
543   nop.m 0
544   // P45=C_4+C_5*r
545   fma.s1 f10=f11,f6,f10
546   nop.i 0;;
549 {.mfi
550   nop.m 0
551   // C_1*r
552   (p6) fma.s1 f14=f14,f6,f0
553   nop.i 0;;
555 {.mfi
556   nop.m 0
557   // normalize additive term (l=exponent of x)
558   fcvt.xf f8=f8
559   nop.i 0
561 {.mfi
562   nop.m 0
563   // P13=1-0.5*r+C_3*r^2
564   (p6) fma.s1 f15=f15,f7,f32
565   nop.i 0;;
568 {.mfi
569   nop.m 0
570   // P47=P45+r2*P67
571   (p6) fma.s1 f13=f13,f7,f10
572   // if significand(x)=1, return exponent (l)
573   nop.i 0
575 {.mfi
576   nop.m 0
577   // r3=r^3
578   (p6) fma.s1 f7=f7,f6,f0
579   nop.i 0;;
582 {.mfi
583   nop.m 0
584   // add T+l
585   (p6) fma.s1 f8=f8,f1,f33
586   nop.i 0
588 {.mfi
589   nop.m 0
590   // P17=P13+r3*P47
591   (p6) fma.s1 f13=f13,f7,f15
592   nop.i 0;;
595 {.mfb
596   nop.m 0
597   // result=T+l+(C_1*r)*P16
598   (p6) fma.d.s0 f8=f13,f14,f8
599   // return
600   br.ret.sptk b0;;
604 SPECIAL_LOG2:
605 {.mfi 
606   nop.m 0
607   // x=+Infinity ?
608   fclass.m p7,p0=f8,0x21
609   nop.i 0;;
611 {.mfi
612   nop.m 0
613   // x=+/-Zero ?
614   fclass.m p8,p0=f8,0x7
615   nop.i 0;;
617 {.mfi
618   nop.m 0
619   // x=-Infinity, -normal, -denormal ?
620   fclass.m p6,p0=f8,0x3a
621   nop.i 0;;
623 {.mfb
624   nop.m 0
625   // log2(+Infinity)=+Infinity
626   nop.f 0
627   (p7) br.ret.spnt b0;;
629 {.mfi
630   (p8) mov GR_Parameter_TAG = 170                          
631   // log2(+/-0)=-infinity, raises Divide by Zero
632   // set f8=-0
633   (p8) fmerge.ns f8=f0,f8
634   nop.i 0;;
636 {.mfb
637   nop.m 0
638   (p8) frcpa.s0 f8,p0=f1,f8
639   (p8) br.cond.sptk __libm_error_region;;
641 {.mfb
642   (p6) mov GR_Parameter_TAG = 171 
643   // x<0: return NaN, raise Invalid
644   (p6) frcpa.s0 f8,p0=f0,f0
645   (p6) br.cond.sptk __libm_error_region;;
646 }                          
647   
649 {.mfb
650   nop.m 0
651   // Remaining cases: NaNs
652   fma.d.s0 f8=f8,f1,f0
653   br.ret.sptk b0;;
656 GLOBAL_LIBM_END(log2)
659 LOCAL_LIBM_ENTRY(__libm_error_region)
660 .prologue
661 { .mfi
662         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
663         nop.f 0
664 .save   ar.pfs,GR_SAVE_PFS
665         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs 
667 { .mfi
668 .fframe 64 
669         add sp=-64,sp                           // Create new stack
670         nop.f 0
671         mov GR_SAVE_GP=gp                       // Save gp
673 { .mmi
674         stfd [GR_Parameter_Y] = FR_Y,16         // STORE Parameter 2 on stack
675         add GR_Parameter_X = 16,sp              // Parameter 1 address
676 .save   b0, GR_SAVE_B0                      
677         mov GR_SAVE_B0=b0                       // Save b0 
679 .body
680 { .mib
681         stfd [GR_Parameter_X] = FR_X                  // STORE Parameter 1 on stack 
682         add   GR_Parameter_RESULT = 0,GR_Parameter_Y  // Parameter 3 address 
683         nop.b 0                                      
685 { .mib
686         stfd [GR_Parameter_Y] = FR_RESULT             // STORE Parameter 3 on stack
687         add   GR_Parameter_Y = -16,GR_Parameter_Y  
688         br.call.sptk b0=__libm_error_support#         // Call error handling function
690 { .mmi
691         nop.m 0
692         nop.m 0
693         add   GR_Parameter_RESULT = 48,sp
695 { .mmi
696         ldfd  f8 = [GR_Parameter_RESULT]       // Get return result off stack
697 .restore sp
698         add   sp = 64,sp                       // Restore stack pointer
699         mov   b0 = GR_SAVE_B0                  // Restore return address
701 { .mib
702         mov   gp = GR_SAVE_GP                  // Restore gp 
703         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
704         br.ret.sptk     b0                     // Return
705 };; 
707 LOCAL_LIBM_END(__libm_error_region)
708 .type   __libm_error_support#,@function
709 .global __libm_error_support#