fixunssfsi.c revision 222656
1/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------===
2 *
3 *                     The LLVM Compiler Infrastructure
4 *
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
7 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __fixunssfsi for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
14#include "abi.h"
15
16#include "int_lib.h"
17
18/* Returns: convert a to a unsigned int, rounding toward zero.
19 *          Negative values all become zero.
20 */
21
22/* Assumption: float is a IEEE 32 bit floating point type
23 *             su_int is a 32 bit integral type
24 *             value in float is representable in su_int or is negative
25 *                 (no range checking performed)
26 */
27
28/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
29
30ARM_EABI_FNALIAS(f2uiz, fixunssfsi);
31
32COMPILER_RT_ABI su_int
33__fixunssfsi(float a)
34{
35    float_bits fb;
36    fb.f = a;
37    int e = ((fb.u & 0x7F800000) >> 23) - 127;
38    if (e < 0 || (fb.u & 0x80000000))
39        return 0;
40    su_int r = (fb.u & 0x007FFFFF) | 0x00800000;
41    if (e > 23)
42        r <<= (e - 23);
43    else
44        r >>= (23 - e);
45    return r;
46}
47