]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/powerpc/powerpc32/fpu/s_trunc.S
powerpc: round/roundf refactor
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc32 / fpu / s_trunc.S
CommitLineData
f9f70e68 1/* trunc function. PowerPC32 version.
04277e02 2 Copyright (C) 2004-2019 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>
51ea3b20 21#include <libm-alias-double.h>
f9f70e68 22
b0e196a4
UD
23 .section .rodata.cst4,"aM",@progbits,4
24 .align 2
f9f70e68 25.LC0: /* 2**52 */
b0e196a4 26 .long 0x59800000
f9f70e68
UD
27
28/* double [fp1] trunc (double x [fp1])
29 IEEE 1003.1 trunc function. IEEE specifies "trunc to the integer
9c84384c 30 value, in floating format, nearest to but no larger in magnitude
f9f70e68
UD
31 then the argument."
32 We set "round toward Zero" mode and trunc by adding +-2**52 then
33 subtracting +-2**52. */
34
f7d78e18 35 .section ".text"
f9f70e68 36ENTRY (__trunc)
f9f70e68
UD
37#ifdef SHARED
38 mflr r11
a7e91561 39 cfi_register(lr,r11)
91d2a845
WS
40 SETUP_GOT_ACCESS(r9,got_label)
41 addis r9,r9,.LC0-got_label@ha
42 lfs fp13,.LC0-got_label@l(r9)
a7e91561
UD
43 mtlr r11
44 cfi_same_value (lr)
f9f70e68
UD
45#else
46 lis r9,.LC0@ha
b0e196a4 47 lfs fp13,.LC0@l(r9)
f9f70e68
UD
48#endif
49 fabs fp0,fp1
50 fsub fp12,fp13,fp13 /* generate 0.0 */
51 fcmpu cr7,fp0,fp13 /* if (fabs(x) > TWO52) */
1f921a93
JM
52 mffs fp11 /* Save current FPU rounding mode and
53 "inexact" state. */
f9f70e68 54 fcmpu cr6,fp1,fp12 /* if (x > 0.0) */
debf7618 55 bnl- cr7,.L10
f9f70e68
UD
56 mtfsfi 7,1 /* Set rounding toward 0 mode. */
57 ble- cr6,.L4
58 fadd fp1,fp1,fp13 /* x+= TWO52; */
59 fsub fp1,fp1,fp13 /* x-= TWO52; */
4d37c8aa
UD
60 fabs fp1,fp1 /* if (x == 0.0) */
61 /* x = 0.0; */
1f921a93
JM
62 mtfsf 0xff,fp11 /* Restore previous rounding mode and
63 "inexact" state. */
f9f70e68
UD
64 blr
65.L4:
66 bge- cr6,.L9 /* if (x < 0.0) */
67 fsub fp1,fp1,fp13 /* x-= TWO52; */
68 fadd fp1,fp1,fp13 /* x+= TWO52; */
4d37c8aa
UD
69 fnabs fp1,fp1 /* if (x == 0.0) */
70 /* x = -0.0; */
71.L9:
1f921a93
JM
72 mtfsf 0xff,fp11 /* Restore previous rounding mode and
73 "inexact" state. */
f9f70e68 74 blr
debf7618
JM
75.L10:
76 /* Ensure sNaN input is converted to qNaN. */
77 fcmpu cr7,fp1,fp1
78 beqlr cr7
79 fadd fp1,fp1,fp1
80 blr
f9f70e68
UD
81 END (__trunc)
82
51ea3b20 83libm_alias_double (__trunc, trunc)