(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / sysdeps / ia64 / fpu / s_floorf.S
blob15b2bbd31d87986fcf4b67d9044e5a6aa82ebfac
1 .file "floorf.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 .align 32
41 .global floorf#
43 .section .text
44 .proc  floorf#
45 .align 32
47 // History
48 //==============================================================
49 // 2/02/00: Initial version
50 // 6/13/00: Improved speed
51 // 6/27/00: Eliminated incorrect invalid flag setting
52 // 2/07/01: Corrected sign of zero result in round to -inf mode
54 // API
55 //==============================================================
56 // float floorf(float x)
58 // general input registers:  
60 floor_GR_FFFF      = r14
61 floor_GR_signexp   = r15
62 floor_GR_exponent  = r16
63 floor_GR_expmask   = r17
64 floor_GR_bigexp    = r18
67 // predicate registers used: 
69 // p6  ==> Input is NaN, infinity, zero
70 // p7  ==> Input is denormal
71 // p8  ==> Input is <0
72 // p9  ==> Input is >=0
73 // p10 ==> Input is already an integer (bigger than largest integer)
74 // p11 ==> Input is not a large integer
75 // p12 ==> Input is a smaller integer
76 // p13 ==> Input is not an even integer, so inexact must be set
79 // floating-point registers used: 
81 FLOOR_NORM_f8      = f9                        
82 FLOOR_FFFF         = f10 
83 FLOOR_INEXACT      = f11 
84 FLOOR_FLOAT_INT_f8 = f12
85 FLOOR_INT_f8       = f13
86 FLOOR_adj          = f14
88 // Overview of operation
89 //==============================================================
91 // float floorf(float x)
92 // Return an integer value (represented as a float) that is the largest 
93 // value not greater than x
94 // This is x rounded toward -infinity to an integral value.
95 // Inexact is set if x != floorf(x)
96 // **************************************************************************
98 // Set denormal flag for denormal input and
99 // and take denormal fault if necessary.
101 // Is the input an integer value already?
103 // double_extended
104 // if the exponent is > 1003e => 3F(true) = 63(decimal)
105 // we have a significand of 64 bits 1.63-bits.
106 // If we multiply by 2^63, we no longer have a fractional part
107 // So input is an integer value already.
109 // double
110 // if the exponent is >= 10033 => 34(true) = 52(decimal)
111 // 34 + 3ff = 433
112 // we have a significand of 53 bits 1.52-bits. (implicit 1)
113 // If we multiply by 2^52, we no longer have a fractional part
114 // So input is an integer value already.
116 // single
117 // if the exponent is > 10016 => 17(true) = 23(decimal)
118 // we have a significand of 24 bits 1.23-bits. (implicit 1)
119 // If we multiply by 2^23, we no longer have a fractional part
120 // So input is an integer value already.
122 // If x is NAN, ZERO, or INFINITY, then  return
124 // qnan snan inf norm     unorm 0 -+
125 // 1    1    1   0        0     1 11     0xe7
127 #include "libm_support.h"
129 floorf:
130 #ifdef _LIBC
131 .global __floorf
132 __floorf:
133 #endif
135 { .mfi
136       getf.exp floor_GR_signexp  = f8
137       fcvt.fx.trunc.s1     FLOOR_INT_f8  = f8
138       addl        floor_GR_bigexp = 0x10016, r0
140 { .mfi
141       addl        floor_GR_FFFF      = -1,r0
142       fcmp.lt.s1  p8,p9 = f8,f0
143       mov         floor_GR_expmask    = 0x1FFFF ;;
146 // p7 ==> denorm
147 { .mfi
148       setf.sig    FLOOR_FFFF  = floor_GR_FFFF
149       fclass.m    p7,p0 = f8, 0x0b
150       nop.i 999
152 { .mfi
153       nop.m 999
154       fnorm.s1           FLOOR_NORM_f8  = f8
155       nop.i 999 ;;
158 // p6 ==> NAN, INF, ZERO
159 { .mfb
160       nop.m 999
161       fclass.m      p6,p10 = f8, 0xe7
162 (p7)  br.cond.spnt  L(FLOOR_DENORM) ;;
165 L(FLOOR_COMMON):
166 .pred.rel "mutex",p8,p9
167 // Set adjustment to subtract from trunc(x) for result
168 //   If x<0,  adjustment is -1.0
169 //   If x>=0, adjustment is 0.0
170 { .mfi
171       and      floor_GR_exponent = floor_GR_signexp, floor_GR_expmask
172 (p8)  fnma.s1  FLOOR_adj = f1,f1,f0
173       nop.i 999
175 { .mfi
176       nop.m 999
177 (p9)  fadd.s1  FLOOR_adj = f0,f0
178       nop.i 999 ;;
181 { .mfi
182       nop.m 999
183       fcmp.eq.s0  p12,p0 = f8,f0 // Dummy op to set denormal and invalid flag
184       nop.i 999
186 { .mfi
187 (p10) cmp.ge.unc    p10,p11 = floor_GR_exponent, floor_GR_bigexp
188 (p6)  fnorm.s f8 = f8
189       nop.i 999 ;;
192 { .mfi
193       nop.m 999
194 (p11) fcvt.xf         FLOOR_FLOAT_INT_f8   = FLOOR_INT_f8
195       nop.i 999 ;;
198 { .mfi
199       nop.m 999
200 (p10) fnorm.s f8 = FLOOR_NORM_f8
201       nop.i 999 ;;
204 { .mfi
205       nop.m 999
206 (p11) fadd.s   f8 = FLOOR_FLOAT_INT_f8,FLOOR_adj
207       nop.i 999 ;;
209 { .mfi
210       nop.m 999
211 (p11) fcmp.eq.unc.s1  p12,p13  = FLOOR_FLOAT_INT_f8, FLOOR_NORM_f8
212       nop.i 999 ;;
215 // Set inexact if result not equal to input
216 { .mfi
217       nop.m 999
218 (p13) fmpy.s0     FLOOR_INEXACT = FLOOR_FFFF,FLOOR_FFFF
219       nop.i 999
221 // Set result to input if integer
222 { .mfb
223       nop.m 999
224 (p12) fnorm.s f8 = FLOOR_NORM_f8
225       br.ret.sptk    b0 ;;
228 // Here if input denorm
229 L(FLOOR_DENORM):
230 { .mfb
231       getf.exp floor_GR_signexp  = FLOOR_NORM_f8
232       fcvt.fx.trunc.s1     FLOOR_INT_f8  = FLOOR_NORM_f8
233       br.cond.sptk  L(FLOOR_COMMON) ;;
236 .endp floorf
237 ASM_SIZE_DIRECTIVE(floorf)