fixsfti.c revision 276851
1168404Spjd/* ===-- fixsfti.c - Implement __fixsfti -----------------------------------=== 2168404Spjd * 3168404Spjd * The LLVM Compiler Infrastructure 4168404Spjd * 5168404Spjd * This file is dual licensed under the MIT and the University of Illinois Open 6168404Spjd * Source Licenses. See LICENSE.TXT for details. 7168404Spjd * 8168404Spjd * ===----------------------------------------------------------------------=== 9168404Spjd * 10168404Spjd * This file implements __fixsfti for the compiler_rt library. 11168404Spjd * 12168404Spjd * ===----------------------------------------------------------------------=== 13168404Spjd */ 14168404Spjd 15168404Spjd#include "int_lib.h" 16168404Spjd 17168404Spjd#ifdef CRT_HAS_128BIT 18168404Spjd 19168404Spjd/* Returns: convert a to a signed long long, rounding toward zero. */ 20168404Spjd 21168404Spjd/* Assumption: float is a IEEE 32 bit floating point type 22168404Spjd * su_int is a 32 bit integral type 23168404Spjd * value in float is representable in ti_int (no range checking performed) 24168404Spjd */ 25168404Spjd 26168404Spjd/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */ 27168404Spjd 28168404SpjdCOMPILER_RT_ABI ti_int 29168404Spjd__fixsfti(float a) 30168404Spjd{ 31168404Spjd float_bits fb; 32168404Spjd fb.f = a; 33168404Spjd int e = ((fb.u & 0x7F800000) >> 23) - 127; 34168404Spjd if (e < 0) 35168404Spjd return 0; 36185029Spjd ti_int s = (si_int)(fb.u & 0x80000000) >> 31; 37168404Spjd ti_int r = (fb.u & 0x007FFFFF) | 0x00800000; 38168404Spjd if (e > 23) 39168404Spjd r <<= (e - 23); 40168404Spjd else 41168404Spjd r >>= (23 - e); 42168404Spjd return (r ^ s) - s; 43168404Spjd} 44168404Spjd 45168404Spjd#endif /* CRT_HAS_128BIT */ 46168404Spjd