2.9
[glibc/nacl-glibc.git] / sysdeps / powerpc / powerpc64 / power5+ / fpu / s_llround.S
blob6a022769f4dd7b2cd54595f54894d7f453266658
1 /* llround function.  POWER5+, PowerPC64 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., 59 Temple Place, Suite 330, Boston, MA
18    02111-1307 USA.  */
20 #include <sysdep.h>
21 #include <math_ldbl_opt.h>
22         
23 /* long long [r3] llround (float x [fp1])
24    IEEE 1003.1 llround function.  IEEE specifies "round to the nearest 
25    integer value, rounding halfway cases away from zero, regardless of
26    the current rounding mode."  However PowerPC Architecture defines
27    "round to Nearest" as "Choose the best approximation. In case of a 
28    tie, choose the one that is even (least significant bit o).". 
29    So we pre-round using the V2.02 Floating Round to Integer Nearest
30    instruction before we use Floating Convert to Integer Word with
31    round to zero instruction.  */
33         .machine        "power5"
34 EALIGN (__llround, 4, 0)
35         CALL_MCOUNT 0
36         frin    fp2, fp1        /* Round to nearest +-0.5.  */  
37         fctidz  fp3, fp2        /* Convert To Integer DW round toward 0.  */
38         stfd    fp3, -16(r1)
39         nop     /* Insure the following load is in a different dispatch group */
40         nop     /* to avoid pipe stall on POWER4&5.  */
41         nop
42         ld      r3, -16(r1)
43         blr
44         END (__llround)
46 strong_alias (__llround, __lround)
47 weak_alias (__llround, llround)
48 weak_alias (__lround, lround)
50 #ifdef NO_LONG_DOUBLE
51 weak_alias (__llround, llroundl)
52 strong_alias (__llround, __llroundl)
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, __llround, llroundl, GLIBC_2_1)
58 compat_symbol (libm, __lround, lroundl, GLIBC_2_1)
59 #endif