(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / e_sqrtl.S
blobe41148243a7e76c0ee2117191e1830ecfcc12a48
1 .file "sqrtl.s"
3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
5 // 
6 // Contributed 2/2/2000 by John Harrison, Ted Kubaska, Bob Norin, Shane Story,
7 // and Ping Tak Peter Tang of the Computational Software Lab, Intel Corporation.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
11 // met:
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
22 // permission.
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. 
35 // 
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://developer.intel.com/opensource.
40 // ********************************************************************
42 // History:
43 // 2/02/00 (hand-optimized)
44 // 4/04/00  Unwind support added
45 // 8/15/00  Bundle added after call to __libm_error_support to properly
46 //          set [the previously overwritten] GR_Parameter_RESULT.
48 // ********************************************************************
50 // Function:   Combined sqrtl(x), where
51 //                         _
52 //             sqrtl(x) = |x, for double-extended precision x values
54 // ********************************************************************
56 // Resources Used:
58 //    Floating-Point Registers: f8  (Input and Return Value)
59 //                              f7 -f14
61 //    General Purpose Registers:
62 //      r32-r36 (Locals)
63 //      r37-r40 (Used to pass arguments to error handling routine)
65 //    Predicate Registers:      p6, p7, p8
67 // ********************************************************************
69 // IEEE Special Conditions:
71 //    All faults and exceptions should be raised correctly.
72 //    sqrtl(QNaN) = QNaN
73 //    sqrtl(SNaN) = QNaN
74 //    sqrtl(+/-0) = +/-0
75 //    sqrtl(negative) = QNaN and error handling is called
77 // ********************************************************************
79 // Implementation:
81 //  Modified Newton-Raphson Algorithm
83 // ********************************************************************
85 #include "libm_support.h"
87 GR_SAVE_PFS         = r33
88 GR_SAVE_B0          = r34
89 GR_SAVE_GP          = r35
90 GR_Parameter_X      = r37
91 GR_Parameter_Y      = r38
92 GR_Parameter_RESULT = r39
93 GR_Parameter_TAG    = r40
95 FR_X                = f15
96 FR_Y                = f0
97 FR_RESULT           = f8
99 .section .text
100 .proc sqrtl#
101 .global sqrtl#
102 .align 64
104 sqrtl:
105 #ifdef _LIBC
106 .global __sqrtl
107 .type __sqrtl,@function
108 __sqrtl:
109 .global __ieee754_sqrtl
110 .type __ieee754_sqrtl,@function
111 __ieee754_sqrtl:
112 #endif
113 { .mlx
114 alloc r32= ar.pfs,0,5,4,0
115   // exponent of +1/2 in r2
116   movl r2 = 0x0fffe;;
117 } { .mfi
118   // +1/2 in f10
119   setf.exp f12 = r2
120   // Step (1)
121   // y0 = 1/sqrt(a) in f7
122   frsqrta.s0 f7,p6=f8
123   nop.i 0;;
124 } { .mfi
125   nop.m 0
126   // Step (2)
127   // H0 = +1/2 * y0 in f9
128   (p6) fma.s1 f9=f12,f7,f0
129   nop.i 0
130 } { .mfi
131   nop.m 0
132   // Step (3)
133   // S0 = a * y0 in f7
134   (p6) fma.s1 f7=f8,f7,f0
135   nop.i 0;;
136 } { .mfi
137   nop.m 0
138   // Make copy input x 
139   mov f13=f8 
140   nop.i 0
141 } { .mfi
142   nop.m 0
143   fclass.m.unc p7,p8 = f8,0x3A
144   nop.i 0;;
145 } { .mfi
146   nop.m 0
147   // Step (4)
148   // d0 = 1/2 - S0 * H0 in f10
149   (p6) fnma.s1 f10=f7,f9,f12
150   nop.i 0;;
152 { .mfi
153   nop.m 0
154   (p0) mov f15=f8
155   nop.i 0;;
156 } { .mfi
157   nop.m 0
158   // Step (5)
159   // H1 = H0 + d0 * H0 in f9
160   (p6) fma.s1 f9=f10,f9,f9
161   nop.i 0
162 } { .mfi
163   nop.m 0
164   // Step (6)
165   // S1 = S0 + d0 * S0 in f7
166   (p6) fma.s1 f7=f10,f7,f7
167   nop.i 0;;
168 } { .mfi
169   nop.m 0
170   // Step (7)
171   // d1 = 1/2 - S1 * H1 in f10
172   (p6) fnma.s1 f10=f7,f9,f12
173   nop.i 0;;
174 } { .mfi
175   nop.m 0
176   // Step (8)
177   // H2 = H1 + d1 * H1 in f9
178   (p6) fma.s1 f9=f10,f9,f9
179   nop.i 0
180 } { .mfi
181   nop.m 0
182   // Step (9)
183   // S2 = S1 + d1 * S1 in f7
184   (p6) fma.s1 f7=f10,f7,f7
185   nop.i 0;;
186 } { .mfi
187   nop.m 0
188   // Step (10)
189   // d2 = 1/2 - S2 * H2 in f10
190   (p6) fnma.s1 f10=f7,f9,f12
191   nop.i 0
192 } { .mfi
193   nop.m 0
194   // Step (11)
195   // e2 = a - S2 * S2 in f12
196   (p6) fnma.s1 f12=f7,f7,f8
197   nop.i 0;;
198 } { .mfi
199   nop.m 0
200   // Step (12)
201   // S3 = S2 + d2 * S2 in f7
202   (p6) fma.s1 f7=f12,f9,f7
203   nop.i 0
204 } { .mfi
205   nop.m 0
206   // Step (13)
207   // H3 = H2 + d2 * H2 in f9
208   (p6) fma.s1 f9=f10,f9,f9
209   nop.i 0;;
210 } { .mfi
211   nop.m 0
212   // Step (14)
213   // e3 = a - S3 * S3 in f12
214   (p6) fnma.s1 f12=f7,f7,f8
215   nop.i 0;;
216 } { .mfb
217   nop.m 0
218   // Step (15)
219   // S = S3 + e3 * H3 in f7
220   (p6) fma.s0 f8=f12,f9,f7
221   (p6) br.ret.sptk b0 ;;
223 { .mfb
224   (p0) mov GR_Parameter_TAG    = 48
225   (p0) mov   f8 = f7
226   (p8) br.ret.sptk b0 ;;
229 // This branch includes all those special values that are not negative,
230 // with the result equal to frcpa(x)
234 // END DOUBLE EXTENDED PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
235 .endp sqrtl#
236 ASM_SIZE_DIRECTIVE(sqrtl)
237 #ifdef _LIBC
238 ASM_SIZE_DIRECTIVE(__sqrtl)
239 ASM_SIZE_DIRECTIVE(__ieee754_sqrtl)
240 #endif
242 .proc __libm_error_region
243 __libm_error_region:
244 .prologue
245 { .mfi
246         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
247         nop.f 0
248 .save   ar.pfs,GR_SAVE_PFS
249         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
251 { .mfi
252 .fframe 64
253         add sp=-64,sp                           // Create new stack
254         nop.f 0
255         mov GR_SAVE_GP=gp                       // Save gp
257 { .mmi
258         stfe [GR_Parameter_Y] = FR_Y,16         // Save Parameter 2 on stack
259         add GR_Parameter_X = 16,sp              // Parameter 1 address
260 .save   b0, GR_SAVE_B0
261         mov GR_SAVE_B0=b0                       // Save b0
263 .body
264 { .mib
265         stfe [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
266         add   GR_Parameter_RESULT = 0,GR_Parameter_Y
267         nop.b 0                                 // Parameter 3 address
269 { .mib
270         stfe [GR_Parameter_Y] = FR_RESULT      // Store Parameter 3 on stack
271         add   GR_Parameter_Y = -16,GR_Parameter_Y
272         br.call.sptk b0=__libm_error_support#  // Call error handling function
274 { .mmi
275         nop.m 0
276         nop.m 0
277         add   GR_Parameter_RESULT = 48,sp
279 { .mmi
280         ldfe  f8 = [GR_Parameter_RESULT]       // Get return result off stack
281 .restore sp
282         add   sp = 64,sp                       // Restore stack pointer
283         mov   b0 = GR_SAVE_B0                  // Restore return address
285 { .mib
286         mov   gp = GR_SAVE_GP                  // Restore gp
287         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
288         br.ret.sptk     b0                     // Return
291 .endp __libm_error_region
292 ASM_SIZE_DIRECTIVE(__libm_error_region)
293 .type   __libm_error_support#,@function
294 .global __libm_error_support#