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.
11 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
14 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
15 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
17 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
18 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
19 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
20 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 // Intel Corporation is the author of this code, and requests that all
24 // problem reports or change requests be submitted to it directly at
25 // http://developer.intel.com/opensource.
28 #include "libm_support.h"
38 //==============================================================
39 // 2/02/00: Initial version
40 // 6/13/00: Improved speed
41 // 6/27/00: Eliminated incorrect invalid flag setting
44 //==============================================================
45 // double ceil(double x)
47 // general input registers:
51 ceil_GR_exponent = r16
56 // predicate registers used:
58 // p6 ==> Input is NaN, infinity, zero
59 // p7 ==> Input is denormal
61 // p9 ==> Input is >=0
62 // p10 ==> Input is already an integer (bigger than largest integer)
63 // p11 ==> Input is not a large integer
64 // p12 ==> Input is a smaller integer
65 // p13 ==> Input is not an even integer, so inexact must be set
66 // p14 ==> Input is between -1 and 0, so result will be -0 and inexact
69 // floating-point registers used:
75 CEIL_FLOAT_INT_f8 = f12
80 // Overview of operation
81 //==============================================================
83 // double ceil(double x)
84 // Return an integer value (represented as a double) that is the smallest
85 // value not less than x
86 // This is x rounded toward +infinity to an integral value.
87 // Inexact is set if x != ceil(x)
88 // **************************************************************************
90 // Set denormal flag for denormal input and
91 // and take denormal fault if necessary.
93 // Is the input an integer value already?
96 // if the exponent is > 1003e => 3F(true) = 63(decimal)
97 // we have a significand of 64 bits 1.63-bits.
98 // If we multiply by 2^63, we no longer have a fractional part
99 // So input is an integer value already.
102 // if the exponent is >= 10033 => 34(true) = 52(decimal)
104 // we have a significand of 53 bits 1.52-bits. (implicit 1)
105 // If we multiply by 2^52, we no longer have a fractional part
106 // So input is an integer value already.
109 // if the exponent is > 10016 => 17(true) = 23(decimal)
110 // we have a significand of 24 bits 1.23-bits. (implicit 1)
111 // If we multiply by 2^23, we no longer have a fractional part
112 // So input is an integer value already.
114 // If x is NAN, ZERO, or INFINITY, then return
116 // qnan snan inf norm unorm 0 -+
117 // 1 1 1 0 0 1 11 0xe7
123 getf.exp ceil_GR_signexp = f8
124 fcvt.fx.trunc.s1 CEIL_INT_f8 = f8
125 addl ceil_GR_bigexp = 0x10033, r0
128 addl ceil_GR_FFFF = -1,r0
129 fcmp.lt.s1 p8,p9 = f8,f0
130 mov ceil_GR_expmask = 0x1FFFF ;;
135 setf.sig CEIL_FFFF = ceil_GR_FFFF
136 fclass.m p7,p0 = f8, 0x0b
141 fnorm CEIL_NORM_f8 = f8
145 // Form 0 with sign of input in case negative zero is needed
148 fmerge.s CEIL_SIGNED_ZERO = f8, f0
153 fsub.s1 CEIL_MINUS_ONE = f0, f1
157 // p6 ==> NAN, INF, ZERO
160 fclass.m p6,p10 = f8, 0xe7
161 (p7) br.cond.spnt L(CEIL_DENORM) ;;
165 .pred.rel "mutex",p8,p9
166 // Set adjustment to add to trunc(x) for result
167 // If x>0, adjustment is 1.0
168 // If x<=0, adjustment is 0.0
170 and ceil_GR_exponent = ceil_GR_signexp, ceil_GR_expmask
171 (p9) fadd.s1 CEIL_adj = f1,f0
176 (p8) fadd.s1 CEIL_adj = f0,f0
181 (p10) cmp.ge.unc p10,p11 = ceil_GR_exponent, ceil_GR_bigexp
188 (p11) fcvt.xf CEIL_FLOAT_INT_f8 = CEIL_INT_f8
194 (p10) fnorm.d f8 = CEIL_NORM_f8
198 // Is -1 < x < 0? If so, result will be -0. Special case it with p14 set.
201 (p8) fcmp.gt.unc.s1 p14,p0 = CEIL_NORM_f8, CEIL_MINUS_ONE
206 (p14) cmp.ne p11,p0 = r0,r0
207 (p14) fnorm.d f8 = CEIL_SIGNED_ZERO
212 (p14) fmpy.s0 CEIL_INEXACT = CEIL_FFFF,CEIL_FFFF
218 (p11) fadd.d f8 = CEIL_FLOAT_INT_f8,CEIL_adj
223 (p11) fcmp.eq.unc.s1 p12,p13 = CEIL_FLOAT_INT_f8, CEIL_NORM_f8
227 // Set inexact if result not equal to input
230 (p13) fmpy.s0 CEIL_INEXACT = CEIL_FFFF,CEIL_FFFF
233 // Set result to input if integer
236 (p12) fnorm.d f8 = CEIL_NORM_f8
240 // Here if input denorm
243 getf.exp ceil_GR_signexp = CEIL_NORM_f8
244 fcvt.fx.trunc.s1 CEIL_INT_f8 = CEIL_NORM_f8
245 br.cond.sptk L(CEIL_COMMON) ;;
249 ASM_SIZE_DIRECTIVE(ceil)