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