(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / e_sqrtf.S
blob1799845d6dc30542cf9c01119ffee762e7ab6f6d
1 .file "sqrtf.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 // *********************************************************************
41 // History:
43 // 2/02/00  Initial version
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 sqrtf(x), where
51 //                         _
52 //             sqrtf(x) = |x, for single precision x values
54 // ********************************************************************
56 // Accuracy:       Correctly Rounded 
58 // ********************************************************************
60 // Resources Used:
62 //    Floating-Point Registers: f8  (Input and Return Value)
63 //                              f7 -f14
65 //    General Purpose Registers:
66 //      r32-r36 (Locals)
67 //      r37-r40 (Used to pass arguments to error handling routine)
69 //    Predicate Registers:      p6, p7, p8
71 // ********************************************************************
73 // IEEE Special Conditions:
75 //    All faults and exceptions should be raised correctly.
76 //    sqrtf(QNaN) = QNaN
77 //    sqrtf(SNaN) = QNaN
78 //    sqrtf(+/-0) = +/-0 
79 //    sqrtf(negative) = QNaN and error handling is called
81 // ********************************************************************
83 // Implementation:
85 //  Modified Newton-Raphson Algorithm
87 // ********************************************************************
89 #include "libm_support.h"
91 GR_SAVE_B0                    = r34
92 GR_SAVE_PFS                   = r33
93 GR_SAVE_GP                    = r35 
95 GR_Parameter_X                = r37
96 GR_Parameter_Y                = r38
97 GR_Parameter_RESULT           = r39
98 GR_Parameter_TAG              = r40
100 FR_X             = f13
101 FR_Y             = f0
102 FR_RESULT        = f8
106 .section .text
107 .proc sqrtf#
108 .global sqrtf#
109 .align 64 
111 sqrtf: 
112 #ifdef _LIBC
113 .global __sqrtf
114 .type __sqrtf,@function
115 __sqrtf:
116 .global __ieee754_sqrtf
117 .type __ieee754_sqrtf,@function
118 __ieee754_sqrtf:
119 #endif
120 { .mlx
121   // BEGIN SINGLE PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
122   alloc r32= ar.pfs,0,5,4,0
123   // exponent of +1/2 in r2
124   movl r2 = 0x0fffe
125 } { .mfi
126   // +1/2 in f12
127   nop.m 0
128   frsqrta.s0 f7,p6=f8
129   nop.i 0;;
130 } { .mfi
131   setf.exp f12 = r2
132   // Step (1)
133   // y0 = 1/sqrt(a) in f7
134   fclass.m.unc p7,p8 = f8,0x3A 
135   nop.i 0
136 } { .mfi
137   nop.m 0
138   // Make a copy of x just in case 
139   mov f13 = f8 
140   nop.i 0;;
141 } { .mfi
142   nop.m 0
143   // Step (2)
144   // H0 = 1/2 * y0 in f9
145   (p6) fma.s1 f9=f12,f7,f0
146   nop.i 0
147 } { .mfi
148   nop.m 0
149   // Step (3)
150   // S0 = a * y0 in f7
151   (p6) fma.s1 f7=f8,f7,f0
152   nop.i 0;;
153 } { .mfi
154   nop.m 0
155   // Step (4)
156   // d = 1/2 - S0 * H0 in f10
157   (p6) fnma.s1 f10=f7,f9,f12
158   nop.i 0
159 } { .mfi
160   nop.m 0
161   // Step (0'')
162   // 3/2 = 1 + 1/2 in f12
163   (p6) fma.s1 f12=f12,f1,f1
164   nop.i 0;;
165 } { .mfi
166   nop.m 0
167   // Step (5)
168   // e = 1 + 3/2 * d in f12
169   (p6) fma.s1 f12=f12,f10,f1
170   nop.i 0
171 } { .mfi
172   nop.m 0
173   // Step (6)
174   // T0 = d * S0 in f11
175   (p6) fma.s1 f11=f10,f7,f0
176   nop.i 0;;
177 } { .mfi
178   nop.m 0
179   // Step (7)
180   // G0 = d * H0 in f10
181   (p6) fma.s1 f10=f10,f9,f0
182   nop.i 0;;
183 } { .mfi
184   nop.m 0
185   // Step (8)
186   // S1 = S0 + e * T0 in f7
187   (p6) fma.s.s1 f7=f12,f11,f7
188   nop.i 0;;
189 } { .mfi
190   nop.m 0
191   // Step (9)
192   // H1 = H0 + e * G0 in f12
193   (p6) fma.s1 f12=f12,f10,f9
194   nop.i 0;;
195 } { .mfi
196   nop.m 0
197   // Step (10)
198   // d1 = a - S1 * S1 in f9
199   (p6) fnma.s1 f9=f7,f7,f8
200   nop.i 0;;;
201 } { .mfb
202   nop.m 0
203   // Step (11)
204   // S = S1 + d1 * H1 in f7
205   (p6) fma.s.s0 f8=f9,f12,f7
206   (p6) br.ret.sptk   b0 ;;
207 // END SINGLE PRECISION MINIMUM LATENCY SQUARE ROOT ALGORITHM
208 } { .mfb
209   nop.m 0
210   (p0) mov   f8 = f7
211   (p8) br.ret.sptk b0 ;;
214 // This branch includes all those special values that are not negative,
215 // with the result equal to frcpa(x)
217 .endp sqrtf
218 ASM_SIZE_DIRECTIVE(sqrtf)
219 #ifdef _LIBC
220 ASM_SIZE_DIRECTIVE(__sqrtf)
221 ASM_SIZE_DIRECTIVE(__ieee754_sqrtf)
222 #endif
225 .proc __libm_error_region
226 __libm_error_region:
227 .prologue
228 { .mii
229         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
230 (p0)    mov   GR_Parameter_TAG = 50                   
231 .save   ar.pfs,GR_SAVE_PFS
232         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
234 { .mfi
235 .fframe 64
236         add sp=-64,sp                           // Create new stack
237         nop.f 0
238         mov GR_SAVE_GP=gp                       // Save gp
240 { .mmi
241         stfs [GR_Parameter_Y] = FR_Y,16         // Store Parameter 2 on stack
242         add GR_Parameter_X = 16,sp              // Parameter 1 address
243 .save   b0, GR_SAVE_B0
244         mov GR_SAVE_B0=b0                       // Save b0
246 .body
247 { .mib
248         stfs [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
249         add   GR_Parameter_RESULT = 0,GR_Parameter_Y
250         nop.b 0                                 // Parameter 3 address
252 { .mib
253         stfs [GR_Parameter_Y] = FR_RESULT       // Store Parameter 3 on stack
254         add   GR_Parameter_Y = -16,GR_Parameter_Y
255         br.call.sptk b0=__libm_error_support#   // Call error handling function
257 { .mmi
258         nop.m 0
259         nop.m 0
260         add   GR_Parameter_RESULT = 48,sp
262 { .mmi
263         ldfs  f8 = [GR_Parameter_RESULT]       // Get return result off stack
264 .restore sp
265         add   sp = 64,sp                       // Restore stack pointer
266         mov   b0 = GR_SAVE_B0                  // Restore return address
268 { .mib
269         mov   gp = GR_SAVE_GP                  // Restore gp 
270         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
271         br.ret.sptk     b0                     // Return
272 };; 
274 .endp __libm_error_region
275 ASM_SIZE_DIRECTIVE(__libm_error_region)
278 .type   __libm_error_support#,@function
279 .global __libm_error_support#