1.file "hypotf.s"
2
3
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:
11//
12// * Redistributions of source code must retain the above copyright
13// notice, this list of conditions and the following disclaimer.
14//
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.
18//
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.
22
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.
34//
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.
38//
39//*********************************************************************
40//
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
50//
51//*********************************************************************
52//                           ___________
53// Function:   hypotf(x,y) = |(x^2 + y^2) = for single precision values
54//             x and y
55//             Also provides cabsf functionality.
56//
57//*********************************************************************
58//
59// Resources Used:
60//
61//    Floating-Point Registers: f8  (Input and Return Value)
62//                              f9  (Input)
63//                              f6 -f15
64//
65//    General Purpose Registers:
66//      r2-r3   (Scratch)
67//      r32-r36 (Locals)
68//      r37-r40 (Used to pass arguments to error handling routine)
69//
70//    Predicate Registers:      p6 - p10
71//
72//*********************************************************************
73//
74// IEEE Special Conditions:
75//
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
81//
82//*********************************************************************
83//
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
89//
90//*********************************************************************
91
92GR_SAVE_PFS         = r33
93GR_SAVE_B0          = r34
94GR_SAVE_GP          = r35
95GR_Parameter_X      = r36
96GR_Parameter_Y      = r37
97GR_Parameter_RESULT = r38
98GR_Parameter_TAG    = r39
99
100FR_X                = f14
101FR_Y                = f15
102FR_RESULT           = f8
103
104.section .text
105
106LOCAL_LIBM_ENTRY(cabsf)
107LOCAL_LIBM_END(cabsf)
108
109GLOBAL_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
116}
117{.mfi
118  nop.m 0
119  // y*y
120  fma.s1 f11=f9,f9,f0
121  nop.i 0;;
122}
123
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
130}
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;;
138}
139
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
146}
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;;
154}
155{.mfi
156  nop.m 0
157  // is y Zero ?
158  (p6) fclass.m p6,p0=f9,0x7
159  nop.i 0;;
160}
161{.mfi
162  nop.m 0
163  // is x Zero ?
164  (p9) fclass.m p9,p0=f8,0x7
165  nop.i 0;;
166}
167
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;;
174}
175
176{.mfi
177  nop.m 0
178  // x not NaN ?
179  (p6) fclass.m p7,p0=f8,0x3f
180  nop.i 0
181}
182{.mfi
183  // 2*emax-2
184  mov r2=0x100fb
185  // f6=2
186  fma.s1 f6=f1,f1,f1
187  nop.i 0;;
188}
189
190{.mfi
191  nop.m 0
192  // y not NaN ?
193  (p9) fclass.m p8,p0=f9,0x3f
194  nop.i 0;;
195}
196
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
203}
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;;
209}
210
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
217}
218{.mfi
219  nop.m 0
220  // z0=frsqrta(a)
221  frsqrta.s1 f8,p6=f12
222  nop.i 0;;
223}
224
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;;
231}
232
233
234{.mfi
235  nop.m 0
236  // S0=a*z0
237  (p6) fma.s1 f12=f12,f8,f0
238  nop.i 0
239}
240{.mfi
241  nop.m 0
242  // H0=0.5*z0
243  (p6) fma.s1 f10=f8,f7,f0
244  nop.i 0;;
245}
246
247
248{.mfi
249  nop.m 0
250  // f6=5/2
251  fma.s1 f6=f7,f1,f6
252  nop.i 0
253}
254{.mfi
255  nop.m 0
256  // f11=3/2
257  fma.s1 f11=f7,f1,f1
258  nop.i 0;;
259}
260
261{.mfi
262  nop.m 0
263  // d=0.5-S0*H0
264  (p6) fnma.s1 f7=f12,f10,f7
265  nop.i 0;;
266}
267
268{.mfi
269  nop.m 0
270  // P01=d+1
271  (p6) fma.s1 f10=f1,f7,f1
272  nop.i 0
273}
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;;
279}
280{.mfi
281  nop.m 0
282  // d2=d*d
283  (p6) fma.s1 f7=f7,f7,f0
284  nop.i 0;;
285}
286
287
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;;
295}
296
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;;
303}
304
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 ;;
312}
313
314
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 ;;
321}
322{ .mfi
323(p8) setf.exp f11 = r2
324(p8) fsetc.s2 0x7F,0x40
325//   Restore Original Mode in S2
326     nop.i 0 ;;
327}
328{ .mfi
329     nop.m 0
330(p8) fcmp.lt.unc.s1 p9, p10 =  f12, f11
331     nop.i 0 ;;
332}
333{ .mib
334     nop.m 0
335     mov GR_Parameter_TAG = 47
336	 // No overflow
337(p9) br.ret.sptk b0;;
338}
339GLOBAL_IEEE754_END(hypotf)
340libm_alias_float_other (__hypot, hypot)
341
342LOCAL_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
349}
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
355};;
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
361};;
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
367}
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
372};;
373{ .mmi
374        nop.m 0
375        nop.m 0
376        add   GR_Parameter_RESULT = 48,sp
377};;
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
383};;
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
388};;
389
390LOCAL_LIBM_END(__libm_error_region)
391
392
393.type   __libm_error_support#,@function
394.global __libm_error_support#
395