3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
6 // Contributed 2/2/2000 by John Harrison, Cristina Iordache, Ted Kubaska,
7 // Bob Norin, Shane Story, and Ping Tak Peter Tang of the
8 // Computational Software Lab, Intel Corporation.
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
14 // * Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
17 // * Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
21 // * The name of Intel Corporation may not be used to endorse or promote
22 // products derived from this software without specific prior written
25 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
33 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 // Intel Corporation is the author of this code, and requests that all
38 // problem reports or change requests be submitted to it directly at
39 // http://developer.intel.com/opensource.
41 // *********************************************************************
44 // 2/02/00 hand-optimized
45 // 4/04/00 Unwind support added
46 // 6/20/00 new version
47 // 8/15/00 Bundle added after call to __libm_error_support to properly
48 // set [the previously overwritten] GR_Parameter_RESULT.
50 // *********************************************************************
52 // Function: hypotl(x,y) = |(x^2 + y^2) = for double extended values
54 // Also provides cabsl functionality.
56 // *********************************************************************
60 // Floating-Point Registers: f8 (Input and Return Value)
64 // General Purpose Registers:
67 // r37-r40 (Used to pass arguments to error handling routine)
69 // Predicate Registers: p6 - p10
71 // *********************************************************************
73 // IEEE Special Conditions:
75 // All faults and exceptions should be raised correctly.
76 // Overflow can occur.
77 // hypotl(Infinity and anything) = +Infinity
78 // hypotl(QNaN and anything) = QNaN
79 // hypotl(SNaN and anything ) = QNaN
81 // *********************************************************************
84 // x2 = x * x in double-extended
85 // y2 = y * y in double-extended
86 // temp = x2 + y2 in double-extended
87 // sqrt(temp) rounded to double extended
89 // *********************************************************************
91 #include "libm_support.h"
98 GR_Parameter_RESULT = r38
99 GR_Parameter_TAG = r39
120 .global __ieee754_hypotl
124 alloc r32= ar.pfs,0,4,4,0
139 // Check if x is an Inf - if so return Inf even
140 // if y is a NaN (C9X)
141 fclass.m.unc p7, p6 = f8, 0x023
146 // if possible overflow, copy f8 to f32
147 // set Denormal, if necessary
154 // Check if y is an Inf - if so return Inf even
155 // if x is a NaN (C9X)
156 fclass.m.unc p8, p9 = f9, 0x023
161 // For x=inf, multiply y by 1 to raise invalid on y an SNaN
162 // (p7) fma.s0 f9=f9,f1,f0
163 // copy f9 to f33; set Denormal, if necessary
170 (p6) fclass.m p6,p0=f9,0x7
178 fma.s1 f12=f10,f1,f11
190 (p9) fclass.m p9,p0=f8,0x7
203 (p6) fclass.m p7,p0=f8,0x3f
229 (p9) fclass.m p8,p0=f9,0x3f
235 // if f8=Infinity or f9=Zero, return |f8|
236 (p7) fmerge.s f8=f0,f32
237 (p7) br.ret.spnt b0;;
249 // Identify Natvals, Infs, NaNs, and Zeros
251 fclass.m.unc p7, p0 = f12, 0x1E7
255 // get exponent of x^2+y^2
258 fma.s1 f13=f13,f1,f14
265 // if f9=Infinity or f8=Zero, return |f9|
266 (p8) fmerge.s f8=f0,f33
272 fnma.s1 f10=f10,f1,f12
279 (p6) fma.s1 f14=f12,f8,f0
285 (p6) fma.s1 f15=f8,f7,f0
291 // if special case, set f8
298 fnma.s1 f10=f10,f1,f34
317 (p6) fnma.s1 f7=f14,f15,f7
324 (p6) fma.s1 f11=f11,f7,f1
330 (p6) fma.s1 f9=f9,f7,f6
336 (p6) fma.s1 f34=f7,f7,f0
343 (p6) fma.s1 f6=f7,f14,f0
349 (p6) fma.s1 f7=f7,f15,f0
355 (p6) fma.s1 f11=f34,f9,f11
362 (p6) fma.s1 f14=f11,f6,f14
368 (p6) fma.s1 f15=f11,f7,f15
376 (p6) fnma.s1 f7=f14,f14,f12
380 // Is x^2 + y^2 well less than the overflow
382 (p6) cmp.lt.unc p7, p8 = r3,r2
384 (p6) fma.s1 f13=f13,f1,f10
391 (p6) fma.s1 f13=f7,f1,f13
398 fma.s0 f8=f13,f15,f14
399 // No overflow in this case
400 (p7) br.ret.sptk b0;;
405 (p8) fsetc.s2 0x7F,0x42
406 // Possible overflow path, must detect by
407 // Setting widest range exponent with prevailing
414 // bias+0x4000 (bias+EMAX+1)
417 (p8) fma.s2 f12=f13,f15,f14
421 (p8) setf.exp f11 = r2
422 (p8) fsetc.s2 0x7F,0x40
423 // Restore Original Mode in S2
428 (p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
433 mov GR_Parameter_TAG = 45;
435 (p9) br.ret.sptk b0;;
438 ASM_SIZE_DIRECTIVE(hypotl)
440 .proc __libm_error_region
444 add GR_Parameter_Y=-32,sp // Parameter 2 value
446 .save ar.pfs,GR_SAVE_PFS
447 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
451 add sp=-64,sp // Create new stack
453 mov GR_SAVE_GP=gp // Save gp
456 stfe [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
457 add GR_Parameter_X = 16,sp // Parameter 1 address
459 mov GR_SAVE_B0=b0 // Save b0
463 stfe [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
464 add GR_Parameter_RESULT = 0,GR_Parameter_Y
465 nop.b 0 // Parameter 3 address
468 stfe [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
469 add GR_Parameter_Y = -16,GR_Parameter_Y
470 br.call.sptk b0=__libm_error_support# // Call error handling function
475 add GR_Parameter_RESULT = 48,sp
478 ldfe f8 = [GR_Parameter_RESULT] // Get return result off stack
480 add sp = 64,sp // Restore stack pointer
481 mov b0 = GR_SAVE_B0 // Restore return address
484 mov gp = GR_SAVE_GP // Restore gp
485 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
486 br.ret.sptk b0 // Return
488 .endp __libm_error_region
489 ASM_SIZE_DIRECTIVE(__libm_error_region)
490 .type __libm_error_support#,@function
491 .global __libm_error_support#