Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1030 → Rev 1031

//uspace/trunk/softfloat/generic/softfloat.c
38,8 → 38,6
#include<comparison.h>
#include<other.h>
 
#include<arch.h>
#include<types.h>
#include<functions.h>
 
/* Arithmetic functions */
484,13 → 482,3
/* TODO: */
}
 
float __mulsc3(float a, float b, float c, float d)
{
/* TODO: */
}
 
float __divsc3(float a, float b, float c, float d)
{
/* TODO: */
}
 
//uspace/trunk/softfloat/generic/div.c
37,8 → 37,8
float32 divFloat32(float32 a, float32 b)
{
float32 result;
__s32 aexp, bexp, cexp;
__u64 afrac, bfrac, cfrac;
int32_t aexp, bexp, cexp;
uint64_t afrac, bfrac, cfrac;
result.parts.sign = a.parts.sign ^ b.parts.sign;
180,7 → 180,7
}
} else {
result.parts.exp = (__u32)cexp;
result.parts.exp = (uint32_t)cexp;
}
result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK));
191,9 → 191,9
float64 divFloat64(float64 a, float64 b)
{
float64 result;
__s64 aexp, bexp, cexp;
__u64 afrac, bfrac, cfrac;
__u64 remlo, remhi;
int64_t aexp, bexp, cexp;
uint64_t afrac, bfrac, cfrac;
uint64_t remlo, remhi;
result.parts.sign = a.parts.sign ^ b.parts.sign;
306,7 → 306,7
remhi = afrac - remhi - ( remlo > 0);
remlo = - remlo;
while ((__s64) remhi < 0) {
while ((int64_t) remhi < 0) {
cfrac--;
remlo += bfrac;
remhi += ( remlo < bfrac );
320,11 → 320,11
 
}
 
__u64 divFloat64estim(__u64 a, __u64 b)
uint64_t divFloat64estim(uint64_t a, uint64_t b)
{
__u64 bhi;
__u64 remhi, remlo;
__u64 result;
uint64_t bhi;
uint64_t remhi, remlo;
uint64_t result;
if ( b <= a ) {
return 0xFFFFFFFFFFFFFFFFull;
338,7 → 338,7
remlo = - remlo;
 
b <<= 32;
while ( (__s64) remhi < 0 ) {
while ( (int64_t) remhi < 0 ) {
result -= 0x1ll << 32;
remlo += b;
remhi += bhi + ( remlo < b );
//uspace/trunk/softfloat/generic/conversion.c
34,7 → 34,7
float64 convertFloat32ToFloat64(float32 a)
{
float64 result;
__u64 frac;
uint64_t frac;
result.parts.sign = a.parts.sign;
result.parts.fraction = a.parts.fraction;
73,8 → 73,8
float32 convertFloat64ToFloat32(float64 a)
{
float32 result;
__s32 exp;
__u64 frac;
int32_t exp;
uint64_t frac;
result.parts.sign = a.parts.sign;
83,7 → 83,7
result.parts.exp = 0xFF;
if (isFloat64SigNaN(a)) {
result.parts.fraction = 0x800000; /* set first bit of fraction nonzero */
result.parts.fraction = 0x400000; /* set first bit of fraction nonzero */
return result;
}
144,9 → 144,9
* @param a floating point number in normalized form (no NaNs or Inf are checked )
* @return unsigned integer
*/
static __u32 _float32_to_uint32_helper(float32 a)
static uint32_t _float32_to_uint32_helper(float32 a)
{
__u32 frac;
uint32_t frac;
if (a.parts.exp < FLOAT32_BIAS) {
/*TODO: rounding*/
172,7 → 172,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__u32 float32_to_uint32(float32 a)
uint32_t float32_to_uint32(float32 a)
{
if (isFloat32NaN(a)) {
return MAX_UINT32;
192,7 → 192,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__s32 float32_to_int32(float32 a)
int32_t float32_to_int32(float32 a)
{
if (isFloat32NaN(a)) {
return MAX_INT32;
212,9 → 212,9
* @param a floating point number in normalized form (no NaNs or Inf are checked )
* @return unsigned integer
*/
static __u64 _float64_to_uint64_helper(float64 a)
static uint64_t _float64_to_uint64_helper(float64 a)
{
__u64 frac;
uint64_t frac;
if (a.parts.exp < FLOAT64_BIAS) {
/*TODO: rounding*/
240,7 → 240,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__u64 float64_to_uint64(float64 a)
uint64_t float64_to_uint64(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_UINT64;
260,7 → 260,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__s64 float64_to_int64(float64 a)
int64_t float64_to_int64(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_INT64;
283,9 → 283,9
* @param a floating point number in normalized form (no NaNs or Inf are checked )
* @return unsigned integer
*/
static __u64 _float32_to_uint64_helper(float32 a)
static uint64_t _float32_to_uint64_helper(float32 a)
{
__u64 frac;
uint64_t frac;
if (a.parts.exp < FLOAT32_BIAS) {
/*TODO: rounding*/
311,7 → 311,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__u64 float32_to_uint64(float32 a)
uint64_t float32_to_uint64(float32 a)
{
if (isFloat32NaN(a)) {
return MAX_UINT64;
331,7 → 331,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__s64 float32_to_int64(float32 a)
int64_t float32_to_int64(float32 a)
{
if (isFloat32NaN(a)) {
return MAX_INT64;
351,7 → 351,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__u32 float64_to_uint32(float64 a)
uint32_t float64_to_uint32(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_UINT32;
364,7 → 364,7
return MAX_UINT32;
}
return (__u32)_float64_to_uint64_helper(a);
return (uint32_t)_float64_to_uint64_helper(a);
}
 
/* Convert float64 to signed int32
371,7 → 371,7
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
__s32 float64_to_int32(float64 a)
int32_t float64_to_int32(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_INT32;
383,7 → 383,7
}
return MAX_INT32;
}
return (__s32)_float64_to_uint64_helper(a);
return (int32_t)_float64_to_uint64_helper(a);
}
 
/** Convert unsigned integer to float32
390,10 → 390,10
*
*
*/
float32 uint32_to_float32(__u32 i)
float32 uint32_to_float32(uint32_t i)
{
int counter;
__s32 exp;
int32_t exp;
float32 result;
result.parts.sign = 0;
422,14 → 422,14
return result;
}
 
float32 int32_to_float32(__s32 i)
float32 int32_to_float32(int32_t i)
{
float32 result;
 
if (i < 0) {
result = uint32_to_float32((__u32)(-i));
result = uint32_to_float32((uint32_t)(-i));
} else {
result = uint32_to_float32((__u32)i);
result = uint32_to_float32((uint32_t)i);
}
result.parts.sign = i < 0;
438,10 → 438,11
}
 
 
float32 uint64_to_float32(__u64 i)
float32 uint64_to_float32(uint64_t i)
{
int counter;
__s32 exp;
int32_t exp;
int32_t j;
float32 result;
result.parts.sign = 0;
462,22 → 463,23
} else {
i >>= 1 + 32 - counter;
}
j = (uint32_t)i;
roundFloat32(&exp, &j);
 
roundFloat32(&exp, &i);
 
result.parts.fraction = i >> 7;
result.parts.fraction = j >> 7;
result.parts.exp = exp;
return result;
}
 
float32 int64_to_float32(__s64 i)
float32 int64_to_float32(int64_t i)
{
float32 result;
 
if (i < 0) {
result = uint64_to_float32((__u64)(-i));
result = uint64_to_float32((uint64_t)(-i));
} else {
result = uint64_to_float32((__u64)i);
result = uint64_to_float32((uint64_t)i);
}
result.parts.sign = i < 0;
489,12 → 491,12
*
*
*/
float64 uint32_to_float64(__u32 i)
float64 uint32_to_float64(uint32_t i)
{
int counter;
__s32 exp;
int32_t exp;
float64 result;
__u64 frac;
uint64_t frac;
result.parts.sign = 0;
result.parts.fraction = 0;
519,14 → 521,14
return result;
}
 
float64 int32_to_float64(__s32 i)
float64 int32_to_float64(int32_t i)
{
float64 result;
 
if (i < 0) {
result = uint32_to_float64((__u32)(-i));
result = uint32_to_float64((uint32_t)(-i));
} else {
result = uint32_to_float64((__u32)i);
result = uint32_to_float64((uint32_t)i);
}
result.parts.sign = i < 0;
535,10 → 537,10
}
 
 
float64 uint64_to_float64(__u64 i)
float64 uint64_to_float64(uint64_t i)
{
int counter;
__s32 exp;
int32_t exp;
float64 result;
result.parts.sign = 0;
566,14 → 568,14
return result;
}
 
float64 int64_to_float64(__s64 i)
float64 int64_to_float64(int64_t i)
{
float64 result;
 
if (i < 0) {
result = uint64_to_float64((__u64)(-i));
result = uint64_to_float64((uint64_t)(-i));
} else {
result = uint64_to_float64((__u64)i);
result = uint64_to_float64((uint64_t)i);
}
result.parts.sign = i < 0;
//uspace/trunk/softfloat/generic/add.c
35,7 → 35,7
float32 addFloat32(float32 a, float32 b)
{
int expdiff;
__u32 exp1, exp2,frac1, frac2;
uint32_t exp1, exp2,frac1, frac2;
expdiff = a.parts.exp - b.parts.exp;
if (expdiff < 0) {
143,8 → 143,8
float64 addFloat64(float64 a, float64 b)
{
int expdiff;
__u32 exp1, exp2;
__u64 frac1, frac2;
uint32_t exp1, exp2;
uint64_t frac1, frac2;
expdiff = ((int )a.parts.exp) - b.parts.exp;
if (expdiff < 0) {
//uspace/trunk/softfloat/generic/common.c
56,7 → 56,7
* @param cfrac fraction shifted 10 places left with added hidden bit
* @return valied float64
*/
float64 finishFloat64(__s32 cexp, __u64 cfrac, char sign)
float64 finishFloat64(int32_t cexp, uint64_t cfrac, char sign)
{
float64 result;
 
108,7 → 108,7
return result;
}
 
result.parts.exp = (__u32)cexp;
result.parts.exp = (uint32_t)cexp;
result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2 ) ) & (~FLOAT64_HIDDEN_BIT_MASK));
118,7 → 118,7
/** Counts leading zeroes in 64bit unsigned integer
* @param i
*/
int countZeroes64(__u64 i)
int countZeroes64(uint64_t i)
{
int j;
for (j =0; j < 64; j += 8) {
133,7 → 133,7
/** Counts leading zeroes in 32bit unsigned integer
* @param i
*/
int countZeroes32(__u32 i)
int countZeroes32(uint32_t i)
{
int j;
for (j =0; j < 32; j += 8) {
148,7 → 148,7
/** Counts leading zeroes in byte
* @param i
*/
int countZeroes8(__u8 i)
int countZeroes8(uint8_t i)
{
return zeroTable[i];
}
157,7 → 157,7
* @param exp exponent
* @param fraction part with hidden bit shifted to 30. bit
*/
void roundFloat32(__s32 *exp, __u32 *fraction)
void roundFloat32(int32_t *exp, uint32_t *fraction)
{
/* rounding - if first bit after fraction is set then round up */
(*fraction) += (0x1 << 6);
182,7 → 182,7
* @param exp exponent
* @param fraction part with hidden bit shifted to 62. bit
*/
void roundFloat64(__s32 *exp, __u64 *fraction)
void roundFloat64(int32_t *exp, uint64_t *fraction)
{
/* rounding - if first bit after fraction is set then round up */
(*fraction) += (0x1 << 9);
//uspace/trunk/softfloat/generic/sub.c
35,7 → 35,7
float32 subFloat32(float32 a, float32 b)
{
int expdiff;
__u32 exp1, exp2, frac1, frac2;
uint32_t exp1, exp2, frac1, frac2;
float32 result;
 
result.f = 0;
146,8 → 146,8
float64 subFloat64(float64 a, float64 b)
{
int expdiff;
__u32 exp1, exp2;
__u64 frac1, frac2;
uint32_t exp1, exp2;
uint64_t frac1, frac2;
float64 result;
 
result.d = 0;
//uspace/trunk/softfloat/generic/mul.c
37,8 → 37,8
float32 mulFloat32(float32 a, float32 b)
{
float32 result;
__u64 frac1, frac2;
__s32 exp;
uint64_t frac1, frac2;
int32_t exp;
 
result.parts.sign = a.parts.sign ^ b.parts.sign;
173,8 → 173,8
float64 mulFloat64(float64 a, float64 b)
{
float64 result;
__u64 frac1, frac2;
__s32 exp;
uint64_t frac1, frac2;
int32_t exp;
 
result.parts.sign = a.parts.sign ^ b.parts.sign;
257,10 → 257,10
* @param lo lower part from result
* @param hi higher part of result
*/
void mul64integers(__u64 a,__u64 b, __u64 *lo, __u64 *hi)
void mul64integers(uint64_t a,uint64_t b, uint64_t *lo, uint64_t *hi)
{
__u64 low, high, middle1, middle2;
__u32 alow, blow;
uint64_t low, high, middle1, middle2;
uint32_t alow, blow;
 
alow = a & 0xFFFFFFFF;
blow = b & 0xFFFFFFFF;
268,13 → 268,13
a >>= 32;
b >>= 32;
low = ((__u64)alow) * blow;
low = ((uint64_t)alow) * blow;
middle1 = a * blow;
middle2 = alow * b;
high = a * b;
 
middle1 += middle2;
high += (((__u64)(middle1 < middle2)) << 32) + (middle1 >> 32);
high += (((uint64_t)(middle1 < middle2)) << 32) + (middle1 >> 32);
middle1 <<= 32;
low += middle1;
high += (low < middle1);