]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ia64/fpu/e_hypot.S
Remove "Contributed by" lines
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / e_hypot.S
1 .file "hypot.s"
2
3
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
11 //
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
18 //
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
21 // permission.
22
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 //
35 // Intel Corporation is the author of this code, and requests that all
36 // problem reports or change requests be submitted to it directly at
37 // http://www.intel.com/software/products/opensource/libraries/num.htm.
38 //
39 //*********************************************************************
40 //
41 // History:
42 // 02/02/00 hand-optimized
43 // 04/04/00 Unwind support added
44 // 06/20/00 new version
45 // 08/15/00 Bundle added after call to __libm_error_support to properly
46 // set [the previously overwritten] GR_Parameter_RESULT.
47 // 05/20/02 Cleaned up namespace and sf0 syntax
48 // 02/10/03 Reordered header: .section, .global, .proc, .align
49 // 04/17/03 Added missing mutex directive
50 //
51 //*********************************************************************
52 // ___________
53 // Function: hypot(x,y) = |(x^2 + y^2) = for double precision values
54 // x and y
55 // Also provides cabs functionality.
56 //
57 //*********************************************************************
58 //
59 // Resources Used:
60 //
61 // Floating-Point Registers: f8 (Input and Return Value)
62 // f9 (Input)
63 // f6 -f15, f32-f34
64 //
65 // General Purpose Registers:
66 // r2,r3,r29 (Scratch)
67 // r32-r36 (Locals)
68 // r37-r40 (Used to pass arguments to error handling routine)
69 //
70 // Predicate Registers: p6 - p10
71 //
72 //*********************************************************************
73 //
74 // IEEE Special Conditions:
75 //
76 // All faults and exceptions should be raised correctly.
77 // Overflow can occur.
78 // hypot(Infinity and anything) = +Infinity
79 // hypot(QNaN and anything) = QNaN
80 // hypot(SNaN and anything ) = QNaN
81 //
82 //*********************************************************************
83 //
84 // Implementation:
85 // x2 = x * x in double-extended
86 // y2 = y * y in double-extended
87 // temp = x2 + y2 in double-extended
88 // sqrt(temp) rounded to double
89 //
90 //*********************************************************************
91
92 GR_SAVE_PFS = r33
93 GR_SAVE_B0 = r34
94 GR_SAVE_GP = r35
95 GR_Parameter_X = r36
96 GR_Parameter_Y = r37
97 GR_Parameter_RESULT = r38
98 GR_Parameter_TAG = r39
99
100 FR_X = f32
101 FR_Y = f33
102 FR_RESULT = f8
103
104 .section .text
105
106 LOCAL_LIBM_ENTRY(cabs)
107 LOCAL_LIBM_END(cabs)
108
109 GLOBAL_IEEE754_ENTRY(hypot)
110
111 {.mfi
112 alloc r32= ar.pfs,0,4,4,0
113 // Compute x*x
114 fma.s1 f10=f8,f8,f0
115 // r2=bias-1
116 mov r2=0xfffe
117 }
118 {.mfi
119 // 63/8
120 mov r3=0x40fc //0000
121 // y*y
122 fma.s1 f11=f9,f9,f0
123 // r29=429/16
124 mov r29=0x41d68;; //000
125 }
126
127 { .mfi
128 nop.m 0
129 // Check if x is an Inf - if so return Inf even
130 // if y is a NaN (C9X)
131 fclass.m.unc p7, p6 = f8, 0x023
132 shl r3=r3,16
133 }
134 {.mfi
135 nop.m 0
136 // if possible overflow, copy f8 to f32
137 // set Denormal, if necessary
138 // (p8)
139 fma.d.s0 f32=f8,f1,f0
140 nop.i 0;;
141 }
142 { .mfi
143 nop.m 0
144 // Check if y is an Inf - if so return Inf even
145 // if x is a NaN (C9X)
146 fclass.m.unc p8, p9 = f9, 0x023
147 shl r29=r29,12
148 }
149 { .mfb
150 // f7=0.5
151 setf.exp f7=r2
152 // For x=inf, multiply y by 1 to raise invalid on y an SNaN
153 // (p7) fma.s0 f9=f9,f1,f0
154 // copy f9 to f33; set Denormal, if necessary
155 fma.d.s0 f33=f9,f1,f0
156 nop.b 0;;
157 }
158 {.mfb
159 // f13=63/8
160 setf.s f13=r3
161 // is y Zero ?
162 (p6) fclass.m p6,p0=f9,0x7
163 nop.b 0
164 }
165 {.mlx
166 nop.m 0
167 movl r2=0x408c0000;;
168 }
169
170 {.mfi
171 // f34=429/16
172 setf.s f34=r29
173 // is x Zero ?
174 (p9) fclass.m p9,p0=f8,0x7
175 // 231/16
176 mov r3=0x4167;; //0000
177 }
178 {.mfi
179 nop.m 0
180 // a=x2+y2
181 fma.s1 f12=f10,f1,f11
182 nop.i 0;;
183 }
184 {.mfi
185 nop.m 0
186 // y not NaN ?
187 (p9) fclass.m p8,p0=f9,0x3f
188 shl r3=r3,16
189 }
190 {.mfi
191 nop.m 0
192 // f6=2
193 fma.s1 f6=f1,f1,f1
194 nop.i 0;;
195 }
196
197
198 {.mfi
199 nop.m 0
200 // x not NaN ?
201 (p6) fclass.m p7,p0=f8,0x3f
202 nop.i 0;;
203 }
204 {.mfi
205 // f9=35/8
206 setf.s f9=r2
207 nop.f 0
208 // 2*emax-2
209 mov r2=0x107fb;;
210 }
211
212 .pred.rel "mutex",p7,p8
213 {.mfb
214 nop.m 0
215 // if f8=Infinity or f9=Zero, return |f8|
216 (p7) fmerge.s f8=f0,f32
217 (p7) br.ret.spnt b0
218 }
219 {.mfb
220 nop.m 0
221 // if f9=Infinity or f8=Zero, return |f9|
222 (p8) fmerge.s f8=f0,f33
223 (p8) br.ret.spnt b0;;
224 }
225
226
227 {.mfi
228 // f10 =231/16
229 setf.s f10=r3
230 // z0=frsqrta(a)
231 frsqrta.s1 f8,p6=f12
232 nop.i 0;;
233 }
234
235 { .mfi
236 nop.m 0
237 // Identify Natvals, Infs, NaNs, and Zeros
238 // and return result
239 fclass.m.unc p7, p0 = f12, 0x1E7
240 nop.i 0;;
241 }
242 {.mfb
243 // get exponent of x^2+y^2
244 getf.exp r3=f12
245 // if special case, set f8
246 (p7) mov f8=f12
247 (p7) br.ret.spnt b0;;
248 }
249
250
251 {.mfi
252 nop.m 0
253 // S0=a*z0
254 (p6) fma.s1 f14=f12,f8,f0
255 nop.i 0
256 }
257 {.mfi
258 nop.m 0
259 // H0=0.5*z0
260 (p6) fma.s1 f15=f8,f7,f0
261 nop.i 0;;
262 }
263
264
265 {.mfi
266 nop.m 0
267 // f6=5/2
268 fma.s1 f6=f7,f1,f6
269 nop.i 0
270 }
271 {.mfi
272 nop.m 0
273 // f11=3/2
274 fma.s1 f11=f7,f1,f1
275 nop.i 0;;
276 }
277
278 {.mfi
279 nop.m 0
280 // d=0.5-S0*H0
281 (p6) fnma.s1 f7=f14,f15,f7
282 nop.i 0;;
283 }
284
285 {.mfi
286 nop.m 0
287 // P67=231/16+429/16*d
288 (p6) fma.s1 f10=f34,f7,f10
289 nop.i 0
290 }
291 {.mfi
292 nop.m 0
293 // P45=63/8*d+35/8
294 (p6) fma.s1 f9=f13,f7,f9
295 nop.i 0;;
296 }
297 {.mfi
298 nop.m 0
299 // P23=5/2*d+3/2
300 (p6) fma.s1 f11=f6,f7,f11
301 nop.i 0
302 }
303 {.mfi
304 nop.m 0
305 // d2=d*d
306 (p6) fma.s1 f13=f7,f7,f0
307 nop.i 0;;
308 }
309
310 {.mfi
311 nop.m 0
312 // P47=d2*P67+P45
313 (p6) fma.s1 f10=f10,f13,f9
314 nop.i 0
315 }
316 {.mfi
317 nop.m 0
318 // P13=d*P23+1
319 (p6) fma.s1 f11=f11,f7,f1
320 nop.i 0;;
321 }
322 {.mfi
323 nop.m 0
324 // d3=d2*d
325 (p6) fma.s1 f13=f13,f7,f0
326 nop.i 0;;
327 }
328
329 {.mfi
330 nop.m 0
331 // T0=d*S0
332 (p6) fma.s1 f15=f7,f14,f0
333 nop.i 0
334 }
335 {.mfi
336 // Is x^2 + y^2 well less than the overflow
337 // threshold?
338 (p6) cmp.lt.unc p7, p8 = r3,r2
339 // P=P13+d3*P47
340 (p6) fma.s1 f10=f13,f10,f11
341 nop.i 0;;
342 }
343
344 {.mfb
345 nop.m 0
346 // S=P*T0+S0
347 fma.d.s0 f8=f10,f15,f14
348 // No overflow in this case
349 (p7) br.ret.sptk b0;;
350 }
351
352 { .mfi
353 nop.m 0
354 (p8) fsetc.s2 0x7F,0x42
355 // Possible overflow path, must detect by
356 // Setting widest range exponent with prevailing
357 // rounding mode.
358 nop.i 0 ;;
359 }
360
361
362 { .mfi
363 // bias+0x400 (bias+EMAX+1)
364 (p8) mov r2=0x103ff
365 // S=P*T0+S0
366 (p8) fma.d.s2 f12=f10,f15,f14
367 nop.i 0 ;;
368 }
369 { .mfi
370 (p8) setf.exp f11 = r2
371 (p8) fsetc.s2 0x7F,0x40
372 // Restore Original Mode in S2
373 nop.i 0 ;;
374 }
375 { .mfi
376 nop.m 0
377 (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
378 nop.i 0 ;;
379 }
380 { .mib
381 nop.m 0
382 mov GR_Parameter_TAG = 46
383 // No overflow
384 (p9) br.ret.sptk b0;;
385 }
386 GLOBAL_IEEE754_END(hypot)
387 libm_alias_double_other (__hypot, hypot)
388
389 LOCAL_LIBM_ENTRY(__libm_error_region)
390 .prologue
391 { .mfi
392 add GR_Parameter_Y=-32,sp // Parameter 2 value
393 nop.f 0
394 .save ar.pfs,GR_SAVE_PFS
395 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
396 }
397 { .mfi
398 .fframe 64
399 add sp=-64,sp // Create new stack
400 nop.f 0
401 mov GR_SAVE_GP=gp // Save gp
402 };;
403 { .mmi
404 stfd [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
405 add GR_Parameter_X = 16,sp // Parameter 1 address
406 .save b0, GR_SAVE_B0
407 mov GR_SAVE_B0=b0 // Save b0
408 };;
409 .body
410 { .mib
411 stfd [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
412 add GR_Parameter_RESULT = 0,GR_Parameter_Y
413 nop.b 0 // Parameter 3 address
414 }
415 { .mib
416 stfd [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
417 add GR_Parameter_Y = -16,GR_Parameter_Y
418 br.call.sptk b0=__libm_error_support# // Call error handling function
419 };;
420 { .mmi
421 nop.m 0
422 nop.m 0
423 add GR_Parameter_RESULT = 48,sp
424 };;
425 { .mmi
426 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
427 .restore sp
428 add sp = 64,sp // Restore stack pointer
429 mov b0 = GR_SAVE_B0 // Restore return address
430 };;
431 { .mib
432 mov gp = GR_SAVE_GP // Restore gp
433 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
434 br.ret.sptk b0 // Return
435 };;
436 LOCAL_LIBM_END(__libm_error_region#)
437 .type __libm_error_support#,@function
438 .global __libm_error_support#