4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
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.
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
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.
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.
39 //*********************************************************************
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
51 //*********************************************************************
53 // Function: hypot(x,y) = |(x^2 + y^2) = for double precision values
55 // Also provides cabs functionality.
57 //*********************************************************************
61 // Floating-Point Registers: f8 (Input and Return Value)
65 // General Purpose Registers:
66 // r2,r3,r29 (Scratch)
68 // r37-r40 (Used to pass arguments to error handling routine)
70 // Predicate Registers: p6 - p10
72 //*********************************************************************
74 // IEEE Special Conditions:
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
82 //*********************************************************************
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
90 //*********************************************************************
97 GR_Parameter_RESULT = r38
98 GR_Parameter_TAG = r39
106 LOCAL_LIBM_ENTRY(cabs)
109 GLOBAL_IEEE754_ENTRY(hypot)
112 alloc r32= ar.pfs,0,4,4,0
124 mov r29=0x41d68;; //000
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
136 // if possible overflow, copy f8 to f32
137 // set Denormal, if necessary
139 fma.d.s0 f32=f8,f1,f0
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
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
162 (p6) fclass.m p6,p0=f9,0x7
174 (p9) fclass.m p9,p0=f8,0x7
176 mov r3=0x4167;; //0000
181 fma.s1 f12=f10,f1,f11
187 (p9) fclass.m p8,p0=f9,0x3f
201 (p6) fclass.m p7,p0=f8,0x3f
212 .pred.rel "mutex",p7,p8
215 // if f8=Infinity or f9=Zero, return |f8|
216 (p7) fmerge.s f8=f0,f32
221 // if f9=Infinity or f8=Zero, return |f9|
222 (p8) fmerge.s f8=f0,f33
223 (p8) br.ret.spnt b0;;
237 // Identify Natvals, Infs, NaNs, and Zeros
239 fclass.m.unc p7, p0 = f12, 0x1E7
243 // get exponent of x^2+y^2
245 // if special case, set f8
247 (p7) br.ret.spnt b0;;
254 (p6) fma.s1 f14=f12,f8,f0
260 (p6) fma.s1 f15=f8,f7,f0
281 (p6) fnma.s1 f7=f14,f15,f7
287 // P67=231/16+429/16*d
288 (p6) fma.s1 f10=f34,f7,f10
294 (p6) fma.s1 f9=f13,f7,f9
300 (p6) fma.s1 f11=f6,f7,f11
306 (p6) fma.s1 f13=f7,f7,f0
313 (p6) fma.s1 f10=f10,f13,f9
319 (p6) fma.s1 f11=f11,f7,f1
325 (p6) fma.s1 f13=f13,f7,f0
332 (p6) fma.s1 f15=f7,f14,f0
336 // Is x^2 + y^2 well less than the overflow
338 (p6) cmp.lt.unc p7, p8 = r3,r2
340 (p6) fma.s1 f10=f13,f10,f11
347 fma.d.s0 f8=f10,f15,f14
348 // No overflow in this case
349 (p7) br.ret.sptk b0;;
354 (p8) fsetc.s2 0x7F,0x42
355 // Possible overflow path, must detect by
356 // Setting widest range exponent with prevailing
363 // bias+0x400 (bias+EMAX+1)
366 (p8) fma.d.s2 f12=f10,f15,f14
370 (p8) setf.exp f11 = r2
371 (p8) fsetc.s2 0x7F,0x40
372 // Restore Original Mode in S2
377 (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
382 mov GR_Parameter_TAG = 46
384 (p9) br.ret.sptk b0;;
386 GLOBAL_IEEE754_END(hypot)
387 libm_alias_double_other (__hypot, hypot)
389 LOCAL_LIBM_ENTRY(__libm_error_region)
392 add GR_Parameter_Y=-32,sp // Parameter 2 value
394 .save ar.pfs,GR_SAVE_PFS
395 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
399 add sp=-64,sp // Create new stack
401 mov GR_SAVE_GP=gp // Save gp
404 stfd [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
405 add GR_Parameter_X = 16,sp // Parameter 1 address
407 mov GR_SAVE_B0=b0 // Save b0
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
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
423 add GR_Parameter_RESULT = 48,sp
426 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
428 add sp = 64,sp // Restore stack pointer
429 mov b0 = GR_SAVE_B0 // Restore return address
432 mov gp = GR_SAVE_GP // Restore gp
433 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
434 br.ret.sptk b0 // Return
436 LOCAL_LIBM_END(__libm_error_region#)
437 .type __libm_error_support#,@function
438 .global __libm_error_support#