]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/ia64/fpu/s_floor.S
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / ia64 / fpu / s_floor.S
CommitLineData
8da2915d
UD
1.file "floor.s"
2
a334319f 3// Copyright (C) 2000, 2001, Intel Corporation
8da2915d 4// All rights reserved.
a334319f
UD
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.
aeb25823
AJ
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:
12//
13// * Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//
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.
19//
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.
a334319f
UD
23//
24// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
8da2915d 26// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
a334319f 27// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
8da2915d 28// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
a334319f
UD
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
8da2915d 32// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
a334319f
UD
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//
8da2915d 36// Intel Corporation is the author of this code, and requests that all
a334319f
UD
37// problem reports or change requests be submitted to it directly at
38// http://developer.intel.com/opensource.
8da2915d 39//
a334319f
UD
40.align 32
41.global floor#
42
43.section .text
44.proc floor#
45.align 32
46
8da2915d
UD
47// History
48//==============================================================
a334319f
UD
49// 2/02/00: Initial version
50// 3/22/00: Updated to improve performance
51// 6/13/00: Improved speed, fixed setting of inexact flag
52// 6/27/00: Eliminated incorrect invalid flag setting
53// 2/07/01: Corrected sign of zero result in round to -inf mode
8da2915d
UD
54
55// API
56//==============================================================
57// double floor(double x)
58
a334319f
UD
59// general input registers:
60
61floor_GR_FFFF = r14
62floor_GR_signexp = r15
63floor_GR_exponent = r16
64floor_GR_expmask = r17
65floor_GR_bigexp = r18
66
8da2915d 67
a334319f 68// predicate registers used:
8da2915d 69
a334319f
UD
70// p6 ==> Input is NaN, infinity, zero
71// p7 ==> Input is denormal
72// p8 ==> Input is <0
73// p9 ==> Input is >=0
74// p10 ==> Input is already an integer (bigger than largest integer)
75// p11 ==> Input is not a large integer
76// p12 ==> Input is a smaller integer
77// p13 ==> Input is not an even integer, so inexact must be set
8da2915d 78
8da2915d 79
a334319f
UD
80// floating-point registers used:
81
82FLOOR_NORM_f8 = f9
83FLOOR_FFFF = f10
84FLOOR_INEXACT = f11
85FLOOR_FLOAT_INT_f8 = f12
86FLOOR_INT_f8 = f13
87FLOOR_adj = f14
8da2915d
UD
88
89// Overview of operation
90//==============================================================
a334319f 91
8da2915d 92// double floor(double x)
a334319f 93// Return an integer value (represented as a double) that is the largest
8da2915d
UD
94// value not greater than x
95// This is x rounded toward -infinity to an integral value.
96// Inexact is set if x != floor(x)
a334319f
UD
97// **************************************************************************
98
99// Set denormal flag for denormal input and
100// and take denormal fault if necessary.
101
102// Is the input an integer value already?
8da2915d
UD
103
104// double_extended
105// if the exponent is > 1003e => 3F(true) = 63(decimal)
106// we have a significand of 64 bits 1.63-bits.
107// If we multiply by 2^63, we no longer have a fractional part
108// So input is an integer value already.
109
110// double
111// if the exponent is >= 10033 => 34(true) = 52(decimal)
112// 34 + 3ff = 433
113// we have a significand of 53 bits 1.52-bits. (implicit 1)
114// If we multiply by 2^52, we no longer have a fractional part
115// So input is an integer value already.
116
117// single
118// if the exponent is > 10016 => 17(true) = 23(decimal)
119// we have a significand of 24 bits 1.23-bits. (implicit 1)
120// If we multiply by 2^23, we no longer have a fractional part
121// So input is an integer value already.
122
a334319f 123// If x is NAN, ZERO, or INFINITY, then return
8da2915d 124
a334319f
UD
125// qnan snan inf norm unorm 0 -+
126// 1 1 1 0 0 1 11 0xe7
127
128#include "libm_support.h"
129
130floor:
131#ifdef _LIBC
132.global __floor
133__floor:
134#endif
8da2915d
UD
135
136{ .mfi
a334319f
UD
137 getf.exp floor_GR_signexp = f8
138 fcvt.fx.trunc.s1 FLOOR_INT_f8 = f8
139 addl floor_GR_bigexp = 0x10033, r0
8da2915d
UD
140}
141{ .mfi
a334319f
UD
142 addl floor_GR_FFFF = -1,r0
143 fcmp.lt.s1 p8,p9 = f8,f0
144 mov floor_GR_expmask = 0x1FFFF ;;
8da2915d
UD
145}
146
a334319f 147// p7 ==> denorm
8da2915d 148{ .mfi
a334319f
UD
149 setf.sig FLOOR_FFFF = floor_GR_FFFF
150 fclass.m p7,p0 = f8, 0x0b
151 nop.i 999
8da2915d 152}
a334319f
UD
153{ .mfi
154 nop.m 999
155 fnorm.s1 FLOOR_NORM_f8 = f8
156 nop.i 999 ;;
8da2915d
UD
157}
158
a334319f
UD
159// p6 ==> NAN, INF, ZERO
160{ .mfb
161 nop.m 999
162 fclass.m p6,p10 = f8, 0xe7
163(p7) br.cond.spnt L(FLOOR_DENORM) ;;
8da2915d
UD
164}
165
a334319f 166L(FLOOR_COMMON):
8da2915d 167.pred.rel "mutex",p8,p9
a334319f
UD
168// Set adjustment to subtract from trunc(x) for result
169// If x<0, adjustment is -1.0
170// If x>=0, adjustment is 0.0
8da2915d 171{ .mfi
a334319f
UD
172 and floor_GR_exponent = floor_GR_signexp, floor_GR_expmask
173(p8) fnma.s1 FLOOR_adj = f1,f1,f0
174 nop.i 999
8da2915d
UD
175}
176{ .mfi
a334319f
UD
177 nop.m 999
178(p9) fadd.s1 FLOOR_adj = f0,f0
179 nop.i 999 ;;
8da2915d
UD
180}
181
182{ .mfi
a334319f
UD
183 nop.m 999
184 fcmp.eq.s0 p12,p0 = f8,f0 // Dummy op to set denormal and invalid flag
185 nop.i 999
8da2915d 186}
a334319f
UD
187{ .mfi
188(p10) cmp.ge.unc p10,p11 = floor_GR_exponent, floor_GR_bigexp
189(p6) fnorm.d f8 = f8
190 nop.i 999 ;;
8da2915d
UD
191}
192
a334319f
UD
193{ .mfi
194 nop.m 999
195(p11) fcvt.xf FLOOR_FLOAT_INT_f8 = FLOOR_INT_f8
196 nop.i 999 ;;
8da2915d
UD
197}
198
199{ .mfi
a334319f
UD
200 nop.m 999
201(p10) fnorm.d f8 = FLOOR_NORM_f8
202 nop.i 999 ;;
8da2915d 203}
a334319f
UD
204
205
8da2915d 206{ .mfi
a334319f
UD
207 nop.m 999
208(p11) fadd.d f8 = FLOOR_FLOAT_INT_f8,FLOOR_adj
209 nop.i 999 ;;
8da2915d
UD
210}
211
212{ .mfi
a334319f
UD
213 nop.m 999
214(p11) fcmp.eq.unc.s1 p12,p13 = FLOOR_FLOAT_INT_f8, FLOOR_NORM_f8
215 nop.i 999 ;;
8da2915d
UD
216}
217
a334319f 218// Set inexact if result not equal to input
8da2915d 219{ .mfi
a334319f
UD
220 nop.m 999
221(p13) fmpy.s0 FLOOR_INEXACT = FLOOR_FFFF,FLOOR_FFFF
222 nop.i 999
8da2915d 223}
a334319f 224// Set result to input if integer
8da2915d 225{ .mfb
a334319f
UD
226 nop.m 999
227(p12) fnorm.d f8 = FLOOR_NORM_f8
228 br.ret.sptk b0 ;;
8da2915d
UD
229}
230
a334319f
UD
231// Here if input denorm
232L(FLOOR_DENORM):
8da2915d 233{ .mfb
a334319f
UD
234 getf.exp floor_GR_signexp = FLOOR_NORM_f8
235 fcvt.fx.trunc.s1 FLOOR_INT_f8 = FLOOR_NORM_f8
236 br.cond.sptk L(FLOOR_COMMON) ;;
8da2915d
UD
237}
238
a334319f
UD
239.endp floor
240ASM_SIZE_DIRECTIVE(floor)