]>
Commit | Line | Data |
---|---|---|
f9f70e68 | 1 | /* lround function. PowerPC32 version. |
d4697bc9 | 2 | Copyright (C) 2004-2014 Free Software Foundation, Inc. |
f9f70e68 UD |
3 | This file is part of the GNU C Library. |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
f9f70e68 UD |
18 | |
19 | #include <sysdep.h> | |
f964490f | 20 | #include <math_ldbl_opt.h> |
a334319f | 21 | |
c1e6b459 | 22 | .section .rodata.cst4,"aM",@progbits,4 |
b0e196a4 | 23 | .align 2 |
c1e6b459 | 24 | .LC0: /* 0.5 */ |
b0e196a4 | 25 | .long 0x3f000000 |
f9f70e68 | 26 | .section ".text" |
9c84384c | 27 | |
f9f70e68 | 28 | /* long [r3] lround (float x [fp1]) |
9c84384c | 29 | IEEE 1003.1 lround function. IEEE specifies "round to the nearest |
f9f70e68 UD |
30 | integer value, rounding halfway cases away from zero, regardless of |
31 | the current rounding mode." However PowerPC Architecture defines | |
9c84384c JM |
32 | "round to Nearest" as "Choose the best approximation. In case of a |
33 | tie, choose the one that is even (least significant bit o).". | |
f9f70e68 UD |
34 | So we can't use the PowerPC "round to Nearest" mode. Instead we set |
35 | "round toward Zero" mode and round by adding +-0.5 before rounding | |
c1e6b459 UD |
36 | to the integer value. It is necessary to detect when x is |
37 | (+-)0x1.fffffffffffffp-2 because adding +-0.5 in this case will | |
38 | cause an erroneous shift, carry and round. We simply return 0 if | |
39 | 0.5 > x > -0.5. */ | |
f9f70e68 UD |
40 | |
41 | ENTRY (__lround) | |
a7e91561 UD |
42 | stwu r1,-16(r1) |
43 | cfi_adjust_cfa_offset (16) | |
f9f70e68 UD |
44 | #ifdef SHARED |
45 | mflr r11 | |
a7e91561 | 46 | cfi_register(lr,r11) |
91d2a845 WS |
47 | SETUP_GOT_ACCESS(r9,got_label) |
48 | addis r9,r9,.LC0-got_label@ha | |
49 | lfs fp10,.LC0-got_label@l(r9) | |
f9f70e68 | 50 | mtlr r11 |
a7e91561 | 51 | cfi_same_value (lr) |
f9f70e68 UD |
52 | #else |
53 | lis r9,.LC0@ha | |
c1e6b459 | 54 | lfs fp10,.LC0@l(r9) |
f9f70e68 | 55 | #endif |
c1e6b459 UD |
56 | fabs fp2, fp1 /* Get the absolute value of x. */ |
57 | fsub fp12,fp10,fp10 /* Compute 0.0. */ | |
58 | fcmpu cr6, fp2, fp10 /* if |x| < 0.5 */ | |
9ea8bfec | 59 | fcmpu cr7, fp1, fp12 /* x is negative? x < 0.0 */ |
c1e6b459 UD |
60 | blt- cr6,.Lretzero |
61 | fadd fp3,fp2,fp10 /* |x|+=0.5 bias to prepare to round. */ | |
9ea8bfec | 62 | bge cr7,.Lconvert /* x is positive so don't negate x. */ |
9c84384c | 63 | fnabs fp3,fp3 /* -(|x|+=0.5) */ |
c1e6b459 UD |
64 | .Lconvert: |
65 | fctiwz fp4,fp3 /* Convert to Integer word lround toward 0. */ | |
66 | stfd fp4,8(r1) | |
f7d78e18 UD |
67 | nop /* Ensure the following load is in a different dispatch */ |
68 | nop /* group to avoid pipe stall on POWER4&5. */ | |
f9f70e68 | 69 | nop |
7b88401f | 70 | lwz r3,8+LOWORD(r1) /* Load return as integer. */ |
c1e6b459 | 71 | .Lout: |
a7e91561 | 72 | addi r1,r1,16 |
f9f70e68 | 73 | blr |
c1e6b459 UD |
74 | .Lretzero: /* when 0.5 > x > -0.5 */ |
75 | li r3,0 /* return 0. */ | |
76 | b .Lout | |
f9f70e68 UD |
77 | END (__lround) |
78 | ||
f9f70e68 UD |
79 | weak_alias (__lround, lround) |
80 | ||
81 | strong_alias (__lround, __lroundf) | |
82 | weak_alias (__lround, lroundf) | |
83 | ||
84 | #ifdef NO_LONG_DOUBLE | |
85 | weak_alias (__lround, lroundl) | |
86 | strong_alias (__lround, __lroundl) | |
87 | #endif | |
f964490f RM |
88 | #if LONG_DOUBLE_COMPAT(libm, GLIBC_2_1) |
89 | compat_symbol (libm, __lround, lroundl, GLIBC_2_1) | |
90 | #endif |