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/26/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: hypotf(x,y) = |(x^2 + y^2) = for single precision values
56 // Also provides cabsf functionality.
58 //*********************************************************************
62 // Floating-Point Registers: f8 (Input and Return Value)
66 // General Purpose Registers:
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 // hypotf(Infinity and anything) = +Infinity
80 // hypotf(QNaN and anything) = QNaN
81 // hypotf(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 single precision
91 //*********************************************************************
98 GR_Parameter_RESULT = r38
99 GR_Parameter_TAG = r39
107 LOCAL_LIBM_ENTRY(cabsf)
108 LOCAL_LIBM_END(cabsf)
110 GLOBAL_IEEE754_ENTRY(hypotf)
112 alloc r32= ar.pfs,0,4,4,0
127 // Check if x is an Inf - if so return Inf even
128 // if y is a NaN (C9X)
129 fclass.m.unc p7, p6 = f8, 0x023
134 // if possible overflow, copy f8 to f14
135 // set Denormal, if necessary
137 fma.s.s0 f14=f8,f1,f0
143 // Check if y is an Inf - if so return Inf even
144 // if x is a NaN (C9X)
145 fclass.m.unc p8, p9 = f9, 0x023
150 // For x=inf, multiply y by 1 to raise invalid on y an SNaN
151 // (p7) fma.s0 f9=f9,f1,f0
152 // copy f9 to f15; set Denormal, if necessary
153 fma.s.s0 f15=f9,f1,f0
159 (p6) fclass.m p6,p0=f9,0x7
165 (p9) fclass.m p9,p0=f8,0x7
173 fma.s1 f12=f10,f1,f11
180 (p6) fclass.m p7,p0=f8,0x3f
194 (p9) fclass.m p8,p0=f9,0x3f
198 .pred.rel "mutex",p7,p8
201 // if f8=Infinity or f9=Zero, return |f8|
202 (p7) fmerge.s f8=f0,f14
207 // if f9=Infinity or f8=Zero, return |f9|
208 (p8) fmerge.s f8=f0,f15
209 (p8) br.ret.spnt b0;;
214 // Identify Natvals, Infs, NaNs, and Zeros
216 fclass.m.unc p7, p0 = f12, 0x1E7
227 // get exponent of x^2+y^2
229 // if special case, set f8
231 (p7) br.ret.spnt b0;;
238 (p6) fma.s1 f12=f12,f8,f0
244 (p6) fma.s1 f10=f8,f7,f0
265 (p6) fnma.s1 f7=f12,f10,f7
272 (p6) fma.s1 f10=f1,f7,f1
278 (p6) fma.s1 f11=f6,f7,f11
284 (p6) fma.s1 f7=f7,f7,f0
290 // Is x^2 + y^2 well less than the overflow
292 (p6) cmp.lt.unc p7, p8 = r3,r2
294 (p6) fma.s1 f10=f7,f11,f10
301 fma.s.s0 f8=f10,f12,f0
302 // No overflow in this case
303 (p7) br.ret.sptk b0;;
308 (p8) fsetc.s2 0x7F,0x42
309 // Possible overflow path, must detect by
310 // Setting widest range exponent with prevailing
317 // bias+0x400 (bias+EMAX+1)
320 (p8) fma.s.s2 f12=f10,f12,f0
324 (p8) setf.exp f11 = r2
325 (p8) fsetc.s2 0x7F,0x40
326 // Restore Original Mode in S2
331 (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
336 mov GR_Parameter_TAG = 47
338 (p9) br.ret.sptk b0;;
340 GLOBAL_IEEE754_END(hypotf)
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#