localedata: dz_BT, bo_CN: convert to UTF-8
[glibc.git] / sysdeps / ia64 / fpu / e_hypotf.S
blob58e93984ae60305753f188d0a1a5294455ba9da1
1 .file "hypotf.s"
4 // Copyright (c) 2000 - 2003, Intel Corporation
5 // All rights reserved.
6 //
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are
10 // met:
12 // * Redistributions of source code must retain the above copyright
13 // notice, this list of conditions and the following disclaimer.
15 // * Redistributions in binary form must reproduce the above copyright
16 // notice, this list of conditions and the following disclaimer in the
17 // documentation and/or other materials provided with the distribution.
19 // * The name of Intel Corporation may not be used to endorse or promote
20 // products derived from this software without specific prior written
21 // permission.
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
27 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
31 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
32 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 // Intel Corporation is the author of this code, and requests that all
36 // problem reports or change requests be submitted to it directly at
37 // http://www.intel.com/software/products/opensource/libraries/num.htm.
39 //*********************************************************************
41 // History:
42 // 02/02/00 hand-optimized
43 // 04/04/00 Unwind support added
44 // 06/26/00 new version
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
49 // 04/17/03 Added missing mutex directive
51 //*********************************************************************
52 //                           ___________
53 // Function:   hypotf(x,y) = |(x^2 + y^2) = for single precision values
54 //             x and y
55 //             Also provides cabsf functionality.
57 //*********************************************************************
59 // Resources Used:
61 //    Floating-Point Registers: f8  (Input and Return Value)
62 //                              f9  (Input)
63 //                              f6 -f15
65 //    General Purpose Registers:
66 //      r2-r3   (Scratch)
67 //      r32-r36 (Locals)
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 //    hypotf(Infinity and anything) = +Infinity
79 //    hypotf(QNaN and anything) = QNaN
80 //    hypotf(SNaN and anything ) = QNaN
82 //*********************************************************************
84 // Implementation:
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 single precision
90 //*********************************************************************
92 GR_SAVE_PFS         = r33
93 GR_SAVE_B0          = r34
94 GR_SAVE_GP          = r35
95 GR_Parameter_X      = r36
96 GR_Parameter_Y      = r37
97 GR_Parameter_RESULT = r38
98 GR_Parameter_TAG    = r39
100 FR_X                = f14
101 FR_Y                = f15
102 FR_RESULT           = f8
104 .section .text
106 LOCAL_LIBM_ENTRY(cabsf)
107 LOCAL_LIBM_END(cabsf)
109 GLOBAL_IEEE754_ENTRY(hypotf)
110 {.mfi
111   alloc r32= ar.pfs,0,4,4,0
112   // Compute x*x
113   fma.s1 f10=f8,f8,f0
114   // r2=bias-1
115   mov r2=0xfffe
117 {.mfi
118   nop.m 0
119   // y*y
120   fma.s1 f11=f9,f9,f0
121   nop.i 0;;
124 { .mfi
125      nop.m 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
129      nop.i 0
131 {.mfi
132   nop.m 0
133   // if possible overflow, copy f8 to f14
134   // set Denormal, if necessary
135   // (p8)
136   fma.s.s0 f14=f8,f1,f0
137   nop.i 0;;
140 { .mfi
141      nop.m 0
142 //   Check if y is an Inf - if so return Inf even
143 //   if x is a NaN (C9X)
144      fclass.m.unc p8, p9 = f9, 0x023
145          nop.i 0
147 { .mfi
148      nop.m 0
149 //   For x=inf, multiply y by 1 to raise invalid on y an SNaN
150 //   (p7) fma.s0 f9=f9,f1,f0
151      // copy f9 to f15; set Denormal, if necessary
152          fma.s.s0 f15=f9,f1,f0
153      nop.i 0;;
155 {.mfi
156   nop.m 0
157   // is y Zero ?
158   (p6) fclass.m p6,p0=f9,0x7
159   nop.i 0;;
161 {.mfi
162   nop.m 0
163   // is x Zero ?
164   (p9) fclass.m p9,p0=f8,0x7
165   nop.i 0;;
168 {.mfi
169   // f7=0.5
170   setf.exp f7=r2
171   // a=x2+y2
172   fma.s1 f12=f10,f1,f11
173   nop.i 0;;
176 {.mfi
177   nop.m 0
178   // x not NaN ?
179   (p6) fclass.m p7,p0=f8,0x3f
180   nop.i 0
182 {.mfi
183   // 2*emax-2
184   mov r2=0x100fb
185   // f6=2
186   fma.s1 f6=f1,f1,f1
187   nop.i 0;;
190 {.mfi
191   nop.m 0
192   // y not NaN ?
193   (p9) fclass.m p8,p0=f9,0x3f
194   nop.i 0;;
197 .pred.rel "mutex",p7,p8
198 {.mfb
199   nop.m 0
200   // if f8=Infinity or f9=Zero, return |f8|
201   (p7) fmerge.s f8=f0,f14
202   (p7) br.ret.spnt b0
204 {.mfb
205   nop.m 0
206   // if f9=Infinity or f8=Zero, return |f9|
207   (p8) fmerge.s f8=f0,f15
208   (p8) br.ret.spnt b0;;
211 { .mfi
212          nop.m 0
213 //   Identify Natvals, Infs, NaNs, and Zeros
214 //   and return result
215      fclass.m.unc p7, p0 = f12, 0x1E7
216      nop.i 0
218 {.mfi
219   nop.m 0
220   // z0=frsqrta(a)
221   frsqrta.s1 f8,p6=f12
222   nop.i 0;;
225 {.mfb
226   // get exponent of x^2+y^2
227   getf.exp r3=f12
228   // if special case, set f8
229   (p7) mov f8=f12
230   (p7) br.ret.spnt b0;;
234 {.mfi
235   nop.m 0
236   // S0=a*z0
237   (p6) fma.s1 f12=f12,f8,f0
238   nop.i 0
240 {.mfi
241   nop.m 0
242   // H0=0.5*z0
243   (p6) fma.s1 f10=f8,f7,f0
244   nop.i 0;;
248 {.mfi
249   nop.m 0
250   // f6=5/2
251   fma.s1 f6=f7,f1,f6
252   nop.i 0
254 {.mfi
255   nop.m 0
256   // f11=3/2
257   fma.s1 f11=f7,f1,f1
258   nop.i 0;;
261 {.mfi
262   nop.m 0
263   // d=0.5-S0*H0
264   (p6) fnma.s1 f7=f12,f10,f7
265   nop.i 0;;
268 {.mfi
269   nop.m 0
270   // P01=d+1
271   (p6) fma.s1 f10=f1,f7,f1
272   nop.i 0
274 {.mfi
275   nop.m 0
276   // P23=5/2*d+3/2
277   (p6) fma.s1 f11=f6,f7,f11
278   nop.i 0;;
280 {.mfi
281   nop.m 0
282   // d2=d*d
283   (p6) fma.s1 f7=f7,f7,f0
284   nop.i 0;;
288 {.mfi
289   // Is x^2 + y^2 well less than the overflow
290   // threshold?
291   (p6) cmp.lt.unc p7, p8 =  r3,r2
292   // P=P01+d2*P23
293   (p6) fma.s1 f10=f7,f11,f10
294   nop.i 0;;
297 {.mfb
298   nop.m 0
299   // S=P*S0
300   fma.s.s0 f8=f10,f12,f0
301   // No overflow in this case
302   (p7) br.ret.sptk b0;;
305 { .mfi
306      nop.m 0
307 (p8) fsetc.s2 0x7F,0x42
308      // Possible overflow path, must detect by
309      // Setting widest range exponent with prevailing
310      // rounding mode.
311      nop.i 0 ;;
315 { .mfi
316    // bias+0x400 (bias+EMAX+1)
317    (p8) mov r2=0x1007f
318    // S=P*S0
319    (p8) fma.s.s2 f12=f10,f12,f0
320    nop.i 0 ;;
322 { .mfi
323 (p8) setf.exp f11 = r2
324 (p8) fsetc.s2 0x7F,0x40
325 //   Restore Original Mode in S2
326      nop.i 0 ;;
328 { .mfi
329      nop.m 0
330 (p8) fcmp.lt.unc.s1 p9, p10 =  f12, f11
331      nop.i 0 ;;
333 { .mib
334      nop.m 0
335      mov GR_Parameter_TAG = 47
336          // No overflow
337 (p9) br.ret.sptk b0;;
339 GLOBAL_IEEE754_END(hypotf)
340 libm_alias_float_other (__hypot, hypot)
342 LOCAL_LIBM_ENTRY(__libm_error_region)
343 .prologue
344 { .mii
345         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
346         mov   GR_Parameter_TAG = 47
347 .save   ar.pfs,GR_SAVE_PFS
348         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
350 { .mfi
351 .fframe 64
352         add sp=-64,sp                           // Create new stack
353         nop.f 0
354         mov GR_SAVE_GP=gp                       // Save gp
356 { .mmi
357         stfs [GR_Parameter_Y] = FR_Y,16         // Store Parameter 2 on stack
358         add GR_Parameter_X = 16,sp              // Parameter 1 address
359 .save   b0, GR_SAVE_B0
360         mov GR_SAVE_B0=b0                       // Save b0
362 .body
363 { .mib
364         stfs [GR_Parameter_X] = FR_X            // Store Parameter 1 on stack
365         add   GR_Parameter_RESULT = 0,GR_Parameter_Y
366         nop.b 0                                 // Parameter 3 address
368 { .mib
369         stfs [GR_Parameter_Y] = FR_RESULT       // Store Parameter 3 on stack
370         add   GR_Parameter_Y = -16,GR_Parameter_Y
371         br.call.sptk b0=__libm_error_support#   // Call error handling function
373 { .mmi
374         nop.m 0
375         nop.m 0
376         add   GR_Parameter_RESULT = 48,sp
378 { .mmi
379         ldfs  f8 = [GR_Parameter_RESULT]       // Get return result off stack
380 .restore sp
381         add   sp = 64,sp                       // Restore stack pointer
382         mov   b0 = GR_SAVE_B0                  // Restore return address
384 { .mib
385         mov   gp = GR_SAVE_GP                  // Restore gp
386         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
387         br.ret.sptk     b0                     // Return
390 LOCAL_LIBM_END(__libm_error_region)
393 .type   __libm_error_support#,@function
394 .global __libm_error_support#