fixunssfdi.c revision 214152
1214152Sed/* ===-- fixunssfdi.c - Implement __fixunssfdi -----------------------------===
2214152Sed *
3214152Sed *                     The LLVM Compiler Infrastructure
4214152Sed *
5222656Sed * This file is distributed under the University of Illinois Open Source
6222656Sed * License. See LICENSE.TXT for details.
7214152Sed *
8214152Sed * ===----------------------------------------------------------------------===
9214152Sed *
10214152Sed * This file implements __fixunssfdi for the compiler_rt library.
11214152Sed *
12214152Sed * ===----------------------------------------------------------------------===
13214152Sed */
14214152Sed
15214152Sed#include "int_lib.h"
16214152Sed
17214152Sed/* Returns: convert a to a unsigned long long, rounding toward zero.
18214152Sed *          Negative values all become zero.
19214152Sed */
20214152Sed
21214152Sed/* Assumption: float is a IEEE 32 bit floating point type
22214152Sed *             du_int is a 64 bit integral type
23214152Sed *             value in float is representable in du_int or is negative
24214152Sed *                 (no range checking performed)
25214152Sed */
26214152Sed
27214152Sed/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
28239138Sandrew
29222656Seddu_int
30222656Sed__fixunssfdi(float a)
31214152Sed{
32214152Sed    float_bits fb;
33214152Sed    fb.f = a;
34214152Sed    int e = ((fb.u & 0x7F800000) >> 23) - 127;
35214152Sed    if (e < 0 || (fb.u & 0x80000000))
36214152Sed        return 0;
37214152Sed    du_int r = (fb.u & 0x007FFFFF) | 0x00800000;
38214152Sed    if (e > 23)
39214152Sed        r <<= (e - 23);
40214152Sed    else
41214152Sed        r >>= (23 - e);
42214152Sed    return r;
43214152Sed}
44214152Sed