xref: /aosp_15_r20/external/compiler-rt/lib/builtins/fixunssfdi.c (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot /* ===-- fixunssfdi.c - Implement __fixunssfdi -----------------------------===
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 
ARM_EABI_FNALIAS(f2ulz,fixunssfdi)14*7c3d14c8STreehugger Robot ARM_EABI_FNALIAS(f2ulz, fixunssfdi)
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
22*7c3d14c8STreehugger Robot __fixunssfdi(float a)
23*7c3d14c8STreehugger Robot {
24*7c3d14c8STreehugger Robot     if (a <= 0.0f) return 0;
25*7c3d14c8STreehugger Robot     double da = a;
26*7c3d14c8STreehugger Robot     su_int high = da / 4294967296.f;               /* da / 0x1p32f; */
27*7c3d14c8STreehugger Robot     su_int low = da - (double)high * 4294967296.f; /* high * 0x1p32f; */
28*7c3d14c8STreehugger Robot     return ((du_int)high << 32) | low;
29*7c3d14c8STreehugger Robot }
30*7c3d14c8STreehugger Robot 
31*7c3d14c8STreehugger Robot #else
32*7c3d14c8STreehugger Robot /* Support for systems that don't have hardware floating-point; there are no
33*7c3d14c8STreehugger Robot  * flags to set, and we don't want to code-gen to an unknown soft-float
34*7c3d14c8STreehugger Robot  * implementation.
35*7c3d14c8STreehugger Robot  */
36*7c3d14c8STreehugger Robot 
37*7c3d14c8STreehugger Robot typedef du_int fixuint_t;
38*7c3d14c8STreehugger Robot #include "fp_fixuint_impl.inc"
39*7c3d14c8STreehugger Robot 
40*7c3d14c8STreehugger Robot COMPILER_RT_ABI du_int
41*7c3d14c8STreehugger Robot __fixunssfdi(fp_t a) {
42*7c3d14c8STreehugger Robot     return __fixuint(a);
43*7c3d14c8STreehugger Robot }
44*7c3d14c8STreehugger Robot 
45*7c3d14c8STreehugger Robot #endif
46