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