1 /* lround function. PowerPC32 version.
2 Copyright (C) 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 1 Franklin Street, Fifth Floor, Boston MA
21 #include <math_ldbl_opt.h>
23 .section .rodata.cst4,"aM",@progbits,4
29 /* long [r3] lround (float x [fp1])
30 IEEE 1003.1 lround function. IEEE specifies "round to the nearest
31 integer value, rounding halfway cases away from zero, regardless of
32 the current rounding mode." However PowerPC Architecture defines
33 "round to Nearest" as "Choose the best approximation. In case of a
34 tie, choose the one that is even (least significant bit o).".
35 So we can't use the PowerPC "round to Nearest" mode. Instead we set
36 "round toward Zero" mode and round by adding +-0.5 before rounding
37 to the integer value. It is necessary to detect when x is
38 (+-)0x1.fffffffffffffp-2 because adding +-0.5 in this case will
39 cause an erroneous shift, carry and round. We simply return 0 if
44 cfi_adjust_cfa_offset (16)
50 addis r9,r9,.LC0-1b@ha
51 lfs fp10,.LC0-1b@l(r9)
58 fabs fp2, fp1 /* Get the absolute value of x. */
59 fsub fp12,fp10,fp10 /* Compute 0.0. */
60 fcmpu cr6, fp2, fp10 /* if |x| < 0.5 */
61 fcmpu cr7, fp1, fp12 /* x is negative? x < 0.0 */
63 fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */
64 bge cr7,.Lconvert /* x is positive so don't negate x. */
65 fnabs fp3,fp3 /* -(|x|+=0.5) */
67 fctiwz fp4,fp3 /* Convert to Integer word lround toward 0. */
69 nop /* Ensure the following load is in a different dispatch */
70 nop /* group to avoid pipe stall on POWER4&5. */
72 lwz r3,12(r1) /* Load return as integer. */
76 .Lretzero: /* when 0.5 > x > -0.5 */
77 li r3,0 /* return 0. */
81 weak_alias (__lround, lround)
83 strong_alias (__lround, __lroundf)
84 weak_alias (__lround, lroundf)
87 weak_alias (__lround, lroundl)
88 strong_alias (__lround, __lroundl)
90 #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1)
91 compat_symbol (libm, __lround, lroundl, GLIBC_2_1)