fixsfdi.c revision 214152
1214152Sed/* ===-- fixsfdi.c - Implement __fixsfdi -----------------------------------=== 2214152Sed * 3214152Sed * The LLVM Compiler Infrastructure 4214152Sed * 5214152Sed * This file is distributed under the University of Illinois Open Source 6214152Sed * License. See LICENSE.TXT for details. 7214152Sed * 8214152Sed * ===----------------------------------------------------------------------=== 9214152Sed * 10214152Sed * This file implements __fixsfdi for the compiler_rt library. 11214152Sed * 12214152Sed * ===----------------------------------------------------------------------=== 13214152Sed */ 14214152Sed 15214152Sed#include "int_lib.h" 16214152Sed 17214152Sed/* Returns: convert a to a signed long long, rounding toward zero. */ 18214152Sed 19214152Sed/* Assumption: float is a IEEE 32 bit floating point type 20214152Sed * su_int is a 32 bit integral type 21214152Sed * value in float is representable in di_int (no range checking performed) 22214152Sed */ 23214152Sed 24214152Sed/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */ 25214152Sed 26214152Seddi_int 27214152Sed__fixsfdi(float a) 28214152Sed{ 29214152Sed float_bits fb; 30214152Sed fb.f = a; 31214152Sed int e = ((fb.u & 0x7F800000) >> 23) - 127; 32214152Sed if (e < 0) 33214152Sed return 0; 34214152Sed di_int s = (si_int)(fb.u & 0x80000000) >> 31; 35214152Sed di_int r = (fb.u & 0x007FFFFF) | 0x00800000; 36214152Sed if (e > 23) 37214152Sed r <<= (e - 23); 38214152Sed else 39214152Sed r >>= (23 - e); 40214152Sed return (r ^ s) - s; 41214152Sed} 42