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 // 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
50 //********************************************************************
52 // Function: Combined sqrtl(x), where
54 // sqrtl(x) = |x, for double-extended precision x values
56 //********************************************************************
60 // Floating-Point Registers: f8 (Input and Return Value)
63 // General Purpose Registers:
65 // r37-r40 (Used to pass arguments to error handling routine)
67 // Predicate Registers: p6, p7, p8
69 //********************************************************************
71 // IEEE Special Conditions:
73 // All faults and exceptions should be raised correctly.
77 // sqrtl(negative) = QNaN and error handling is called
79 //********************************************************************
83 // Modified Newton-Raphson Algorithm
85 //********************************************************************
92 GR_Parameter_RESULT = r39
93 GR_Parameter_TAG = r40
100 GLOBAL_IEEE754_ENTRY(sqrtl)
102 alloc r32= ar.pfs,0,5,4,0
103 // exponent of +1/2 in r2
109 // y0 = 1/sqrt(a) in f7
115 // H0 = +1/2 * y0 in f9
116 (p6) fma.s1 f9=f12,f7,f0
122 (p6) fma.s1 f7=f8,f7,f0
131 fclass.m.unc p7,p8 = f8,0x3A
136 // d0 = 1/2 - S0 * H0 in f10
137 (p6) fnma.s1 f10=f7,f9,f12
147 // H1 = H0 + d0 * H0 in f9
148 (p6) fma.s1 f9=f10,f9,f9
153 // S1 = S0 + d0 * S0 in f7
154 (p6) fma.s1 f7=f10,f7,f7
159 // d1 = 1/2 - S1 * H1 in f10
160 (p6) fnma.s1 f10=f7,f9,f12
165 // H2 = H1 + d1 * H1 in f9
166 (p6) fma.s1 f9=f10,f9,f9
171 // S2 = S1 + d1 * S1 in f7
172 (p6) fma.s1 f7=f10,f7,f7
177 // d2 = 1/2 - S2 * H2 in f10
178 (p6) fnma.s1 f10=f7,f9,f12
183 // e2 = a - S2 * S2 in f12
184 (p6) fnma.s1 f12=f7,f7,f8
189 // S3 = S2 + d2 * S2 in f7
190 (p6) fma.s1 f7=f12,f9,f7
195 // H3 = H2 + d2 * H2 in f9
196 (p6) fma.s1 f9=f10,f9,f9
201 // e3 = a - S3 * S3 in f12
202 (p6) fnma.s1 f12=f7,f7,f8
207 // S = S3 + e3 * H3 in f7
208 (p6) fma.s0 f8=f12,f9,f7
209 (p6) br.ret.sptk b0 ;;
212 mov GR_Parameter_TAG = 48
214 (p8) br.ret.sptk b0 ;;
217 // This branch includes all those special values that are not negative,
218 // with the result equal to frcpa(x)
222 // END DOUBLE EXTENDED PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
223 GLOBAL_IEEE754_END(sqrtl)
225 LOCAL_LIBM_ENTRY(__libm_error_region)
228 add GR_Parameter_Y=-32,sp // Parameter 2 value
230 .save ar.pfs,GR_SAVE_PFS
231 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
235 add sp=-64,sp // Create new stack
237 mov GR_SAVE_GP=gp // Save gp
240 stfe [GR_Parameter_Y] = FR_Y,16 // Save Parameter 2 on stack
241 add GR_Parameter_X = 16,sp // Parameter 1 address
243 mov GR_SAVE_B0=b0 // Save b0
247 stfe [GR_Parameter_X] = FR_X // Store Parameter 1 on stack
248 add GR_Parameter_RESULT = 0,GR_Parameter_Y
249 nop.b 0 // Parameter 3 address
252 stfe [GR_Parameter_Y] = FR_RESULT // Store Parameter 3 on stack
253 add GR_Parameter_Y = -16,GR_Parameter_Y
254 br.call.sptk b0=__libm_error_support# // Call error handling function
259 add GR_Parameter_RESULT = 48,sp
262 ldfe f8 = [GR_Parameter_RESULT] // Get return result off stack
264 add sp = 64,sp // Restore stack pointer
265 mov b0 = GR_SAVE_B0 // Restore return address
268 mov gp = GR_SAVE_GP // Restore gp
269 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
270 br.ret.sptk b0 // Return
273 LOCAL_LIBM_END(__libm_error_region#)
274 .type __libm_error_support#,@function
275 .global __libm_error_support#