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 //********************************************************************
42 //********************************************************************
43 // 02/02/00 Initial version
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 // 02/10/03 Reordered header: .section, .global, .proc, .align
49 //********************************************************************
51 // Function: Combined sqrt(x), where
53 // sqrt(x) = |x, for double precision x values
55 //********************************************************************
57 // Accuracy: Correctly Rounded
59 //********************************************************************
63 // Floating-Point Registers: f8 (Input and Return Value)
66 // General Purpose Registers:
68 // r37-r40 (Used to pass arguments to error handling routine)
70 // Predicate Registers: p6, p7, p8
72 //*********************************************************************
74 // IEEE Special Conditions:
76 // All faults and exceptions should be raised correctly.
80 // sqrt(negative) = QNaN and error handling is called
82 //*********************************************************************
86 // Modified Newton-Raphson Algorithm
88 //*********************************************************************
96 GR_Parameter_RESULT = r39
100 GLOBAL_IEEE754_ENTRY(sqrt)
102 alloc r32= ar.pfs,0,5,4,0
106 // BEGIN DOUBLE PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
108 // exponent of +1/2 in r2
122 // y0 = 1/sqrt(a) in f7
123 fclass.m.unc p7,p8 = f8,0x3A
132 movl r3 = 0x40fc0000;;
136 // h = +1/2 * y0 in f6
137 (p6) fma.s1 f6=f9,f7,f0
143 (p6) fma.s1 f7=f8,f7,f0
152 movl r2 = 0x41670000;;
156 // e = 1/2 - g * h in f9
157 (p6) fnma.s1 f9=f7,f6,f9
162 movl r3 = 0x408c0000;;
166 // S = 3/2 + 5/2 * e in f10
167 (p6) fma.s1 f10=f11,f9,f10
173 (p6) fma.s1 f11=f9,f9,f0
178 // t = 63/8 + 231/16 * e in f12
179 (p6) fma.s1 f12=f13,f9,f12
184 // S1 = e + e2 * S in f10
185 (p6) fma.s1 f10=f11,f10,f9
190 // e4 = e2 * e2 in f11
191 (p6) fma.s1 f11=f11,f11,f0
196 // t1 = 35/8 + e * t in f9
197 (p6) fma.s1 f9=f9,f12,f14
202 // G = g + S1 * g in f12
203 (p6) fma.s1 f12=f10,f7,f7
209 (p6) fma.s1 f7=f7,f11,f0
214 // u = S1 + e4 * t1 in f10
215 (p6) fma.s1 f10=f11,f9,f10
220 // g1 = G + t1 * E in f7
221 (p6) fma.d.s1 f7=f9,f7,f12
226 // h1 = h + u * h in f6
227 (p6) fma.s1 f6=f10,f6,f6
232 // d = a - g1 * g1 in f9
233 (p6) fnma.s1 f9=f7,f7,f8
238 // g2 = g1 + d * h1 in f7
239 (p6) fma.d.s0 f8=f9,f6,f7
240 (p6) br.ret.sptk b0 ;;
246 (p8) br.ret.sptk b0 ;;
251 (p7) br.cond.sptk __libm_error_region ;;
253 // END DOUBLE PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
254 GLOBAL_IEEE754_END(sqrt)
255 // Stack operations when calling error support.
256 // (1) (2) (3) (call) (4)
257 // sp -> + psp -> + psp -> + sp -> +
259 // | | <- GR_Y R3 ->| <- GR_RESULT | -> f8
261 // | <-GR_Y Y2->| Y2 ->| <- GR_Y |
263 // | | <- GR_X X1 ->| |
265 // sp-64 -> + sp -> + sp -> + +
266 // save ar.pfs save b0 restore gp
267 // save gp restore ar.pfs
270 LOCAL_LIBM_ENTRY(__libm_error_region)
273 // This branch includes all those special values that are not negative,
274 // with the result equal to frcpa(x)
278 // We are distinguishing between over(under)flow and letting
279 // __libm_error_support set ERANGE or do anything else needed.
283 add GR_Parameter_Y=-32,sp // Parameter 2 value
285 .save ar.pfs,GR_SAVE_PFS
286 mov GR_SAVE_PFS=ar.pfs // Save ar.pfs
290 add sp=-64,sp // Create new stack
292 mov GR_SAVE_GP=gp // Save gp
298 stfd [GR_Parameter_Y] = f0,16 // STORE Parameter 2 on stack
299 add GR_Parameter_X = 16,sp // Parameter 1 address
301 mov GR_SAVE_B0=b0 // Save b0
307 stfd [GR_Parameter_X] = f15 // STORE Parameter 1 on stack
308 add GR_Parameter_RESULT = 0,GR_Parameter_Y // Parameter 3 address
312 stfd [GR_Parameter_Y] = f8 // STORE Parameter 3 on stack
313 add GR_Parameter_Y = -16,GR_Parameter_Y
314 br.call.sptk b0=__libm_error_support# // Call error handling function
319 add GR_Parameter_RESULT = 48,sp
324 ldfd f8 = [GR_Parameter_RESULT] // Get return result off stack
326 add sp = 64,sp // Restore stack pointer
327 mov b0 = GR_SAVE_B0 // Restore return address
330 mov gp = GR_SAVE_GP // Restore gp
331 mov ar.pfs = GR_SAVE_PFS // Restore ar.pfs
332 br.ret.sptk b0 // Return
335 LOCAL_LIBM_END(__libm_error_region)
340 .type __libm_error_support#,@function
341 .global __libm_error_support#