fixunssfsi.c revision 222656
1214152Sed/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------===
2214152Sed *
3214152Sed *                     The LLVM Compiler Infrastructure
4214152Sed *
5222656Sed * This file is dual licensed under the MIT and the University of Illinois Open
6222656Sed * Source Licenses. See LICENSE.TXT for details.
7214152Sed *
8214152Sed * ===----------------------------------------------------------------------===
9214152Sed *
10214152Sed * This file implements __fixunssfsi for the compiler_rt library.
11214152Sed *
12214152Sed * ===----------------------------------------------------------------------===
13214152Sed */
14214152Sed#include "abi.h"
15214152Sed
16214152Sed#include "int_lib.h"
17214152Sed
18214152Sed/* Returns: convert a to a unsigned int, rounding toward zero.
19229135Sed *          Negative values all become zero.
20229135Sed */
21229135Sed
22214152Sed/* Assumption: float is a IEEE 32 bit floating point type
23229135Sed *             su_int is a 32 bit integral type
24214152Sed *             value in float is representable in su_int or is negative
25229135Sed *                 (no range checking performed)
26229135Sed */
27229135Sed
28245642Sandrew/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
29245642Sandrew
30245642SandrewARM_EABI_FNALIAS(f2uiz, fixunssfsi);
31245642Sandrew
32245642SandrewCOMPILER_RT_ABI su_int
33245642Sandrew__fixunssfsi(float a)
34245642Sandrew{
35245642Sandrew    float_bits fb;
36245642Sandrew    fb.f = a;
37214152Sed    int e = ((fb.u & 0x7F800000) >> 23) - 127;
38229135Sed    if (e < 0 || (fb.u & 0x80000000))
39229135Sed        return 0;
40214152Sed    su_int r = (fb.u & 0x007FFFFF) | 0x00800000;
41214152Sed    if (e > 23)
42229135Sed        r <<= (e - 23);
43229135Sed    else
44229135Sed        r >>= (23 - e);
45229135Sed    return r;
46229135Sed}
47214152Sed