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/26/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: hypotf(x,y) = |(x^2 + y^2) = for single precision values
55 // Also provides cabsf functionality.
57 //*********************************************************************
61 // Floating-Point Registers: f8 (Input and Return Value)
65 // General Purpose Registers:
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 // hypotf(Infinity and anything) = +Infinity
79 // hypotf(QNaN and anything) = QNaN
80 // hypotf(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 single precision
90 //*********************************************************************
97 GR_Parameter_RESULT = r38
98 GR_Parameter_TAG = r39
106 LOCAL_LIBM_ENTRY(cabsf)
107 LOCAL_LIBM_END(cabsf)
109 GLOBAL_IEEE754_ENTRY(hypotf)
111 alloc r32= ar.pfs,0,4,4,0
126 // Check if x is an Inf - if so return Inf even
127 // if y is a NaN (C9X)
128 fclass.m.unc p7, p6 = f8, 0x023
133 // if possible overflow, copy f8 to f14
134 // set Denormal, if necessary
136 fma.s.s0 f14=f8,f1,f0
142 // Check if y is an Inf - if so return Inf even
143 // if x is a NaN (C9X)
144 fclass.m.unc p8, p9 = f9, 0x023
149 // For x=inf, multiply y by 1 to raise invalid on y an SNaN
150 // (p7) fma.s0 f9=f9,f1,f0
151 // copy f9 to f15; set Denormal, if necessary
152 fma.s.s0 f15=f9,f1,f0
158 (p6) fclass.m p6,p0=f9,0x7
164 (p9) fclass.m p9,p0=f8,0x7
172 fma.s1 f12=f10,f1,f11
179 (p6) fclass.m p7,p0=f8,0x3f
193 (p9) fclass.m p8,p0=f9,0x3f
197 .pred.rel "mutex",p7,p8
200 // if f8=Infinity or f9=Zero, return |f8|
201 (p7) fmerge.s f8=f0,f14
206 // if f9=Infinity or f8=Zero, return |f9|
207 (p8) fmerge.s f8=f0,f15
208 (p8) br.ret.spnt b0;;
213 // Identify Natvals, Infs, NaNs, and Zeros
215 fclass.m.unc p7, p0 = f12, 0x1E7
226 // get exponent of x^2+y^2
228 // if special case, set f8
230 (p7) br.ret.spnt b0;;
237 (p6) fma.s1 f12=f12,f8,f0
243 (p6) fma.s1 f10=f8,f7,f0
264 (p6) fnma.s1 f7=f12,f10,f7
271 (p6) fma.s1 f10=f1,f7,f1
277 (p6) fma.s1 f11=f6,f7,f11
283 (p6) fma.s1 f7=f7,f7,f0
289 // Is x^2 + y^2 well less than the overflow
291 (p6) cmp.lt.unc p7, p8 = r3,r2
293 (p6) fma.s1 f10=f7,f11,f10
300 fma.s.s0 f8=f10,f12,f0
301 // No overflow in this case
302 (p7) br.ret.sptk b0;;
307 (p8) fsetc.s2 0x7F,0x42
308 // Possible overflow path, must detect by
309 // Setting widest range exponent with prevailing
316 // bias+0x400 (bias+EMAX+1)
319 (p8) fma.s.s2 f12=f10,f12,f0
323 (p8) setf.exp f11 = r2
324 (p8) fsetc.s2 0x7F,0x40
325 // Restore Original Mode in S2
330 (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
335 mov GR_Parameter_TAG = 47
337 (p9) br.ret.sptk b0;;
339 GLOBAL_IEEE754_END(hypotf)
340 libm_alias_float_other (__hypot, hypot)
342 LOCAL_LIBM_ENTRY(__libm_error_region)
345 add GR_Parameter_Y=-32,sp // Parameter 2 value
346 mov GR_Parameter_TAG = 47
347 .save ar.pfs,GR_SAVE_PFS
348 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
352 add sp=-64,sp // Create new stack
354 mov GR_SAVE_GP=gp // Save gp
357 stfs [GR_Parameter_Y] = FR_Y,16 // Store Parameter 2 on stack
358 add GR_Parameter_X = 16,sp // Parameter 1 address
360 mov GR_SAVE_B0=b0 // Save b0
364 stfs [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
365 add GR_Parameter_RESULT = 0,GR_Parameter_Y
366 nop.b 0 // Parameter 3 address
369 stfs [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
370 add GR_Parameter_Y = -16,GR_Parameter_Y
371 br.call.sptk b0=__libm_error_support# // Call error handling function
376 add GR_Parameter_RESULT = 48,sp
379 ldfs f8 = [GR_Parameter_RESULT] // Get return result off stack
381 add sp = 64,sp // Restore stack pointer
382 mov b0 = GR_SAVE_B0 // Restore return address
385 mov gp = GR_SAVE_GP // Restore gp
386 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
387 br.ret.sptk b0 // Return
390 LOCAL_LIBM_END(__libm_error_region)
393 .type __libm_error_support#,@function
394 .global __libm_error_support#