/uspace/trunk/softfloat/include/sftypes.h |
---|
29,6 → 29,9 |
#ifndef __SFTYPES_H__ |
#define __SFTYPES_H__ |
#include <types.h> |
#include <arch.h> |
typedef union { |
float f; |
__u32 binary; |
/uspace/trunk/softfloat/include/softfloat.h |
---|
111,6 → 111,21 |
long double __floattitf(long long i); |
long double __floattixf(long long i); |
float __floatunsisf(unsigned int i); |
double __floatunsidf(unsigned int i); |
long double __floatunsitf(unsigned int i); |
long double __floatunsixf(unsigned int i); |
float __floatundisf(unsigned long i); |
double __floatundidf(unsigned long i); |
long double __floatunditf(unsigned long i); |
long double __floatundixf(unsigned long i); |
float __floatuntisf(unsigned long long i); |
double __floatuntidf(unsigned long long i); |
long double __floatuntitf(unsigned long long i); |
long double __floatuntixf(unsigned long long i); |
int __cmpsf2(float a, float b); |
int __cmpdf2(double a, double b); |
int __cmptf2(long double a, long double b); |
/uspace/trunk/softfloat/generic/softfloat.c |
---|
38,6 → 38,10 |
#include<comparison.h> |
#include<other.h> |
#include<arch.h> |
#include<types.h> |
#include<functions.h> |
/* Arithmetic functions */ |
float __addsf3(float a, float b) |
160,7 → 164,108 |
return convertFloat64ToFloat32(da).f; |
} |
int __fixsfsi(float a) |
{ |
float32 fa; |
fa.f = a; |
return float32_to_int(fa); |
} |
int __fixdfsi(double a) |
{ |
} |
long __fixsfdi(float a) |
{ |
float32 fa; |
fa.f = a; |
return float32_to_long(fa); |
} |
long __fixdfdi(double a) |
{ |
} |
long long __fixsfti(float a) |
{ |
} |
long long __fixdfti(double a) |
{ |
} |
unsigned int __fixunssfsi(float a) |
{ |
float32 fa; |
fa.f = a; |
return float32_to_uint(fa); |
} |
unsigned int __fixunsdfsi(double a) |
{ |
} |
unsigned long __fixunssfdi(float a) |
{ |
float32 fa; |
fa.f = a; |
return float32_to_long(fa); |
} |
unsigned long __fixunsdfdi(double a) |
{ |
} |
unsigned long long __fixunssfti(float a) |
{ |
} |
unsigned long long __fixunsdfti(double a) |
{ |
} |
float __floatsisf(int i) |
{ |
} |
double __floatsidf(int i) |
{ |
} |
float __floatdisf(long i) |
{ |
} |
double __floatdidf(long i) |
{ |
} |
float __floattisf(long long i) |
{ |
} |
double __floattidf(long long i) |
{ |
} |
float __floatunsisf(unsigned int i) |
{ |
} |
double __floatunsidf(unsigned int i) |
{ |
} |
float __floatundisf(unsigned long i) |
{ |
} |
double __floatundidf(unsigned long i) |
{ |
} |
float __floatuntisf(unsigned long long i) |
{ |
} |
double __floatuntidf(unsigned long long i) |
{ |
} |
/* Comparison functions */ |
/* Comparison functions */ |
/* a<b .. -1 |
* a=b .. 0 |
/uspace/trunk/softfloat/generic/conversion.c |
---|
28,6 → 28,7 |
#include "sftypes.h" |
#include "conversion.h" |
#include "comparison.h" |
float64 convertFloat32ToFloat64(float32 a) |
{ |
66,7 → 67,7 |
return result; |
}; |
} |
float32 convertFloat64ToFloat32(float64 a) |
{ |
135,5 → 136,75 |
result.parts.exp = exp; |
result.parts.fraction = a.parts.fraction >> (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE); |
return result; |
}; |
} |
/** Helping procedure for converting float32 to uint32 |
* @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) |
{ |
__u32 frac; |
if (a.parts.exp < FLOAT32_BIAS) { |
/*TODO: rounding*/ |
return 0; |
} |
frac = a.parts.fraction; |
frac |= FLOAT32_HIDDEN_BIT_MASK; |
/* shift fraction to left so hidden bit will be the most significant bit */ |
frac <<= 32 - FLOAT32_FRACTION_SIZE - 1; |
frac >>= 32 - (a.parts.exp - FLOAT32_BIAS) - 1; |
if ((a.parts.sign == 1) && (frac != 0)) { |
frac = ~frac; |
++frac; |
} |
return frac; |
} |
/* Convert float to unsigned int32 |
* 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) |
{ |
if (isFloat32NaN(a)) { |
return MAX_UINT32; |
} |
if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { |
if (a.parts.sign) { |
return MIN_UINT32; |
} |
return MAX_UINT32; |
} |
return _float32_to_uint32_helper(a); |
} |
/* Convert float to signed int32 |
* 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) |
{ |
if (isFloat32NaN(a)) { |
return MAX_INT32; |
} |
if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { |
if (a.parts.sign) { |
return MIN_INT32; |
} |
return MAX_INT32; |
} |
return _float32_to_uint32_helper(a); |
} |
/uspace/trunk/softfloat/arch/ia32/include/arch.h |
---|
0,0 → 1,34 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __ia32_ARCH_H__ |
#define __ia32_ARCH_H__ |
#define __LITTLE_ENDIAN__ |
#endif |
/uspace/trunk/softfloat/arch/ia32/include/types.h |
---|
0,0 → 1,57 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __ia32_TYPES_H__ |
#define __ia32_TYPES_H__ |
typedef char __s8; |
typedef short __s16; |
typedef long __s32; |
typedef long long __s64; |
typedef unsigned char __u8; |
typedef unsigned short __u16; |
typedef unsigned long __u32; |
typedef unsigned long long __u64; |
#define MAX_INT32 (0x7FFFFFFF) |
#define MIN_INT32 (0x80000000) |
#define MAX_UINT32 (0xFFFFFFFF) |
#define MIN_UINT32 (0) |
#define MAX_INT64 (0x7FFFFFFFFFFFFFFFll) |
#define MIN_INT64 (0x8000000000000000ll) |
#define MAX_UINT64 (0xFFFFFFFFFFFFFFFll) |
#define MIN_UINT64 (0ll) |
#endif |
/uspace/trunk/softfloat/arch/ia32/include/functions.h |
---|
0,0 → 1,44 |
/* |
* Copyright (C) 2006 Josef Cejka |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
#ifndef __ia32_FUNCTIONS_H__ |
#define __ia32_FUNCTIONS_H__ |
#define float32_to_int(X) float32_to_int32(X); |
#define float32_to_long(X) float32_to_int32(X); |
#define float32_to_longlong(X) float32_to_int64(X); |
#define float64_to_int(X) float64_to_int32(X); |
#define float64_to_long(X) float64_to_int32(X); |
#define float64_to_longlong(X) float64_to_int64(X); |
#define float32_to_uint(X) float32_to_uint32(X); |
#define float32_to_ulong(X) float32_to_uint32(X); |
#define float32_to_ulonglong(X) float32_to_uint64(X); |
#endif |