blob: 5458f0276887637737dec4f868af4b11d2ad73fb [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- fixsfdi.c - Implement __fixsfdi -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements __fixsfdi for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "int_lib.h"
15
16// Returns: convert a to a signed long long, rounding toward zero.
17
18// Assumption: float is a IEEE 32 bit floating point type
19// su_int is a 32 bit integral type
20// value in float is representable in di_int (no range checking performed)
21
22// seee eeee emmm mmmm mmmm mmmm mmmm mmmm
23
24di_int
25__fixsfdi(float a)
26{
27 float_bits fb;
28 fb.f = a;
29 int e = ((fb.u & 0x7F800000) >> 23) - 127;
30 if (e < 0)
31 return 0;
32 di_int s = (si_int)(fb.u & 0x80000000) >> 31;
33 di_int r = (fb.u & 0x007FFFFF) | 0x00800000;
34 if (e > 23)
35 r <<= (e - 23);
36 else
37 r >>= (23 - e);
38 return (r ^ s) - s;
39}