1 /* Copyright (C) 1996-2024 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, see
17 <https://www.gnu.org/licenses/>. */
20 #include <get-rounding-mode.h>
22 #include <math-barriers.h>
23 #include <libm-alias-double.h>
46 #if IREG_SIZE == 64 && OREG_SIZE == 32
49 if (__builtin_fabs (x
) > INT32_MAX
)
51 /* Converting large values to a 32 bit int may cause the frintx/fcvtza
52 sequence to set both FE_INVALID and FE_INEXACT. To avoid this
53 check the rounding mode and do a single instruction with the
54 appropriate rounding mode. */
56 switch (get_rounding_mode ())
59 asm volatile ("fcvtns" "\t%" OREGS
"0, %" IREGS
"1"
60 : "=r" (result
) : "w" (x
));
63 asm volatile ("fcvtps" "\t%" OREGS
"0, %" IREGS
"1"
64 : "=r" (result
) : "w" (x
));
67 asm volatile ("fcvtms" "\t%" OREGS
"0, %" IREGS
"1"
68 : "=r" (result
) : "w" (x
));
72 asm volatile ("fcvtzs" "\t%" OREGS
"0, %" IREGS
"1"
73 : "=r" (result
) : "w" (x
));
79 double r
= __builtin_rint (x
);
81 /* Prevent gcc from calling lrint directly when compiled with
82 -fno-math-errno by inserting a barrier. */
88 libm_alias_double (__lrint
, lrint
)