//uspace/trunk/softfloat/include/conversion.h |
---|
35,13 → 35,20 |
__u32 float32_to_uint32(float32 a); |
__s32 float32_to_int32(float32 a); |
__u64 float32_to_uint64(float32 a); |
__s64 float32_to_int64(float32 a); |
__u64 float64_to_uint64(float64 a); |
__s64 float64_to_int64(float64 a); |
__u64 float32_to_uint64(float32 a); |
__s64 float32_to_int64(float32 a); |
__u32 float64_to_uint32(float64 a); |
__s32 float64_to_int32(float64 a); |
float32 uint32_to_float32(__u32 i); |
float32 int32_to_float32(__s32 i); |
float32 uint64_to_float32(__u64 i); |
float32 int64_to_float32(__s64 i); |
#endif |
//uspace/trunk/softfloat/include/common.h |
---|
33,4 → 33,10 |
float64 finishFloat64(__s32 cexp, __u64 cfrac, char sign); |
int countZeroes32(__u32 i); |
int countZeroes8(__u8 i); |
void roundFloat32(__s32 *exp, __u32 *fraction); |
void roundFloat64(__s32 *exp, __u64 *fraction); |
#endif |
//uspace/trunk/softfloat/generic/softfloat.c |
---|
256,6 → 256,10 |
float __floatsisf(int i) |
{ |
float32 fa; |
fa = int_to_float32(i); |
return fa.f; |
} |
double __floatsidf(int i) |
{ |
263,6 → 267,10 |
float __floatdisf(long i) |
{ |
float32 fa; |
fa = long_to_float32(i); |
return fa.f; |
} |
double __floatdidf(long i) |
{ |
270,6 → 278,10 |
float __floattisf(long long i) |
{ |
float32 fa; |
fa = longlong_to_float32(i); |
return fa.f; |
} |
double __floattidf(long long i) |
{ |
277,6 → 289,10 |
float __floatunsisf(unsigned int i) |
{ |
float32 fa; |
fa = uint_to_float32(i); |
return fa.f; |
} |
double __floatunsidf(unsigned int i) |
{ |
284,6 → 300,10 |
float __floatundisf(unsigned long i) |
{ |
float32 fa; |
fa = ulong_to_float32(i); |
return fa.f; |
} |
double __floatundidf(unsigned long i) |
{ |
291,6 → 311,10 |
float __floatuntisf(unsigned long long i) |
{ |
float32 fa; |
fa = ulonglong_to_float32(i); |
return fa.f; |
} |
double __floatuntidf(unsigned long long i) |
{ |
//uspace/trunk/softfloat/generic/conversion.c |
---|
29,6 → 29,7 |
#include "sftypes.h" |
#include "conversion.h" |
#include "comparison.h" |
#include "common.h" |
float64 convertFloat32ToFloat64(float32 a) |
{ |
385,4 → 386,74 |
return (__s32)_float64_to_uint64_helper(a); |
} |
/** Convert unsigned integer to float32 |
* |
* |
*/ |
float32 uint32_to_float32(__u32 i) |
{ |
int counter; |
__s32 exp; |
float32 result; |
result.parts.sign = 0; |
result.parts.fraction = 0; |
counter = countZeroes32(i); |
exp = FLOAT32_BIAS + 32 - counter - 1; |
if (counter == 32) { |
result.binary = 0; |
return result; |
} |
if (counter > 0) { |
i <<= counter - 1; |
} else { |
i >>= 1; |
} |
roundFloat32(&exp, &i); |
result.parts.fraction = i >> 7; |
result.parts.exp = exp; |
return result; |
} |
float32 int32_to_float32(__s32 i) |
{ |
float32 result; |
if (i < 0) { |
result = uint32_to_float32((__u32)(-i)); |
} else { |
result = uint32_to_float32((__u32)i); |
} |
result.parts.sign = i < 0; |
return result; |
} |
float32 uint64_to_float32(__u64 i) |
{ |
} |
float32 int64_to_float32(__s64 i) |
{ |
float32 result; |
if (i < 0) { |
result = uint64_to_float32((__u64)(-i)); |
} else { |
result = uint64_to_float32((__u64)i); |
} |
result.parts.sign = i < 0; |
return result; |
} |
//uspace/trunk/softfloat/generic/common.c |
---|
29,6 → 29,28 |
#include<sftypes.h> |
#include<common.h> |
/* Table for fast leading zeroes counting */ |
char zeroTable[256] = { |
8, 7, 7, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, \ |
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ |
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ |
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ |
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
}; |
/** Take fraction shifted by 10 bits to left, round it, normalize it and detect exceptions |
* @param exp exponent with bias |
* @param cfrac fraction shifted 10 places left with added hidden bit |
62,7 → 84,7 |
cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); |
if (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_HIDDEN_BIT_MASK - 1)))) { |
if (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1)))) { |
result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2) ) & (~FLOAT64_HIDDEN_BIT_MASK)); |
return result; |
93,3 → 115,91 |
return result; |
} |
/** Counts leading zeroes in 64bit unsigned integer |
* @param i |
*/ |
int countZeroes64(__u64 i) |
{ |
int j; |
for (j =0; j < 64; j += 8) { |
if ( i & (0xFFll << (56 - j))) { |
return (j + countZeroes8(i >> (56 - j))); |
} |
} |
return 64; |
} |
/** Counts leading zeroes in 32bit unsigned integer |
* @param i |
*/ |
int countZeroes32(__u32 i) |
{ |
int j; |
for (j =0; j < 32; j += 8) { |
if ( i & (0xFF << (24 - j))) { |
return (j + countZeroes8(i >> (24 - j))); |
} |
} |
return 32; |
} |
/** Counts leading zeroes in byte |
* @param i |
*/ |
int countZeroes8(__u8 i) |
{ |
return zeroTable[i]; |
} |
/** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 30. bit |
* @param exp exponent |
* @param fraction part with hidden bit shifted to 30. bit |
*/ |
void roundFloat32(__s32 *exp, __u32 *fraction) |
{ |
/* rounding - if first bit after fraction is set then round up */ |
(*fraction) += (0x1 << 6); |
if ((*fraction) & (FLOAT32_HIDDEN_BIT_MASK << 8)) { |
/* rounding overflow */ |
++(*exp); |
(*fraction) >>= 1; |
}; |
if (((*exp) >= FLOAT32_MAX_EXPONENT ) || ((*exp) < 0)) { |
/* overflow - set infinity as result */ |
(*exp) = FLOAT32_MAX_EXPONENT; |
(*fraction) = 0; |
return; |
} |
return; |
} |
/** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 62. bit |
* @param exp exponent |
* @param fraction part with hidden bit shifted to 62. bit |
*/ |
void roundFloat64(__s32 *exp, __u64 *fraction) |
{ |
/* rounding - if first bit after fraction is set then round up */ |
(*fraction) += (0x1 << 9); |
if ((*fraction) & (FLOAT64_HIDDEN_BIT_MASK << 11)) { |
/* rounding overflow */ |
++(*exp); |
(*fraction) >>= 1; |
}; |
if (((*exp) >= FLOAT64_MAX_EXPONENT ) || ((*exp) < 0)) { |
/* overflow - set infinity as result */ |
(*exp) = FLOAT64_MAX_EXPONENT; |
(*fraction) = 0; |
return; |
} |
return; |
} |
//uspace/trunk/softfloat/arch/ia32/include/functions.h |
---|
45,4 → 45,22 |
#define float64_to_ulong(X) float64_to_uint32(X); |
#define float64_to_ulonglong(X) float64_to_uint64(X); |
#define int_to_float32(X) int32_to_float32(X); |
#define long_to_float32(X) int32_to_float32(X); |
#define longlong_to_float32(X) int64_to_float32(X); |
#define int_to_float64(X) int32_to_float64(X); |
#define long_to_float64(X) int32_to_float64(X); |
#define longlong_to_float64(X) int64_to_float64(X); |
#define uint_to_float32(X) uint32_to_float32(X); |
#define ulong_to_float32(X) uint32_to_float32(X); |
#define ulonglong_to_float32(X) uint64_to_float32(X); |
#define uint_to_float64(X) uint32_to_float64(X); |
#define ulong_to_float64(X) uint32_to_float64(X); |
#define ulonglong_to_float64(X) uint64_to_float64(X); |
#endif |