blob: 8f4c62627ca5d33a9c8ea81c647e06ca101836d8 [file] [log] [blame]
Edward O'Callaghan2bf62722009-08-05 04:02:56 +00001/* ===-- fixunssfti.c - Implement __fixunssfti -----------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan2bf62722009-08-05 04:02:56 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __fixunssfti for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
Daniel Dunbarb3a69012009-06-26 16:47:03 +000015#include "int_lib.h"
16
Chandler Carruth7f2d7c72012-06-22 21:09:22 +000017#if __x86_64
18
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000019/* Returns: convert a to a unsigned long long, rounding toward zero.
20 * Negative values all become zero.
21 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000022
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000023/* Assumption: float is a IEEE 32 bit floating point type
24 * tu_int is a 64 bit integral type
25 * value in float is representable in tu_int or is negative
26 * (no range checking performed)
27 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000028
Edward O'Callaghan37a6a452009-08-07 20:30:09 +000029/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000030
31tu_int
32__fixunssfti(float a)
33{
34 float_bits fb;
35 fb.f = a;
36 int e = ((fb.u & 0x7F800000) >> 23) - 127;
37 if (e < 0 || (fb.u & 0x80000000))
38 return 0;
39 tu_int r = (fb.u & 0x007FFFFF) | 0x00800000;
40 if (e > 23)
41 r <<= (e - 23);
42 else
43 r >>= (23 - e);
44 return r;
45}
46
47#endif