-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libc: add missing functions __fixunssfsi() and __floatunsisf().
- Loading branch information
Showing
5 changed files
with
96 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------=== | ||
* | ||
* The LLVM Compiler Infrastructure | ||
* | ||
* This file is dual licensed under the MIT and the University of Illinois Open | ||
* Source Licenses. See LICENSE.TXT for details. | ||
* | ||
* ===----------------------------------------------------------------------=== | ||
* | ||
* This file implements __fixunssfsi for the compiler_rt library. | ||
* | ||
* ===----------------------------------------------------------------------=== | ||
*/ | ||
#define SINGLE_PRECISION | ||
#include "fp_lib.h" | ||
|
||
/* Returns: convert a to a unsigned int, rounding toward zero. | ||
* Negative values all become zero. | ||
*/ | ||
|
||
/* Assumption: float is a IEEE 32 bit floating point type | ||
* su_int is a 32 bit integral type | ||
* value in float is representable in su_int or is negative | ||
* (no range checking performed) | ||
*/ | ||
|
||
/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */ | ||
|
||
uint32_t | ||
__fixunssfsi(fp_t a) | ||
{ | ||
union { fp_t f; rep_t u; } fb; | ||
fb.f = a; | ||
|
||
int e = ((fb.u & 0x7F800000) >> 23) - 127; | ||
if (e < 0 || (fb.u & 0x80000000)) | ||
return 0; | ||
|
||
rep_t r = (fb.u & 0x007FFFFF) | 0x00800000; | ||
if (e > 23) | ||
r <<= (e - 23); | ||
else | ||
r >>= (23 - e); | ||
return r; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,8 +16,6 @@ | |
#define SINGLE_PRECISION | ||
#include "fp_lib.h" | ||
|
||
//#include "int_lib.h" | ||
|
||
fp_t | ||
__floatsisf(int a) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===-- lib/floatunsisf.c - uint -> single-precision conversion ---*- C -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is dual licensed under the MIT and the University of Illinois Open | ||
// Source Licenses. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This file implements unsigned integer to single-precision conversion for the | ||
// compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even | ||
// mode. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#define SINGLE_PRECISION | ||
#include "fp_lib.h" | ||
|
||
fp_t | ||
__floatunsisf(unsigned int a) | ||
{ | ||
const int aWidth = sizeof a * CHAR_BIT; | ||
|
||
// Handle zero as a special case to protect clz | ||
if (a == 0) | ||
return fromRep(0); | ||
|
||
// Exponent of (fp_t)a is the width of abs(a). | ||
const int exponent = (aWidth - 1) - __builtin_clz(a); | ||
rep_t result; | ||
|
||
// Shift a into the significand field, rounding if it is a right-shift | ||
if (exponent <= significandBits) { | ||
const int shift = significandBits - exponent; | ||
result = (rep_t)a << shift ^ implicitBit; | ||
} else { | ||
const int shift = exponent - significandBits; | ||
result = (rep_t)a >> shift ^ implicitBit; | ||
rep_t round = (rep_t)a << (typeWidth - shift); | ||
if (round > signBit) result++; | ||
if (round == signBit) result += result & 1; | ||
} | ||
|
||
// Insert the exponent | ||
result += (rep_t)(exponent + exponentBias) << significandBits; | ||
return fromRep(result); | ||
} |