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
51
//*********************************************************************
53
// Function: hypotl(x,y) = |(x^2 + y^2) = for double extended values
55
// Also provides cabsl 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
// hypotl(Infinity and anything) = +Infinity
79
// hypotl(QNaN and anything) = QNaN
80
// hypotl(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 extended
90
//*********************************************************************
97
GR_Parameter_RESULT = r38
98
GR_Parameter_TAG = r39
106
LOCAL_LIBM_ENTRY(cabsl)
107
LOCAL_LIBM_END(cabsl)
109
GLOBAL_IEEE754_ENTRY(hypotl)
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 f32
134
// set Denormal, if necessary
141
// Check if y is an Inf - if so return Inf even
142
// if x is a NaN (C9X)
143
fclass.m.unc p8, p9 = f9, 0x023
148
// For x=inf, multiply y by 1 to raise invalid on y an SNaN
149
// (p7) fma.s0 f9=f9,f1,f0
150
// copy f9 to f33; set Denormal, if necessary
157
(p6) fclass.m p6,p0=f9,0x7
165
fma.s1 f12=f10,f1,f11
177
(p9) fclass.m p9,p0=f8,0x7
190
(p6) fclass.m p7,p0=f8,0x3f
216
(p9) fclass.m p8,p0=f9,0x3f
222
// if f8=Infinity or f9=Zero, return |f8|
223
(p7) fmerge.s f8=f0,f32
224
(p7) br.ret.spnt b0;;
236
// Identify Natvals, Infs, NaNs, and Zeros
238
fclass.m.unc p7, p0 = f12, 0x1E7
242
// get exponent of x^2+y^2
245
fma.s1 f13=f13,f1,f14
252
// if f9=Infinity or f8=Zero, return |f9|
253
(p8) fmerge.s f8=f0,f33
259
fnma.s1 f10=f10,f1,f12
266
(p6) fma.s1 f14=f12,f8,f0
272
(p6) fma.s1 f15=f8,f7,f0
278
// if special case, set f8
285
fnma.s1 f10=f10,f1,f34
304
(p6) fnma.s1 f7=f14,f15,f7
311
(p6) fma.s1 f11=f11,f7,f1
317
(p6) fma.s1 f9=f9,f7,f6
323
(p6) fma.s1 f34=f7,f7,f0
330
(p6) fma.s1 f6=f7,f14,f0
336
(p6) fma.s1 f7=f7,f15,f0
342
(p6) fma.s1 f11=f34,f9,f11
349
(p6) fma.s1 f14=f11,f6,f14
355
(p6) fma.s1 f15=f11,f7,f15
363
(p6) fnma.s1 f7=f14,f14,f12
367
// Is x^2 + y^2 well less than the overflow
369
(p6) cmp.lt.unc p7, p8 = r3,r2
371
(p6) fma.s1 f13=f13,f1,f10
378
(p6) fma.s1 f13=f7,f1,f13
385
fma.s0 f8=f13,f15,f14
386
// No overflow in this case
387
(p7) br.ret.sptk b0;;
392
(p8) fsetc.s2 0x7F,0x42
393
// Possible overflow path, must detect by
394
// Setting widest range exponent with prevailing
401
// bias+0x4000 (bias+EMAX+1)
404
(p8) fma.s2 f12=f13,f15,f14
408
(p8) setf.exp f11 = r2
409
(p8) fsetc.s2 0x7F,0x40
410
// Restore Original Mode in S2
415
(p8) fcmp.lt.unc.s1 p9, p10 = f12, f11
420
mov GR_Parameter_TAG = 45;
422
(p9) br.ret.sptk b0;;
424
GLOBAL_IEEE754_END(hypotl)
426
LOCAL_LIBM_ENTRY(__libm_error_region)
429
add GR_Parameter_Y=-32,sp // Parameter 2 value
431
.save ar.pfs,GR_SAVE_PFS
432
mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
436
add sp=-64,sp // Create new stack
438
mov GR_SAVE_GP=gp // Save gp
441
stfe [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
442
add GR_Parameter_X = 16,sp // Parameter 1 address
444
mov GR_SAVE_B0=b0 // Save b0
448
stfe [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
449
add GR_Parameter_RESULT = 0,GR_Parameter_Y
450
nop.b 0 // Parameter 3 address
453
stfe [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
454
add GR_Parameter_Y = -16,GR_Parameter_Y
455
br.call.sptk b0=__libm_error_support# // Call error handling function
460
add GR_Parameter_RESULT = 48,sp
463
ldfe f8 = [GR_Parameter_RESULT] // Get return result off stack
465
add sp = 64,sp // Restore stack pointer
466
mov b0 = GR_SAVE_B0 // Restore return address
469
mov gp = GR_SAVE_GP // Restore gp
470
mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
471
br.ret.sptk b0 // Return
473
LOCAL_LIBM_END(__libm_error_region#)
474
.type __libm_error_support#,@function
475
.global __libm_error_support#