blob: 87368b7e5a06162c49b6f743da4d2f1ae8fa231f [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- fixdfdi.c - Implement __fixdfdi -----------------------------------===//
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 __fixdfdi 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: double is a IEEE 64 bit floating point type
19// su_int is a 32 bit integral type
20// value in double is representable in di_int (no range checking performed)
21
22// seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
23
24di_int
25__fixdfdi(double a)
26{
27 double_bits fb;
28 fb.f = a;
29 int e = ((fb.u.high & 0x7FF00000) >> 20) - 1023;
30 if (e < 0)
31 return 0;
32 di_int s = (si_int)(fb.u.high & 0x80000000) >> 31;
33 dwords r;
34 r.high = (fb.u.high & 0x000FFFFF) | 0x00100000;
35 r.low = fb.u.low;
36 if (e > 52)
37 r.all <<= (e - 52);
38 else
39 r.all >>= (52 - e);
40 return (r.all ^ s) - s;
41}