xref: /aosp_15_r20/external/compiler-rt/lib/builtins/fixsfdi.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot /* ===-- fixsfdi.c - Implement __fixsfdi -----------------------------------===
2*7c3d14c8STreehugger Robot  *
3*7c3d14c8STreehugger Robot  *                     The LLVM Compiler Infrastructure
4*7c3d14c8STreehugger Robot  *
5*7c3d14c8STreehugger Robot  * This file is dual licensed under the MIT and the University of Illinois Open
6*7c3d14c8STreehugger Robot  * Source Licenses. See LICENSE.TXT for details.
7*7c3d14c8STreehugger Robot  *
8*7c3d14c8STreehugger Robot  * ===----------------------------------------------------------------------===
9*7c3d14c8STreehugger Robot  */
10*7c3d14c8STreehugger Robot 
11*7c3d14c8STreehugger Robot #define SINGLE_PRECISION
12*7c3d14c8STreehugger Robot #include "fp_lib.h"
13*7c3d14c8STreehugger Robot 
14*7c3d14c8STreehugger Robot ARM_EABI_FNALIAS(f2lz, fixsfdi)
15*7c3d14c8STreehugger Robot 
16*7c3d14c8STreehugger Robot #ifndef __SOFT_FP__
17*7c3d14c8STreehugger Robot /* Support for systems that have hardware floating-point; can set the invalid
18*7c3d14c8STreehugger Robot  * flag as a side-effect of computation.
19*7c3d14c8STreehugger Robot  */
20*7c3d14c8STreehugger Robot 
21*7c3d14c8STreehugger Robot COMPILER_RT_ABI du_int __fixunssfdi(float a);
22*7c3d14c8STreehugger Robot 
23*7c3d14c8STreehugger Robot COMPILER_RT_ABI di_int
__fixsfdi(float a)24*7c3d14c8STreehugger Robot __fixsfdi(float a)
25*7c3d14c8STreehugger Robot {
26*7c3d14c8STreehugger Robot     if (a < 0.0f) {
27*7c3d14c8STreehugger Robot         return -__fixunssfdi(-a);
28*7c3d14c8STreehugger Robot     }
29*7c3d14c8STreehugger Robot     return __fixunssfdi(a);
30*7c3d14c8STreehugger Robot }
31*7c3d14c8STreehugger Robot 
32*7c3d14c8STreehugger Robot #else
33*7c3d14c8STreehugger Robot /* Support for systems that don't have hardware floating-point; there are no
34*7c3d14c8STreehugger Robot  * flags to set, and we don't want to code-gen to an unknown soft-float
35*7c3d14c8STreehugger Robot  * implementation.
36*7c3d14c8STreehugger Robot  */
37*7c3d14c8STreehugger Robot 
38*7c3d14c8STreehugger Robot typedef di_int fixint_t;
39*7c3d14c8STreehugger Robot typedef du_int fixuint_t;
40*7c3d14c8STreehugger Robot #include "fp_fixint_impl.inc"
41*7c3d14c8STreehugger Robot 
42*7c3d14c8STreehugger Robot COMPILER_RT_ABI di_int
43*7c3d14c8STreehugger Robot __fixsfdi(fp_t a) {
44*7c3d14c8STreehugger Robot     return __fixint(a);
45*7c3d14c8STreehugger Robot }
46*7c3d14c8STreehugger Robot 
47*7c3d14c8STreehugger Robot #endif
48