fixunssfsi.c revision 214152
10Sstevel@tonic-gate/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------=== 20Sstevel@tonic-gate * 30Sstevel@tonic-gate * The LLVM Compiler Infrastructure 40Sstevel@tonic-gate * 50Sstevel@tonic-gate * This file is distributed under the University of Illinois Open Source 60Sstevel@tonic-gate * License. See LICENSE.TXT for details. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * ===----------------------------------------------------------------------=== 90Sstevel@tonic-gate * 100Sstevel@tonic-gate * This file implements __fixunssfsi for the compiler_rt library. 110Sstevel@tonic-gate * 120Sstevel@tonic-gate * ===----------------------------------------------------------------------=== 130Sstevel@tonic-gate */ 140Sstevel@tonic-gate 150Sstevel@tonic-gate#include "int_lib.h" 160Sstevel@tonic-gate 170Sstevel@tonic-gate/* Returns: convert a to a unsigned int, rounding toward zero. 180Sstevel@tonic-gate * Negative values all become zero. 190Sstevel@tonic-gate */ 200Sstevel@tonic-gate 210Sstevel@tonic-gate/* Assumption: float is a IEEE 32 bit floating point type 220Sstevel@tonic-gate * su_int is a 32 bit integral type 230Sstevel@tonic-gate * value in float is representable in su_int or is negative 240Sstevel@tonic-gate * (no range checking performed) 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */ 280Sstevel@tonic-gate 290Sstevel@tonic-gatesu_int 300Sstevel@tonic-gate__fixunssfsi(float a) 310Sstevel@tonic-gate{ 320Sstevel@tonic-gate float_bits fb; 330Sstevel@tonic-gate fb.f = a; 340Sstevel@tonic-gate int e = ((fb.u & 0x7F800000) >> 23) - 127; 350Sstevel@tonic-gate if (e < 0 || (fb.u & 0x80000000)) 360Sstevel@tonic-gate return 0; 370Sstevel@tonic-gate su_int r = (fb.u & 0x007FFFFF) | 0x00800000; 380Sstevel@tonic-gate if (e > 23) 390Sstevel@tonic-gate r <<= (e - 23); 400Sstevel@tonic-gate else 410Sstevel@tonic-gate r >>= (23 - e); 420Sstevel@tonic-gate return r; 430Sstevel@tonic-gate} 440Sstevel@tonic-gate