Remove support in configure for unsupported architectures
[glibc.git] / sysdeps / ia64 / fpu / s_nextafterl.S
blob20c927b1cc6878500e3a2d1472a559c80e035fad
1 .file "nextafterl.s"
4 // Copyright (c) 2000 - 2004, Intel Corporation
5 // All rights reserved.
6 //
7 // Contributed 2000 by the Intel Numerics Group, 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://www.intel.com/software/products/opensource/libraries/num.htm.
40 // History
41 //==============================================================
42 // 02/02/00 Initial version 
43 // 03/03/00 Modified to conform to C9X, and improve speed of main path
44 // 03/14/00 Fixed case where x is a power of 2, and x > y, improved speed
45 // 04/04/00 Unwind support added
46 // 05/12/00 Fixed erroneous denormal flag setting for exponent change cases 1,3
47 // 08/15/00 Bundle added after call to __libm_error_support to properly
48 //          set [the previously overwritten] GR_Parameter_RESULT.
49 // 09/09/00 Updated fcmp so that qnans do not raise invalid.
50 // 12/15/00 Fixed case of smallest long double normal to largest denormal,
51 //          now adhere to C99 for two zero args, and fixed flag settings 
52 //          for several cases
53 // 05/20/02 Cleaned up namespace and sf0 syntax
54 // 02/10/03 Reordered header: .section, .global, .proc, .align
55 // 12/14/04 Added error handling on underflow.
57 // API
58 //==============================================================
59 // long double nextafterl( long double x, long double y );
60 // input  floating point f8, f9
61 // output floating point f8
63 // Registers used
64 //==============================================================
65 GR_max_pexp     = r14
66 GR_min_pexp     = r15
67 GR_exp          = r16
68 GR_sig          = r17
69 GR_lnorm_sig    = r18
70 GR_sign_mask    = r19
71 GR_exp_mask     = r20
72 GR_sden_sig     = r21
73 GR_new_sig      = r22
74 GR_new_exp      = r23
75 GR_lden_sig     = r24
76 GR_snorm_sig    = r25
77 GR_exp1         = r26
78 GR_x_exp        = r27
79 // r36-39 parameters for libm_error_support
81 GR_SAVE_B0                = r34
82 GR_SAVE_GP                = r35
83 GR_SAVE_PFS               = r32
85 GR_Parameter_X            = r36
86 GR_Parameter_Y            = r37
87 GR_Parameter_RESULT       = r38
88 GR_Parameter_TAG          = r39
90 FR_lnorm_sig       = f10
91 FR_lnorm_exp       = f11
92 FR_lnorm           = f12
93 FR_sden_sig        = f13
94 FR_den_exp         = f14
95 FR_sden            = f15
96 FR_snorm_exp       = f32
97 FR_save_f8         = f33
98 FR_new_exp         = f34
99 FR_new_sig         = f35
100 FR_lden_sig        = f36
101 FR_snorm_sig       = f37
102 FR_exp1            = f38
103 FR_tmp             = f39
106 // Overview of operation
107 //==============================================================
108 // nextafterl determines the next representable value 
109 // after x in the direction of y. 
112 .section .text
113 GLOBAL_LIBM_ENTRY(nextafterl)
115 // Extract signexp from x
116 // Is x < y ?  p10 if yes, p11 if no
117 // Form smallest denormal significand = ulp size
118 { .mfi
119       getf.exp GR_exp      = f8
120       fcmp.lt.s1 p10,p11 = f8, f9                
121       addl GR_sden_sig = 0x1, r0
123 // Form largest normal significand 0xffffffffffffffff
124 // Form smallest normal exponent
125 { .mfi
126       addl GR_lnorm_sig = -0x1,r0
127       nop.f 999
128       addl GR_min_pexp = 0x0c001, r0 ;;
131 // Extract significand from x
132 // Is x=y?   This fcmp also sets Invalid and Denormal if required
133 // Form largest normal exponent
134 { .mfi
135       getf.sig GR_sig      = f8
136       fcmp.eq.s0 p6,p0 = f8, f9
137       addl GR_max_pexp = 0x13ffe, r0
139 // Move largest normal significand to fp reg for special cases
140 { .mfi
141       setf.sig FR_lnorm_sig = GR_lnorm_sig
142       nop.f 999
143       addl GR_sign_mask = 0x20000, r0 ;;
146 // Move smallest denormal significand and exp to fp regs
147 // Is x=nan?
148 // Set p12 and p13 based on whether significand increases or decreases
149 // It increases (p12 set) if x<y and x>=0 or if x>y and x<0
150 // It decreases (p13 set) if x<y and x<0  or if x>y and x>=0
151 { .mfi
152       setf.sig FR_sden_sig = GR_sden_sig
153       fclass.m  p8,p0 = f8, 0xc3           
154 (p10) cmp.lt p12,p13 = GR_exp, GR_sign_mask
156 // Move smallest normal exp to fp regs
157 { .mfi
158       setf.exp FR_snorm_exp = GR_min_pexp
159       nop.f 999
160 (p11) cmp.ge p12,p13 = GR_exp, GR_sign_mask ;;
163 .pred.rel "mutex",p12,p13
165 // Form expected new significand, adding or subtracting 1 ulp increment
166 // If x=y set result to y
167 // Form smallest normal significand and largest denormal significand
168 { .mfi
169 (p12) add GR_new_sig = GR_sig, GR_sden_sig
170 (p6)  fmerge.s f8=f9,f9
171       dep.z GR_snorm_sig = 1,63,1 // 0x8000000000000000
173 { .mlx
174 (p13) sub GR_new_sig = GR_sig, GR_sden_sig
175       movl GR_lden_sig = 0x7fffffffffffffff ;;
178 // Move expected result significand and signexp to fp regs
179 // Is y=nan?
180 // Form new exponent in case result exponent needs incrementing or decrementing
181 { .mfi
182       setf.exp FR_new_exp = GR_exp
183       fclass.m  p9,p0 = f9, 0xc3           
184 (p12) add GR_exp1 = 1, GR_exp
186 { .mib
187       setf.sig FR_new_sig = GR_new_sig
188 (p13) add GR_exp1 = -1, GR_exp
189 (p6)  br.ret.spnt    b0 ;;             // Exit if x=y
192 // Move largest normal signexp to fp reg for special cases
193 // Is x=zero?
194 { .mfi
195       setf.exp FR_lnorm_exp = GR_max_pexp
196       fclass.m  p7,p0 = f8, 0x7
197       nop.i 999
199 { .mfb
200       setf.exp FR_den_exp = GR_min_pexp
201 (p8)  fma.s0 f8 = f8,f1,f9                     
202 (p8)  br.ret.spnt    b0 ;;             // Exit if x=nan
205 // Move exp+-1 and smallest normal significand to fp regs for special cases
206 // Is x=inf?
207 { .mfi
208       setf.exp FR_exp1 = GR_exp1
209       fclass.m  p6,p0 = f8, 0x23           
210       addl GR_exp_mask = 0x1ffff, r0
212 { .mfb
213       setf.sig FR_snorm_sig = GR_snorm_sig
214 (p9)  fma.s0 f8 = f8,f1,f9                     
215 (p9)  br.ret.spnt    b0 ;;             // Exit if y=nan
218 // Move largest denormal significand to fp regs for special cases
219 // Save x
220 { .mfb
221       setf.sig FR_lden_sig = GR_lden_sig
222       mov FR_save_f8 = f8
223 (p7)  br.cond.spnt NEXT_ZERO ;;   // Exit if x=0   
226 // Mask off the sign to get x_exp
227 { .mfb
228       and GR_x_exp = GR_exp_mask, GR_exp
229       nop.f 999
230 (p6)  br.cond.spnt NEXT_INF ;;   // Exit if x=inf   
233 // Check 5 special cases when significand rolls over:
234 //  1 sig size incr, x_sig=max_sig, x_exp < max_exp
235 //     Set p6, result is sig=min_sig, exp++
236 //  2 sig size incr, x_sig=max_sig, x_exp >= max_exp
237 //     Set p7, result is inf, signal overflow
238 //  3 sig size decr, x_sig=min_sig, x_exp > min_exp
239 //     Set p8, result is sig=max_sig, exp--
240 //  4 sig size decr, x_sig=min_sig, x_exp = min_exp
241 //     Set p9, result is sig=max_den_sig, exp same, signal underflow and inexact
242 //  5 sig size decr, x_sig=min_den_sig, x_exp = min_exp
243 //     Set p10, result is zero, sign of x, signal underflow and inexact
245 { .mmi
246 (p12) cmp.eq.unc p6,p0 = GR_new_sig, r0
247 (p13) cmp.eq.unc p9,p10 = GR_new_sig, GR_lden_sig
248       nop.i 999
252 { .mmi
253 (p6)  cmp.lt.unc p6,p7 = GR_x_exp, GR_max_pexp
254 (p10) cmp.eq.unc p10,p0 = GR_new_sig, r0
255 (p9)  cmp.le.unc p9,p8 = GR_x_exp, GR_min_pexp 
259 // Create small normal in case need to generate underflow flag
260 { .mfi
261       nop.m 999
262       fmerge.se FR_tmp = FR_snorm_exp, FR_lnorm_sig
263       nop.i 999
265 // Branch if cases 1, 2, 3
266 { .bbb
267 (p6)  br.cond.spnt NEXT_EXPUP
268 (p7)  br.cond.spnt NEXT_OVERFLOW
269 (p8)  br.cond.spnt NEXT_EXPDOWN ;;
272 // Branch if cases 4, 5
273 { .mbb
274       nop.m 999
275 (p9)  br.cond.spnt NEXT_NORM_TO_DENORM
276 (p10) br.cond.spnt NEXT_UNDERFLOW_TO_ZERO
280 // Here if no special cases
281 // Set p6 if result will be a denormal, so can force underflow flag
282 //    Case 1:  x_exp=min_exp, x_sig=unnormalized
283 //    Case 2:  x_exp<min_exp
284 { .mfi
285       cmp.lt p6,p7 = GR_x_exp, GR_min_pexp
286       fmerge.se f8 = FR_new_exp, FR_new_sig
287       nop.i 999 ;;
290 { .mfi
291       nop.m 999
292       nop.f 999
293 (p6)  tbit.z p6,p0 = GR_new_sig, 63 ;;
296 NEXT_COMMON_FINISH:
297 // Force underflow and inexact if denormal result
298 { .mfi
299       nop.m 999
300 (p6)  fma.s0 FR_tmp = FR_tmp,FR_tmp,f0
301       nop.i 999
303 { .mfb
304       nop.m 999
305       fnorm.s0 f8 = f8 // Final normalization to result precision
306 (p6)  br.cond.spnt NEXT_UNDERFLOW ;;
309 { .mfb
310       nop.m 999
311       nop.f 999
312       br.ret.sptk b0;;
315 //Special cases
316 NEXT_EXPUP:
317 { .mfb
318       cmp.lt p6,p7 = GR_x_exp, GR_min_pexp
319       fmerge.se f8 = FR_exp1, FR_snorm_sig
320       br.cond.sptk NEXT_COMMON_FINISH ;;
323 NEXT_EXPDOWN:
324 { .mfb
325       cmp.lt p6,p7 = GR_x_exp, GR_min_pexp
326       fmerge.se f8 = FR_exp1, FR_lnorm_sig
327       br.cond.sptk NEXT_COMMON_FINISH ;;
330 NEXT_NORM_TO_DENORM:
331 { .mfi
332       nop.m 999
333       fmerge.se f8 = FR_exp1, FR_lden_sig
334       nop.i 999
336 // Force underflow and inexact
337 { .mfb
338       nop.m 999
339       fma.s0 FR_tmp = FR_tmp,FR_tmp,f0
340       br.cond.sptk NEXT_UNDERFLOW ;;
343 NEXT_UNDERFLOW_TO_ZERO:
344 { .mfb
345       cmp.eq p6,p0 = r0,r0
346       fmerge.s f8 = FR_save_f8,f0
347       br.cond.sptk NEXT_COMMON_FINISH ;;
350 NEXT_INF: 
351 // Here if f8 is +- infinity
352 // INF
353 // if f8 is +inf, no matter what y is return  largest long double
354 // if f8 is -inf, no matter what y is return -largest long double
356 // Create largest long double
357 { .mfi
358       nop.m 999
359       fmerge.se FR_lnorm = FR_lnorm_exp,FR_lnorm_sig
360       nop.i 999 ;;
363 { .mfb
364       nop.m 999
365       fmerge.s f8 = f8,FR_lnorm                
366       br.ret.sptk    b0 ;;                        
369 NEXT_ZERO: 
371 // Here if f8 is +- zero
372 // ZERO
373 // if f8 is zero and y is +, return + smallest long double denormal 
374 // if f8 is zero and y is -, return - smallest long double denormal 
376 { .mfi
377       nop.m 999
378       fmerge.se FR_sden = f0,FR_sden_sig
379       nop.i 999 ;;
382 // Create small normal to generate underflow flag
383 { .mfi
384       nop.m 999
385       fmerge.se FR_tmp = FR_snorm_exp, FR_lnorm_sig
386       nop.i 999 ;;
389 // Add correct sign from direction arg
390 { .mfi
391       nop.m 999
392       fmerge.s f8 = f9,FR_sden                
393       nop.i 999 ;;
396 // Force underflow and inexact flags
397 { .mfb
398       nop.m 999
399       fma.s0 FR_tmp = FR_tmp,FR_tmp,f0
400       br.cond.sptk NEXT_UNDERFLOW ;;
403 NEXT_UNDERFLOW: 
404 // Here if result is a denorm, or input is finite and result is zero
405 // Call error support to report possible range error
406 { .mib
407       alloc          r32=ar.pfs,2,2,4,0
408       mov           GR_Parameter_TAG = 267      // Error code
409       br.cond.sptk  __libm_error_region    // Branch to error call
413 NEXT_OVERFLOW: 
414 // Here if input is finite, but result will be infinite
415 // Use frcpa to generate infinity of correct sign
416 // Call error support to report possible range error
417 { .mfi
418       alloc          r32=ar.pfs,2,2,4,0
419       frcpa.s1 f8,p6 = FR_save_f8, f0
420       nop.i 999 ;;
423 // Create largest double
424 { .mfi
425       nop.m 999
426       fmerge.se FR_lnorm = FR_lnorm_exp,FR_lnorm_sig
427       nop.i 999 ;;
430 // Force overflow and inexact flags to be set
431 { .mfb
432       mov           GR_Parameter_TAG = 153      // Error code
433       fma.s0 FR_tmp = FR_lnorm,FR_lnorm,f0
434       br.cond.sptk  __libm_error_region    // Branch to error call
438 GLOBAL_LIBM_END(nextafterl)
441 LOCAL_LIBM_ENTRY(__libm_error_region)
442 .prologue
444 // (1)
445 { .mfi
446         add   GR_Parameter_Y=-32,sp             // Parameter 2 value
447         nop.f 0
448 .save   ar.pfs,GR_SAVE_PFS
449         mov  GR_SAVE_PFS=ar.pfs                 // Save ar.pfs
451 { .mfi
452 .fframe 64
453         add sp=-64,sp                          // Create new stack
454         nop.f 0
455         mov GR_SAVE_GP=gp                      // Save gp
459 // (2)
460 { .mmi
461         stfe [GR_Parameter_Y] = f9,16         // STORE Parameter 2 on stack
462         add GR_Parameter_X = 16,sp            // Parameter 1 address
463 .save   b0, GR_SAVE_B0
464         mov GR_SAVE_B0=b0                     // Save b0
467 .body
468 // (3)
469 { .mib
470         stfe [GR_Parameter_X] = FR_save_f8              // STORE Parameter 1 on stack
471         add   GR_Parameter_RESULT = 0,GR_Parameter_Y           // Parameter 3 address
472         nop.b 0                                
474 { .mib
475         stfe [GR_Parameter_Y] = f8              // STORE Parameter 3 on stack
476         add   GR_Parameter_Y = -16,GR_Parameter_Y
477         br.call.sptk b0=__libm_error_support#   // Call error handling function
479 { .mmi
480         nop.m 0
481         nop.m 0
482         add   GR_Parameter_RESULT = 48,sp
485 // (4)
486 { .mmi
487         ldfe  f8 = [GR_Parameter_RESULT]       // Get return result off stack
488 .restore sp
489         add   sp = 64,sp                       // Restore stack pointer
490         mov   b0 = GR_SAVE_B0                  // Restore return address
492 { .mib
493         mov   gp = GR_SAVE_GP                  // Restore gp
494         mov   ar.pfs = GR_SAVE_PFS             // Restore ar.pfs
495         br.ret.sptk     b0                     // Return
498 LOCAL_LIBM_END(__libm_error_region)
501 .type   __libm_error_support#,@function
502 .global __libm_error_support#