3 // Copyright (C) 2000, 2001, Intel Corporation
4 // All rights reserved.
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.
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are
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
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.
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.
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
55 //==============================================================
56 // long double floorl(long double x)
58 // general input registers:
61 floor_GR_signexp = r15
62 floor_GR_exponent = r16
63 floor_GR_expmask = r17
67 // predicate registers used:
69 // p6 ==> Input is NaN, infinity, zero
70 // p7 ==> Input is denormal
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:
84 FLOOR_FLOAT_INT_f8 = f12
88 // Overview of operation
89 //==============================================================
91 // long double floorl(long double x)
92 // Return an integer value (represented as a long double) 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 != floorl(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?
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.
110 // if the exponent is >= 10033 => 34(true) = 52(decimal)
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.
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"
136 getf.exp floor_GR_signexp = f8
137 fcvt.fx.trunc.s1 FLOOR_INT_f8 = f8
138 addl floor_GR_bigexp = 0x1003e, r0
141 addl floor_GR_FFFF = -1,r0
142 fcmp.lt.s1 p8,p9 = f8,f0
143 mov floor_GR_expmask = 0x1FFFF ;;
148 setf.sig FLOOR_FFFF = floor_GR_FFFF
149 fclass.m p7,p0 = f8, 0x0b
154 fnorm.s1 FLOOR_NORM_f8 = f8
158 // p6 ==> NAN, INF, ZERO
161 fclass.m p6,p10 = f8, 0xe7
162 (p7) br.cond.spnt L(FLOOR_DENORM) ;;
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
171 and floor_GR_exponent = floor_GR_signexp, floor_GR_expmask
172 (p8) fnma.s1 FLOOR_adj = f1,f1,f0
177 (p9) fadd.s1 FLOOR_adj = f0,f0
183 fcmp.eq.s0 p12,p0 = f8,f0 // Dummy op to set denormal and invalid flag
187 (p10) cmp.ge.unc p10,p11 = floor_GR_exponent, floor_GR_bigexp
194 (p11) fcvt.xf FLOOR_FLOAT_INT_f8 = FLOOR_INT_f8
200 (p10) fnorm f8 = FLOOR_NORM_f8
206 (p11) fadd f8 = FLOOR_FLOAT_INT_f8,FLOOR_adj
211 (p11) fcmp.eq.unc.s1 p12,p13 = FLOOR_FLOAT_INT_f8, FLOOR_NORM_f8
215 // Set inexact if result not equal to input
218 (p13) fmpy.s0 FLOOR_INEXACT = FLOOR_FFFF,FLOOR_FFFF
221 // Set result to input if integer
224 (p12) fnorm f8 = FLOOR_NORM_f8
228 // Here if input denorm
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) ;;
237 ASM_SIZE_DIRECTIVE(floorl)