4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
7 // Contributed 2000 by the Intel Numerics Group, Intel Corporation
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
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
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.
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 //*********************************************************************
43 // 02/02/00 hand-optimized
44 // 04/04/00 Unwind support added
45 // 06/20/00 new version
46 // 08/15/00 Bundle added after call to __libm_error_support to properly
47 // set [the previously overwritten] GR_Parameter_RESULT.
48 // 05/20/02 Cleaned up namespace and sf0 syntax
49 // 02/10/03 Reordered header: .section, .global, .proc, .align
50 // 04/17/03 Added missing mutex directive
52 //*********************************************************************
54 // Function: hypot(x,y) = |(x^2 + y^2) = for double precision values
56 // Also provides cabs functionality.
58 //*********************************************************************
62 // Floating-Point Registers: f8 (Input and Return Value)
66 // General Purpose Registers:
67 // r2,r3,r29 (Scratch)
69 // r37-r40 (Used to pass arguments to error handling routine)
71 // Predicate Registers: p6 - p10
73 //*********************************************************************
75 // IEEE Special Conditions:
77 // All faults and exceptions should be raised correctly.
78 // Overflow can occur.
79 // hypot(Infinity and anything) = +Infinity
80 // hypot(QNaN and anything) = QNaN
81 // hypot(SNaN and anything ) = QNaN
83 //*********************************************************************
86 // x2 = x * x in double-extended
87 // y2 = y * y in double-extended
88 // temp = x2 + y2 in double-extended
89 // sqrt(temp) rounded to double
91 //*********************************************************************
98 GR_Parameter_RESULT = r38
99 GR_Parameter_TAG = r39
107 LOCAL_LIBM_ENTRY(cabs)
110 GLOBAL_IEEE754_ENTRY(hypot)
113 alloc r32= ar.pfs,0,4,4,0
125 mov r29=0x41d68;; //000
130 // Check if x is an Inf - if so return Inf even
131 // if y is a NaN (C9X)
132 fclass.m.unc p7, p6 = f8, 0x023
137 // if possible overflow, copy f8 to f32
138 // set Denormal, if necessary
140 fma.d.s0 f32=f8,f1,f0
145 // Check if y is an Inf - if so return Inf even
146 // if x is a NaN (C9X)
147 fclass.m.unc p8, p9 = f9, 0x023
153 // For x=inf, multiply y by 1 to raise invalid on y an SNaN
154 // (p7) fma.s0 f9=f9,f1,f0
155 // copy f9 to f33; set Denormal, if necessary
156 fma.d.s0 f33=f9,f1,f0
163 (p6) fclass.m p6,p0=f9,0x7
175 (p9) fclass.m p9,p0=f8,0x7
177 mov r3=0x4167;; //0000
182 fma.s1 f12=f10,f1,f11
188 (p9) fclass.m p8,p0=f9,0x3f
202 (p6) fclass.m p7,p0=f8,0x3f
213 .pred.rel "mutex",p7,p8
216 // if f8=Infinity or f9=Zero, return |f8|
217 (p7) fmerge.s f8=f0,f32
222 // if f9=Infinity or f8=Zero, return |f9|
223 (p8) fmerge.s f8=f0,f33
224 (p8) br.ret.spnt b0;;
238 // Identify Natvals, Infs, NaNs, and Zeros
240 fclass.m.unc p7, p0 = f12, 0x1E7
244 // get exponent of x^2+y^2
246 // if special case, set f8
248 (p7) br.ret.spnt b0;;
255 (p6) fma.s1 f14=f12,f8,f0
261 (p6) fma.s1 f15=f8,f7,f0
282 (p6) fnma.s1 f7=f14,f15,f7
288 // P67=231/16+429/16*d
289 (p6) fma.s1 f10=f34,f7,f10
295 (p6) fma.s1 f9=f13,f7,f9
301 (p6) fma.s1 f11=f6,f7,f11
307 (p6) fma.s1 f13=f7,f7,f0
314 (p6) fma.s1 f10=f10,f13,f9
320 (p6) fma.s1 f11=f11,f7,f1
326 (p6) fma.s1 f13=f13,f7,f0
333 (p6) fma.s1 f15=f7,f14,f0
337 // Is x^2 + y^2 well less than the overflow
339 (p6) cmp.lt.unc p7, p8 = r3,r2
341 (p6) fma.s1 f10=f13,f10,f11
348 fma.d.s0 f8=f10,f15,f14
349 // No overflow in this case
350 (p7) br.ret.sptk b0;;
355 (p8) fsetc.s2 0x7F,0x42
356 // Possible overflow path, must detect by
357 // Setting widest range exponent with prevailing
364 // bias+0x400 (bias+EMAX+1)
367 (p8) fma.d.s2 f12=f10,f15,f14
371 (p8) setf.exp f11 = r2
372 (p8) fsetc.s2 0x7F,0x40
373 // Restore Original Mode in S2
378 (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
383 mov GR_Parameter_TAG = 46
385 (p9) br.ret.sptk b0;;
387 GLOBAL_IEEE754_END(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#