2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / powerpc32 / power5+ / fpu / s_lround.S
blob83107f6f971b01fbd52f7ed1f614113f324e83fa
1 /* lround function.  POWER5+, PowerPC32 version.
2    Copyright (C) 2006 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
18    02110-1301 USA.  */
19 #include <sysdep.h>
20 #include <math_ldbl_opt.h>
21         
22 /* long [r3] lround (float x [fp1])
23    IEEE 1003.1 lround function.  IEEE specifies "round to the nearest 
24    integer value, rounding halfway cases away from zero, regardless of
25    the current rounding mode."  However PowerPC Architecture defines
26    "round to Nearest" as "Choose the best approximation. In case of a 
27    tie, choose the one that is even (least significant bit o).". 
28    So we pre-round using the V2.02 Floating Round to Integer Nearest
29    instruction before we use the Floating Convert to Integer Word with
30    round to zero instruction.  */
32         .machine        "power5"
33 ENTRY (__lround)
34         stwu    r1,-16(r1)
35         cfi_adjust_cfa_offset (16)
36         frin    fp2,fp1
37         fctiwz  fp3,fp2         /* Convert To Integer Word lround toward 0.  */
38         stfd    fp3,8(r1)
39         nop     /* Ensure the following load is in a different dispatch  */
40         nop     /* group to avoid pipe stall on POWER4&5.  */
41         nop
42         lwz     r3,12(r1)
43         addi    r1,r1,16
44         blr
45         END (__lround)
47 weak_alias (__lround, lround)
49 strong_alias (__lround, __lroundf)
50 weak_alias (__lround, lroundf)
52 #ifdef NO_LONG_DOUBLE
53 weak_alias (__lround, lroundl)
54 strong_alias (__lround, __lroundl)
55 #endif
56 #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1)
57 compat_symbol (libm, __lround, lroundl, GLIBC_2_1)
58 #endif