Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 1963 → Rev 1968

/tags/0.1.1/uspace/softfloat/Makefile
0,0 → 1,81
#
# Copyright (C) 2005 Martin Decky
# 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.
#
 
## Common compiler flags
#
 
LIBC_PREFIX = ../libc
## Setup toolchain
#
 
include $(LIBC_PREFIX)/Makefile.toolchain
 
CFLAGS +=-Iinclude -Iarch/$(ARCH)/include/
 
## Sources
#
 
GENERIC_SOURCES = \
generic/add.c \
generic/common.c \
generic/comparison.c \
generic/conversion.c \
generic/div.c \
generic/mul.c \
generic/other.c \
generic/softfloat.c \
generic/sub.c
 
ARCH_SOURCES =
 
GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
 
.PHONY: all clean depend
 
all: libsoftfloat.a
 
-include Makefile.depend
 
clean:
-rm -f libsoftfloat.a Makefile.depend
find generic/ -name '*.o' -follow -exec rm \{\} \;
 
depend:
-makedepend $(DEFS) $(CFLAGS) -f - $(GENERIC_SOURCES) > Makefile.depend 2> /dev/null
 
libsoftfloat.a: depend $(ARCH_OBJECTS) $(GENERIC_OBJECTS)
$(AR) rc libsoftfloat.a $(ARCH_OBJECTS) $(GENERIC_OBJECTS)
 
%.o: %.S
$(CC) $(DEFS) $(AFLAGS) $(CFLAGS) -D__ASM__ -c $< -o $@
 
%.o: %.s
$(AS) $(AFLAGS) $< -o $@
 
%.o: %.c
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@
/tags/0.1.1/uspace/softfloat/generic/softfloat.c
0,0 → 1,487
/*
* Copyright (C) 2005 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.
*/
 
#include<softfloat.h>
#include<sftypes.h>
 
#include<add.h>
#include<sub.h>
#include<mul.h>
#include<div.h>
 
#include<conversion.h>
#include<comparison.h>
#include<other.h>
 
#include<functions.h>
 
/* Arithmetic functions */
 
float __addsf3(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if (fa.parts.sign != fb.parts.sign) {
if (fa.parts.sign) {
fa.parts.sign = 0;
return subFloat32(fb, fa).f;
};
fb.parts.sign = 0;
return subFloat32(fa, fb).f;
}
return addFloat32(fa, fb).f;
}
 
double __adddf3(double a, double b)
{
float64 da, db;
da.d = a;
db.d = b;
if (da.parts.sign != db.parts.sign) {
if (da.parts.sign) {
da.parts.sign = 0;
return subFloat64(db, da).d;
};
db.parts.sign = 0;
return subFloat64(da, db).d;
}
return addFloat64(da, db).d;
}
 
float __subsf3(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if (fa.parts.sign != fb.parts.sign) {
fb.parts.sign = !fb.parts.sign;
return addFloat32(fa, fb).f;
}
return subFloat32(fa, fb).f;
}
 
double __subdf3(double a, double b)
{
float64 da, db;
da.d = a;
db.d = b;
if (da.parts.sign != db.parts.sign) {
db.parts.sign = !db.parts.sign;
return addFloat64(da, db).d;
}
return subFloat64(da, db).d;
}
 
float __mulsf3(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
return mulFloat32(fa, fb).f;
}
 
double __muldf3(double a, double b)
{
float64 da, db;
da.d = a;
db.d = b;
return mulFloat64(da, db).d;
}
 
float __divsf3(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
return divFloat32(fa, fb).f;
}
 
double __divdf3(double a, double b)
{
float64 da, db;
da.d = a;
db.d = b;
return divFloat64(da, db).d;
}
 
float __negsf2(float a)
{
float32 fa;
fa.f = a;
fa.parts.sign = !fa.parts.sign;
return fa.f;
}
 
double __negdf2(double a)
{
float64 fa;
fa.d = a;
fa.parts.sign = !fa.parts.sign;
return fa.d;
}
 
/* Conversion functions */
 
double __extendsfdf2(float a)
{
float32 fa;
fa.f = a;
return convertFloat32ToFloat64(fa).d;
}
 
float __truncdfsf2(double a)
{
float64 da;
da.d = a;
return convertFloat64ToFloat32(da).f;
}
 
int __fixsfsi(float a)
{
float32 fa;
fa.f = a;
return float32_to_int(fa);
}
int __fixdfsi(double a)
{
float64 da;
da.d = a;
return float64_to_int(da);
}
long __fixsfdi(float a)
{
float32 fa;
fa.f = a;
return float32_to_long(fa);
}
long __fixdfdi(double a)
{
float64 da;
da.d = a;
return float64_to_long(da);
}
long long __fixsfti(float a)
{
float32 fa;
fa.f = a;
return float32_to_longlong(fa);
}
long long __fixdfti(double a)
{
float64 da;
da.d = a;
return float64_to_longlong(da);
}
 
unsigned int __fixunssfsi(float a)
{
float32 fa;
fa.f = a;
return float32_to_uint(fa);
}
unsigned int __fixunsdfsi(double a)
{
float64 da;
da.d = a;
return float64_to_uint(da);
}
unsigned long __fixunssfdi(float a)
{
float32 fa;
fa.f = a;
return float32_to_ulong(fa);
}
unsigned long __fixunsdfdi(double a)
{
float64 da;
da.d = a;
return float64_to_ulong(da);
}
unsigned long long __fixunssfti(float a)
{
float32 fa;
fa.f = a;
return float32_to_ulonglong(fa);
}
unsigned long long __fixunsdfti(double a)
{
float64 da;
da.d = a;
return float64_to_ulonglong(da);
}
float __floatsisf(int i)
{
float32 fa;
fa = int_to_float32(i);
return fa.f;
}
double __floatsidf(int i)
{
float64 da;
da = int_to_float64(i);
return da.d;
}
float __floatdisf(long i)
{
float32 fa;
fa = long_to_float32(i);
return fa.f;
}
double __floatdidf(long i)
{
float64 da;
da = long_to_float64(i);
return da.d;
}
float __floattisf(long long i)
{
float32 fa;
fa = longlong_to_float32(i);
return fa.f;
}
double __floattidf(long long i)
{
float64 da;
da = longlong_to_float64(i);
return da.d;
}
 
float __floatunsisf(unsigned int i)
{
float32 fa;
fa = uint_to_float32(i);
return fa.f;
}
double __floatunsidf(unsigned int i)
{
float64 da;
da = uint_to_float64(i);
return da.d;
}
float __floatundisf(unsigned long i)
{
float32 fa;
fa = ulong_to_float32(i);
return fa.f;
}
double __floatundidf(unsigned long i)
{
float64 da;
da = ulong_to_float64(i);
return da.d;
}
float __floatuntisf(unsigned long long i)
{
float32 fa;
fa = ulonglong_to_float32(i);
return fa.f;
}
double __floatuntidf(unsigned long long i)
{
float64 da;
da = ulonglong_to_float64(i);
return da.d;
}
 
/* Comparison functions */
/* Comparison functions */
 
/* a<b .. -1
* a=b .. 0
* a>b .. 1
* */
 
int __cmpsf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
return 1; /* no special constant for unordered - maybe signaled? */
};
 
if (isFloat32eq(fa, fb)) {
return 0;
};
if (isFloat32lt(fa, fb)) {
return -1;
};
return 1;
}
 
int __unordsf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
return ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) );
}
 
/**
* @return zero, if neither argument is a NaN and are equal
* */
int __eqsf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
/* TODO: sigNaNs*/
return 1;
};
return isFloat32eq(fa, fb) - 1;
}
 
/* strange behavior, but it was in gcc documentation */
int __nesf2(float a, float b)
{
return __eqsf2(a, b);
}
 
/* return value >= 0 if a>=b and neither is NaN */
int __gesf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
/* TODO: sigNaNs*/
return -1;
};
if (isFloat32eq(fa, fb)) {
return 0;
};
if (isFloat32gt(fa, fb)) {
return 1;
};
return -1;
}
 
/** Return negative value, if a<b and neither is NaN*/
int __ltsf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
/* TODO: sigNaNs*/
return 1;
};
if (isFloat32lt(fa, fb)) {
return -1;
};
return 0;
}
 
/* return value <= 0 if a<=b and neither is NaN */
int __lesf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
/* TODO: sigNaNs*/
return 1;
};
if (isFloat32eq(fa, fb)) {
return 0;
};
if (isFloat32lt(fa, fb)) {
return -1;
};
return 1;
}
 
/** Return positive value, if a>b and neither is NaN*/
int __gtsf2(float a, float b)
{
float32 fa, fb;
fa.f = a;
fb.f = b;
if ( (isFloat32NaN(fa)) || (isFloat32NaN(fb)) ) {
/* TODO: sigNaNs*/
return -1;
};
if (isFloat32gt(fa, fb)) {
return 1;
};
return 0;
}
 
/* Other functions */
 
float __powisf2(float a, int b)
{
/* TODO: */
float32 fa;
fa.binary = FLOAT32_NAN;
return fa.f;
}
 
/tags/0.1.1/uspace/softfloat/generic/conversion.c
0,0 → 1,586
/*
* Copyright (C) 2005 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.
*/
 
#include "sftypes.h"
#include "conversion.h"
#include "comparison.h"
#include "common.h"
 
float64 convertFloat32ToFloat64(float32 a)
{
float64 result;
uint64_t frac;
result.parts.sign = a.parts.sign;
result.parts.fraction = a.parts.fraction;
result.parts.fraction <<= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE );
if ((isFloat32Infinity(a))||(isFloat32NaN(a))) {
result.parts.exp = 0x7FF;
/* TODO; check if its correct for SigNaNs*/
return result;
};
result.parts.exp = a.parts.exp + ( (int)FLOAT64_BIAS - FLOAT32_BIAS );
if (a.parts.exp == 0) {
/* normalize denormalized numbers */
 
if (result.parts.fraction == 0ll) { /* fix zero */
result.parts.exp = 0ll;
return result;
}
frac = result.parts.fraction;
while (!(frac & (0x10000000000000ll))) {
frac <<= 1;
--result.parts.exp;
};
++result.parts.exp;
result.parts.fraction = frac;
};
return result;
}
 
float32 convertFloat64ToFloat32(float64 a)
{
float32 result;
int32_t exp;
uint64_t frac;
result.parts.sign = a.parts.sign;
if (isFloat64NaN(a)) {
result.parts.exp = 0xFF;
if (isFloat64SigNaN(a)) {
result.parts.fraction = 0x400000; /* set first bit of fraction nonzero */
return result;
}
result.parts.fraction = 0x1; /* fraction nonzero but its first bit is zero */
return result;
};
 
if (isFloat64Infinity(a)) {
result.parts.fraction = 0;
result.parts.exp = 0xFF;
return result;
};
 
exp = (int)a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS;
if (exp >= 0xFF) {
/*FIXME: overflow*/
result.parts.fraction = 0;
result.parts.exp = 0xFF;
return result;
} else if (exp <= 0 ) {
/* underflow or denormalized */
result.parts.exp = 0;
exp *= -1;
if (exp > FLOAT32_FRACTION_SIZE ) {
/* FIXME: underflow */
result.parts.fraction = 0;
return result;
};
/* denormalized */
frac = a.parts.fraction;
frac |= 0x10000000000000ll; /* denormalize and set hidden bit */
frac >>= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1);
while (exp > 0) {
--exp;
frac >>= 1;
};
result.parts.fraction = frac;
return result;
};
 
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 uint32_t _float32_to_uint32_helper(float32 a)
{
uint32_t 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
*/
uint32_t 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
*/
int32_t 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);
}
 
 
/** Helping procedure for converting float64 to uint64
* @param a floating point number in normalized form (no NaNs or Inf are checked )
* @return unsigned integer
*/
static uint64_t _float64_to_uint64_helper(float64 a)
{
uint64_t frac;
if (a.parts.exp < FLOAT64_BIAS) {
/*TODO: rounding*/
return 0;
}
frac = a.parts.fraction;
frac |= FLOAT64_HIDDEN_BIT_MASK;
/* shift fraction to left so hidden bit will be the most significant bit */
frac <<= 64 - FLOAT64_FRACTION_SIZE - 1;
 
frac >>= 64 - (a.parts.exp - FLOAT64_BIAS) - 1;
if ((a.parts.sign == 1) && (frac != 0)) {
frac = ~frac;
++frac;
}
return frac;
}
 
/* Convert float to unsigned int64
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
uint64_t float64_to_uint64(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_UINT64;
}
if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
if (a.parts.sign) {
return MIN_UINT64;
}
return MAX_UINT64;
}
return _float64_to_uint64_helper(a);
}
 
/* Convert float to signed int64
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
int64_t float64_to_int64(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_INT64;
}
if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
if (a.parts.sign) {
return MIN_INT64;
}
return MAX_INT64;
}
return _float64_to_uint64_helper(a);
}
 
 
 
 
 
/** Helping procedure for converting float32 to uint64
* @param a floating point number in normalized form (no NaNs or Inf are checked )
* @return unsigned integer
*/
static uint64_t _float32_to_uint64_helper(float32 a)
{
uint64_t 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 <<= 64 - FLOAT32_FRACTION_SIZE - 1;
 
frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1;
if ((a.parts.sign == 1) && (frac != 0)) {
frac = ~frac;
++frac;
}
return frac;
}
 
/* Convert float to unsigned int64
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
uint64_t float32_to_uint64(float32 a)
{
if (isFloat32NaN(a)) {
return MAX_UINT64;
}
if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
if (a.parts.sign) {
return MIN_UINT64;
}
return MAX_UINT64;
}
return _float32_to_uint64_helper(a);
}
 
/* Convert float to signed int64
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
int64_t float32_to_int64(float32 a)
{
if (isFloat32NaN(a)) {
return MAX_INT64;
}
if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
if (a.parts.sign) {
return (MIN_INT64);
}
return MAX_INT64;
}
return _float32_to_uint64_helper(a);
}
 
 
/* Convert float64 to unsigned int32
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
uint32_t float64_to_uint32(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_UINT32;
}
if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
if (a.parts.sign) {
return MIN_UINT32;
}
return MAX_UINT32;
}
return (uint32_t)_float64_to_uint64_helper(a);
}
 
/* Convert float64 to signed int32
* FIXME: Im not sure what to return if overflow/underflow happens
* - now its the biggest or the smallest int
*/
int32_t float64_to_int32(float64 a)
{
if (isFloat64NaN(a)) {
return MAX_INT32;
}
if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
if (a.parts.sign) {
return MIN_INT32;
}
return MAX_INT32;
}
return (int32_t)_float64_to_uint64_helper(a);
}
 
/** Convert unsigned integer to float32
*
*
*/
float32 uint32_to_float32(uint32_t i)
{
int counter;
int32_t 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(int32_t i)
{
float32 result;
 
if (i < 0) {
result = uint32_to_float32((uint32_t)(-i));
} else {
result = uint32_to_float32((uint32_t)i);
}
result.parts.sign = i < 0;
 
return result;
}
 
 
float32 uint64_to_float32(uint64_t i)
{
int counter;
int32_t exp;
uint32_t j;
float32 result;
result.parts.sign = 0;
result.parts.fraction = 0;
 
counter = countZeroes64(i);
 
exp = FLOAT32_BIAS + 64 - counter - 1;
if (counter == 64) {
result.binary = 0;
return result;
}
/* Shift all to the first 31 bits (31. will be hidden 1)*/
if (counter > 33) {
i <<= counter - 1 - 32;
} else {
i >>= 1 + 32 - counter;
}
j = (uint32_t)i;
roundFloat32(&exp, &j);
 
result.parts.fraction = j >> 7;
result.parts.exp = exp;
return result;
}
 
float32 int64_to_float32(int64_t i)
{
float32 result;
 
if (i < 0) {
result = uint64_to_float32((uint64_t)(-i));
} else {
result = uint64_to_float32((uint64_t)i);
}
result.parts.sign = i < 0;
 
return result;
}
 
/** Convert unsigned integer to float64
*
*
*/
float64 uint32_to_float64(uint32_t i)
{
int counter;
int32_t exp;
float64 result;
uint64_t frac;
result.parts.sign = 0;
result.parts.fraction = 0;
 
counter = countZeroes32(i);
 
exp = FLOAT64_BIAS + 32 - counter - 1;
if (counter == 32) {
result.binary = 0;
return result;
}
frac = i;
frac <<= counter + 32 - 1;
 
roundFloat64(&exp, &frac);
 
result.parts.fraction = frac >> 10;
result.parts.exp = exp;
 
return result;
}
 
float64 int32_to_float64(int32_t i)
{
float64 result;
 
if (i < 0) {
result = uint32_to_float64((uint32_t)(-i));
} else {
result = uint32_to_float64((uint32_t)i);
}
result.parts.sign = i < 0;
 
return result;
}
 
 
float64 uint64_to_float64(uint64_t i)
{
int counter;
int32_t exp;
float64 result;
result.parts.sign = 0;
result.parts.fraction = 0;
 
counter = countZeroes64(i);
 
exp = FLOAT64_BIAS + 64 - counter - 1;
if (counter == 64) {
result.binary = 0;
return result;
}
if (counter > 0) {
i <<= counter - 1;
} else {
i >>= 1;
}
 
roundFloat64(&exp, &i);
 
result.parts.fraction = i >> 10;
result.parts.exp = exp;
return result;
}
 
float64 int64_to_float64(int64_t i)
{
float64 result;
 
if (i < 0) {
result = uint64_to_float64((uint64_t)(-i));
} else {
result = uint64_to_float64((uint64_t)i);
}
result.parts.sign = i < 0;
 
return result;
}
 
 
/tags/0.1.1/uspace/softfloat/generic/comparison.c
0,0 → 1,123
/*
* Copyright (C) 2005 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.
*/
 
#include<sftypes.h>
#include<comparison.h>
 
inline int isFloat32NaN(float32 f)
{ /* NaN : exp = 0xff and nonzero fraction */
return ((f.parts.exp==0xFF)&&(f.parts.fraction));
}
 
inline int isFloat64NaN(float64 d)
{ /* NaN : exp = 0x7ff and nonzero fraction */
return ((d.parts.exp==0x7FF)&&(d.parts.fraction));
}
 
inline int isFloat32SigNaN(float32 f)
{ /* SigNaN : exp = 0xff fraction = 0xxxxx..x (binary), where at least one x is nonzero */
return ((f.parts.exp==0xFF)&&(f.parts.fraction<0x400000)&&(f.parts.fraction));
}
 
inline int isFloat64SigNaN(float64 d)
{ /* SigNaN : exp = 0x7ff fraction = 0xxxxx..x (binary), where at least one x is nonzero */
return ((d.parts.exp==0x7FF)&&(d.parts.fraction)&&(d.parts.fraction<0x8000000000000ll));
}
 
inline int isFloat32Infinity(float32 f)
{
return ((f.parts.exp==0xFF)&&(f.parts.fraction==0x0));
}
 
inline int isFloat64Infinity(float64 d)
{
return ((d.parts.exp==0x7FF)&&(d.parts.fraction==0x0));
}
 
inline int isFloat32Zero(float32 f)
{
return (((f.binary) & 0x7FFFFFFF) == 0);
}
 
inline int isFloat64Zero(float64 d)
{
return (((d.binary) & 0x7FFFFFFFFFFFFFFFll) == 0);
}
 
/**
* @return 1, if both floats are equal - but NaNs are not recognized
*/
inline int isFloat32eq(float32 a, float32 b)
{
return ((a.binary==b.binary)||(((a.binary| b.binary)&0x7FFFFFFF)==0)); /* a equals to b or both are zeros (with any sign) */
}
 
/**
* @return 1, if a<b - but NaNs are not recognized
*/
inline int isFloat32lt(float32 a, float32 b)
{
if (((a.binary| b.binary)&0x7FFFFFFF)==0) {
return 0; /* +- zeroes */
};
if ((a.parts.sign)&&(b.parts.sign)) {
/*if both are negative, smaller is that with greater binary value*/
return (a.binary>b.binary);
};
/* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/
a.parts.sign=!a.parts.sign;
b.parts.sign=!b.parts.sign;
return (a.binary<b.binary);
}
 
/**
* @return 1, if a>b - but NaNs are not recognized
*/
inline int isFloat32gt(float32 a, float32 b)
{
if (((a.binary| b.binary)&0x7FFFFFFF)==0) {
return 0; /* zeroes are equal with any sign */
};
if ((a.parts.sign)&&(b.parts.sign)) {
/*if both are negative, greater is that with smaller binary value*/
return (a.binary<b.binary);
};
/* lets negate signs - now will be positive numbers allways bigger than negative (first bit will be set for unsigned integer comparison)*/
a.parts.sign=!a.parts.sign;
b.parts.sign=!b.parts.sign;
return (a.binary>b.binary);
}
 
 
 
/tags/0.1.1/uspace/softfloat/generic/div.c
0,0 → 1,356
/*
* Copyright (C) 2005 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.
*/
 
#include<sftypes.h>
#include<add.h>
#include<div.h>
#include<comparison.h>
#include<mul.h>
#include<common.h>
 
 
float32 divFloat32(float32 a, float32 b)
{
float32 result;
int32_t aexp, bexp, cexp;
uint64_t afrac, bfrac, cfrac;
result.parts.sign = a.parts.sign ^ b.parts.sign;
if (isFloat32NaN(a)) {
if (isFloat32SigNaN(a)) {
/*FIXME: SigNaN*/
}
/*NaN*/
return a;
}
if (isFloat32NaN(b)) {
if (isFloat32SigNaN(b)) {
/*FIXME: SigNaN*/
}
/*NaN*/
return b;
}
if (isFloat32Infinity(a)) {
if (isFloat32Infinity(b)) {
/*FIXME: inf / inf */
result.binary = FLOAT32_NAN;
return result;
}
/* inf / num */
result.parts.exp = a.parts.exp;
result.parts.fraction = a.parts.fraction;
return result;
}
 
if (isFloat32Infinity(b)) {
if (isFloat32Zero(a)) {
/* FIXME 0 / inf */
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
/* FIXME: num / inf*/
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
if (isFloat32Zero(b)) {
if (isFloat32Zero(a)) {
/*FIXME: 0 / 0*/
result.binary = FLOAT32_NAN;
return result;
}
/* FIXME: division by zero */
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
 
afrac = a.parts.fraction;
aexp = a.parts.exp;
bfrac = b.parts.fraction;
bexp = b.parts.exp;
/* denormalized numbers */
if (aexp == 0) {
if (afrac == 0) {
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
/* normalize it*/
afrac <<= 1;
/* afrac is nonzero => it must stop */
while (! (afrac & FLOAT32_HIDDEN_BIT_MASK) ) {
afrac <<= 1;
aexp--;
}
}
 
if (bexp == 0) {
bfrac <<= 1;
/* bfrac is nonzero => it must stop */
while (! (bfrac & FLOAT32_HIDDEN_BIT_MASK) ) {
bfrac <<= 1;
bexp--;
}
}
 
afrac = (afrac | FLOAT32_HIDDEN_BIT_MASK ) << (32 - FLOAT32_FRACTION_SIZE - 1 );
bfrac = (bfrac | FLOAT32_HIDDEN_BIT_MASK ) << (32 - FLOAT32_FRACTION_SIZE );
 
if ( bfrac <= (afrac << 1) ) {
afrac >>= 1;
aexp++;
}
cexp = aexp - bexp + FLOAT32_BIAS - 2;
cfrac = (afrac << 32) / bfrac;
if (( cfrac & 0x3F ) == 0) {
cfrac |= ( bfrac * cfrac != afrac << 32 );
}
/* pack and round */
/* find first nonzero digit and shift result and detect possibly underflow */
while ((cexp > 0) && (cfrac) && (!(cfrac & (FLOAT32_HIDDEN_BIT_MASK << 7 )))) {
cexp--;
cfrac <<= 1;
/* TODO: fix underflow */
};
cfrac += (0x1 << 6); /* FIXME: 7 is not sure*/
if (cfrac & (FLOAT32_HIDDEN_BIT_MASK << 7)) {
++cexp;
cfrac >>= 1;
}
 
/* check overflow */
if (cexp >= FLOAT32_MAX_EXPONENT ) {
/* FIXME: overflow, return infinity */
result.parts.exp = FLOAT32_MAX_EXPONENT;
result.parts.fraction = 0;
return result;
}
 
if (cexp < 0) {
/* FIXME: underflow */
result.parts.exp = 0;
if ((cexp + FLOAT32_FRACTION_SIZE) < 0) {
result.parts.fraction = 0;
return result;
}
cfrac >>= 1;
while (cexp < 0) {
cexp ++;
cfrac >>= 1;
}
} else {
result.parts.exp = (uint32_t)cexp;
}
result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK));
return result;
}
 
float64 divFloat64(float64 a, float64 b)
{
float64 result;
int64_t aexp, bexp, cexp;
uint64_t afrac, bfrac, cfrac;
uint64_t remlo, remhi;
result.parts.sign = a.parts.sign ^ b.parts.sign;
if (isFloat64NaN(a)) {
if (isFloat64SigNaN(b)) {
/*FIXME: SigNaN*/
return b;
}
if (isFloat64SigNaN(a)) {
/*FIXME: SigNaN*/
}
/*NaN*/
return a;
}
if (isFloat64NaN(b)) {
if (isFloat64SigNaN(b)) {
/*FIXME: SigNaN*/
}
/*NaN*/
return b;
}
if (isFloat64Infinity(a)) {
if (isFloat64Infinity(b) || isFloat64Zero(b)) {
/*FIXME: inf / inf */
result.binary = FLOAT64_NAN;
return result;
}
/* inf / num */
result.parts.exp = a.parts.exp;
result.parts.fraction = a.parts.fraction;
return result;
}
 
if (isFloat64Infinity(b)) {
if (isFloat64Zero(a)) {
/* FIXME 0 / inf */
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
/* FIXME: num / inf*/
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
if (isFloat64Zero(b)) {
if (isFloat64Zero(a)) {
/*FIXME: 0 / 0*/
result.binary = FLOAT64_NAN;
return result;
}
/* FIXME: division by zero */
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
 
afrac = a.parts.fraction;
aexp = a.parts.exp;
bfrac = b.parts.fraction;
bexp = b.parts.exp;
/* denormalized numbers */
if (aexp == 0) {
if (afrac == 0) {
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
}
/* normalize it*/
aexp++;
/* afrac is nonzero => it must stop */
while (! (afrac & FLOAT64_HIDDEN_BIT_MASK) ) {
afrac <<= 1;
aexp--;
}
}
 
if (bexp == 0) {
bexp++;
/* bfrac is nonzero => it must stop */
while (! (bfrac & FLOAT64_HIDDEN_BIT_MASK) ) {
bfrac <<= 1;
bexp--;
}
}
 
afrac = (afrac | FLOAT64_HIDDEN_BIT_MASK ) << (64 - FLOAT64_FRACTION_SIZE - 2 );
bfrac = (bfrac | FLOAT64_HIDDEN_BIT_MASK ) << (64 - FLOAT64_FRACTION_SIZE - 1);
 
if ( bfrac <= (afrac << 1) ) {
afrac >>= 1;
aexp++;
}
cexp = aexp - bexp + FLOAT64_BIAS - 2;
cfrac = divFloat64estim(afrac, bfrac);
if (( cfrac & 0x1FF ) <= 2) { /*FIXME:?? */
mul64integers( bfrac, cfrac, &remlo, &remhi);
/* (__u128)afrac << 64 - ( ((__u128)remhi<<64) + (__u128)remlo )*/
remhi = afrac - remhi - ( remlo > 0);
remlo = - remlo;
while ((int64_t) remhi < 0) {
cfrac--;
remlo += bfrac;
remhi += ( remlo < bfrac );
}
cfrac |= ( remlo != 0 );
}
/* round and shift */
result = finishFloat64(cexp, cfrac, result.parts.sign);
return result;
 
}
 
uint64_t divFloat64estim(uint64_t a, uint64_t b)
{
uint64_t bhi;
uint64_t remhi, remlo;
uint64_t result;
if ( b <= a ) {
return 0xFFFFFFFFFFFFFFFFull;
}
bhi = b >> 32;
result = ((bhi << 32) <= a) ?( 0xFFFFFFFFull << 32) : ( a / bhi) << 32;
mul64integers(b, result, &remlo, &remhi);
remhi = a - remhi - (remlo > 0);
remlo = - remlo;
 
b <<= 32;
while ( (int64_t) remhi < 0 ) {
result -= 0x1ll << 32;
remlo += b;
remhi += bhi + ( remlo < b );
}
remhi = (remhi << 32) | (remlo >> 32);
if (( bhi << 32) <= remhi) {
result |= 0xFFFFFFFF;
} else {
result |= remhi / bhi;
}
return result;
}
 
/tags/0.1.1/uspace/softfloat/generic/add.c
0,0 → 1,252
/*
* Copyright (C) 2005 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.
*/
 
#include<sftypes.h>
#include<add.h>
#include<comparison.h>
 
/** Add two Float32 numbers with same signs
*/
float32 addFloat32(float32 a, float32 b)
{
int expdiff;
uint32_t exp1, exp2,frac1, frac2;
expdiff = a.parts.exp - b.parts.exp;
if (expdiff < 0) {
if (isFloat32NaN(b)) {
/* TODO: fix SigNaN */
if (isFloat32SigNaN(b)) {
};
 
return b;
};
if (b.parts.exp == FLOAT32_MAX_EXPONENT) {
return b;
}
frac1 = b.parts.fraction;
exp1 = b.parts.exp;
frac2 = a.parts.fraction;
exp2 = a.parts.exp;
expdiff *= -1;
} else {
if ((isFloat32NaN(a)) || (isFloat32NaN(b))) {
/* TODO: fix SigNaN */
if (isFloat32SigNaN(a) || isFloat32SigNaN(b)) {
};
return (isFloat32NaN(a)?a:b);
};
if (a.parts.exp == FLOAT32_MAX_EXPONENT) {
return a;
}
frac1 = a.parts.fraction;
exp1 = a.parts.exp;
frac2 = b.parts.fraction;
exp2 = b.parts.exp;
};
if (exp1 == 0) {
/* both are denormalized */
frac1 += frac2;
if (frac1 & FLOAT32_HIDDEN_BIT_MASK ) {
/* result is not denormalized */
a.parts.exp = 1;
};
a.parts.fraction = frac1;
return a;
};
frac1 |= FLOAT32_HIDDEN_BIT_MASK; /* add hidden bit */
 
if (exp2 == 0) {
/* second operand is denormalized */
--expdiff;
} else {
/* add hidden bit to second operand */
frac2 |= FLOAT32_HIDDEN_BIT_MASK;
};
/* create some space for rounding */
frac1 <<= 6;
frac2 <<= 6;
if (expdiff < (FLOAT32_FRACTION_SIZE + 2) ) {
frac2 >>= expdiff;
frac1 += frac2;
} else {
a.parts.exp = exp1;
a.parts.fraction = (frac1 >> 6) & (~(FLOAT32_HIDDEN_BIT_MASK));
return a;
}
if (frac1 & (FLOAT32_HIDDEN_BIT_MASK << 7) ) {
++exp1;
frac1 >>= 1;
};
/* rounding - if first bit after fraction is set then round up */
frac1 += (0x1 << 5);
if (frac1 & (FLOAT32_HIDDEN_BIT_MASK << 7)) {
/* rounding overflow */
++exp1;
frac1 >>= 1;
};
if ((exp1 == FLOAT32_MAX_EXPONENT ) || (exp2 > exp1)) {
/* overflow - set infinity as result */
a.parts.exp = FLOAT32_MAX_EXPONENT;
a.parts.fraction = 0;
return a;
}
a.parts.exp = exp1;
/*Clear hidden bit and shift */
a.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)) ;
return a;
}
 
 
/** Add two Float64 numbers with same signs
*/
float64 addFloat64(float64 a, float64 b)
{
int expdiff;
uint32_t exp1, exp2;
uint64_t frac1, frac2;
expdiff = ((int )a.parts.exp) - b.parts.exp;
if (expdiff < 0) {
if (isFloat64NaN(b)) {
/* TODO: fix SigNaN */
if (isFloat64SigNaN(b)) {
};
 
return b;
};
/* b is infinity and a not */
if (b.parts.exp == FLOAT64_MAX_EXPONENT ) {
return b;
}
frac1 = b.parts.fraction;
exp1 = b.parts.exp;
frac2 = a.parts.fraction;
exp2 = a.parts.exp;
expdiff *= -1;
} else {
if (isFloat64NaN(a)) {
/* TODO: fix SigNaN */
if (isFloat64SigNaN(a) || isFloat64SigNaN(b)) {
};
return a;
};
/* a is infinity and b not */
if (a.parts.exp == FLOAT64_MAX_EXPONENT ) {
return a;
}
frac1 = a.parts.fraction;
exp1 = a.parts.exp;
frac2 = b.parts.fraction;
exp2 = b.parts.exp;
};
if (exp1 == 0) {
/* both are denormalized */
frac1 += frac2;
if (frac1 & FLOAT64_HIDDEN_BIT_MASK) {
/* result is not denormalized */
a.parts.exp = 1;
};
a.parts.fraction = frac1;
return a;
};
/* add hidden bit - frac1 is sure not denormalized */
frac1 |= FLOAT64_HIDDEN_BIT_MASK;
 
/* second operand ... */
if (exp2 == 0) {
/* ... is denormalized */
--expdiff;
} else {
/* is not denormalized */
frac2 |= FLOAT64_HIDDEN_BIT_MASK;
};
/* create some space for rounding */
frac1 <<= 6;
frac2 <<= 6;
if (expdiff < (FLOAT64_FRACTION_SIZE + 2) ) {
frac2 >>= expdiff;
frac1 += frac2;
} else {
a.parts.exp = exp1;
a.parts.fraction = (frac1 >> 6) & (~(FLOAT64_HIDDEN_BIT_MASK));
return a;
}
if (frac1 & (FLOAT64_HIDDEN_BIT_MASK << 7) ) {
++exp1;
frac1 >>= 1;
};
/* rounding - if first bit after fraction is set then round up */
frac1 += (0x1 << 5);
if (frac1 & (FLOAT64_HIDDEN_BIT_MASK << 7)) {
/* rounding overflow */
++exp1;
frac1 >>= 1;
};
if ((exp1 == FLOAT64_MAX_EXPONENT ) || (exp2 > exp1)) {
/* overflow - set infinity as result */
a.parts.exp = FLOAT64_MAX_EXPONENT;
a.parts.fraction = 0;
return a;
}
a.parts.exp = exp1;
/*Clear hidden bit and shift */
a.parts.fraction = ( (frac1 >> 6 ) & (~FLOAT64_HIDDEN_BIT_MASK));
return a;
}
 
 
/tags/0.1.1/uspace/softfloat/generic/common.c
0,0 → 1,205
/*
* Copyright (C) 2005 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.
*/
 
#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
* @return valied float64
*/
float64 finishFloat64(int32_t cexp, uint64_t cfrac, char sign)
{
float64 result;
 
result.parts.sign = sign;
 
/* find first nonzero digit and shift result and detect possibly underflow */
while ((cexp > 0) && (cfrac) && (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1 ) )))) {
cexp--;
cfrac <<= 1;
/* TODO: fix underflow */
};
if ((cexp < 0) || ( cexp == 0 && (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1)))))) {
/* FIXME: underflow */
result.parts.exp = 0;
if ((cexp + FLOAT64_FRACTION_SIZE + 1) < 0) { /* +1 is place for rounding */
result.parts.fraction = 0;
return result;
}
while (cexp < 0) {
cexp++;
cfrac >>= 1;
}
cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3));
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;
}
} else {
cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3));
}
++cexp;
 
if (cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1 ))) {
++cexp;
cfrac >>= 1;
}
 
/* check overflow */
if (cexp >= FLOAT64_MAX_EXPONENT ) {
/* FIXME: overflow, return infinity */
result.parts.exp = FLOAT64_MAX_EXPONENT;
result.parts.fraction = 0;
return result;
}
 
result.parts.exp = (uint32_t)cexp;
result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2 ) ) & (~FLOAT64_HIDDEN_BIT_MASK));
return result;
}
 
/** Counts leading zeroes in 64bit unsigned integer
* @param i
*/
int countZeroes64(uint64_t 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(uint32_t 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(uint8_t 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(int32_t *exp, uint32_t *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(int32_t *exp, uint64_t *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;
}
 
/tags/0.1.1/uspace/softfloat/generic/sub.c
0,0 → 1,255
/*
* Copyright (C) 2005 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.
*/
 
#include<sftypes.h>
#include<sub.h>
#include<comparison.h>
 
/** Subtract two float32 numbers with same signs
*/
float32 subFloat32(float32 a, float32 b)
{
int expdiff;
uint32_t exp1, exp2, frac1, frac2;
float32 result;
 
result.f = 0;
expdiff = a.parts.exp - b.parts.exp;
if ((expdiff < 0 ) || ((expdiff == 0) && (a.parts.fraction < b.parts.fraction))) {
if (isFloat32NaN(b)) {
/* TODO: fix SigNaN */
if (isFloat32SigNaN(b)) {
};
return b;
};
if (b.parts.exp == FLOAT32_MAX_EXPONENT) {
b.parts.sign = !b.parts.sign; /* num -(+-inf) = -+inf */
return b;
}
result.parts.sign = !a.parts.sign;
frac1 = b.parts.fraction;
exp1 = b.parts.exp;
frac2 = a.parts.fraction;
exp2 = a.parts.exp;
expdiff *= -1;
} else {
if (isFloat32NaN(a)) {
/* TODO: fix SigNaN */
if (isFloat32SigNaN(a) || isFloat32SigNaN(b)) {
};
return a;
};
if (a.parts.exp == FLOAT32_MAX_EXPONENT) {
if (b.parts.exp == FLOAT32_MAX_EXPONENT) {
/* inf - inf => nan */
/* TODO: fix exception */
result.binary = FLOAT32_NAN;
return result;
};
return a;
}
result.parts.sign = a.parts.sign;
frac1 = a.parts.fraction;
exp1 = a.parts.exp;
frac2 = b.parts.fraction;
exp2 = b.parts.exp;
};
if (exp1 == 0) {
/* both are denormalized */
result.parts.fraction = frac1-frac2;
if (result.parts.fraction > frac1) {
/* TODO: underflow exception */
return result;
};
result.parts.exp = 0;
return result;
};
 
/* add hidden bit */
frac1 |= FLOAT32_HIDDEN_BIT_MASK;
if (exp2 == 0) {
/* denormalized */
--expdiff;
} else {
/* normalized */
frac2 |= FLOAT32_HIDDEN_BIT_MASK;
};
/* create some space for rounding */
frac1 <<= 6;
frac2 <<= 6;
if (expdiff > FLOAT32_FRACTION_SIZE + 1) {
goto done;
};
frac1 = frac1 - (frac2 >> expdiff);
done:
/* TODO: find first nonzero digit and shift result and detect possibly underflow */
while ((exp1 > 0) && (!(frac1 & (FLOAT32_HIDDEN_BIT_MASK << 6 )))) {
--exp1;
frac1 <<= 1;
/* TODO: fix underflow - frac1 == 0 does not necessary means underflow... */
};
/* rounding - if first bit after fraction is set then round up */
frac1 += 0x20;
 
if (frac1 & (FLOAT32_HIDDEN_BIT_MASK << 7)) {
++exp1;
frac1 >>= 1;
};
/*Clear hidden bit and shift */
result.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK));
result.parts.exp = exp1;
return result;
}
 
/** Subtract two float64 numbers with same signs
*/
float64 subFloat64(float64 a, float64 b)
{
int expdiff;
uint32_t exp1, exp2;
uint64_t frac1, frac2;
float64 result;
 
result.d = 0;
expdiff = a.parts.exp - b.parts.exp;
if ((expdiff < 0 ) || ((expdiff == 0) && (a.parts.fraction < b.parts.fraction))) {
if (isFloat64NaN(b)) {
/* TODO: fix SigNaN */
if (isFloat64SigNaN(b)) {
};
return b;
};
if (b.parts.exp == FLOAT64_MAX_EXPONENT) {
b.parts.sign = !b.parts.sign; /* num -(+-inf) = -+inf */
return b;
}
result.parts.sign = !a.parts.sign;
frac1 = b.parts.fraction;
exp1 = b.parts.exp;
frac2 = a.parts.fraction;
exp2 = a.parts.exp;
expdiff *= -1;
} else {
if (isFloat64NaN(a)) {
/* TODO: fix SigNaN */
if (isFloat64SigNaN(a) || isFloat64SigNaN(b)) {
};
return a;
};
if (a.parts.exp == FLOAT64_MAX_EXPONENT) {
if (b.parts.exp == FLOAT64_MAX_EXPONENT) {
/* inf - inf => nan */
/* TODO: fix exception */
result.binary = FLOAT64_NAN;
return result;
};
return a;
}
result.parts.sign = a.parts.sign;
frac1 = a.parts.fraction;
exp1 = a.parts.exp;
frac2 = b.parts.fraction;
exp2 = b.parts.exp;
};
if (exp1 == 0) {
/* both are denormalized */
result.parts.fraction = frac1 - frac2;
if (result.parts.fraction > frac1) {
/* TODO: underflow exception */
return result;
};
result.parts.exp = 0;
return result;
};
 
/* add hidden bit */
frac1 |= FLOAT64_HIDDEN_BIT_MASK;
if (exp2 == 0) {
/* denormalized */
--expdiff;
} else {
/* normalized */
frac2 |= FLOAT64_HIDDEN_BIT_MASK;
};
/* create some space for rounding */
frac1 <<= 6;
frac2 <<= 6;
if (expdiff > FLOAT64_FRACTION_SIZE + 1) {
goto done;
};
frac1 = frac1 - (frac2 >> expdiff);
done:
/* TODO: find first nonzero digit and shift result and detect possibly underflow */
while ((exp1 > 0) && (!(frac1 & (FLOAT64_HIDDEN_BIT_MASK << 6 )))) {
--exp1;
frac1 <<= 1;
/* TODO: fix underflow - frac1 == 0 does not necessary means underflow... */
};
/* rounding - if first bit after fraction is set then round up */
frac1 += 0x20;
 
if (frac1 & (FLOAT64_HIDDEN_BIT_MASK << 7)) {
++exp1;
frac1 >>= 1;
};
/*Clear hidden bit and shift */
result.parts.fraction = ((frac1 >> 6) & (~FLOAT64_HIDDEN_BIT_MASK));
result.parts.exp = exp1;
return result;
}
 
/tags/0.1.1/uspace/softfloat/generic/mul.c
0,0 → 1,287
/*
* Copyright (C) 2005 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.
*/
 
#include<sftypes.h>
#include<mul.h>
#include<comparison.h>
#include<common.h>
 
/** Multiply two 32 bit float numbers
*
*/
float32 mulFloat32(float32 a, float32 b)
{
float32 result;
uint64_t frac1, frac2;
int32_t exp;
 
result.parts.sign = a.parts.sign ^ b.parts.sign;
if (isFloat32NaN(a) || isFloat32NaN(b) ) {
/* TODO: fix SigNaNs */
if (isFloat32SigNaN(a)) {
result.parts.fraction = a.parts.fraction;
result.parts.exp = a.parts.exp;
return result;
};
if (isFloat32SigNaN(b)) { /* TODO: fix SigNaN */
result.parts.fraction = b.parts.fraction;
result.parts.exp = b.parts.exp;
return result;
};
/* set NaN as result */
result.binary = FLOAT32_NAN;
return result;
};
if (isFloat32Infinity(a)) {
if (isFloat32Zero(b)) {
/* FIXME: zero * infinity */
result.binary = FLOAT32_NAN;
return result;
}
result.parts.fraction = a.parts.fraction;
result.parts.exp = a.parts.exp;
return result;
}
 
if (isFloat32Infinity(b)) {
if (isFloat32Zero(a)) {
/* FIXME: zero * infinity */
result.binary = FLOAT32_NAN;
return result;
}
result.parts.fraction = b.parts.fraction;
result.parts.exp = b.parts.exp;
return result;
}
 
/* exp is signed so we can easy detect underflow */
exp = a.parts.exp + b.parts.exp;
exp -= FLOAT32_BIAS;
if (exp >= FLOAT32_MAX_EXPONENT) {
/* FIXME: overflow */
/* set infinity as result */
result.binary = FLOAT32_INF;
result.parts.sign = a.parts.sign ^ b.parts.sign;
return result;
};
if (exp < 0) {
/* FIXME: underflow */
/* return signed zero */
result.parts.fraction = 0x0;
result.parts.exp = 0x0;
return result;
};
frac1 = a.parts.fraction;
if (a.parts.exp > 0) {
frac1 |= FLOAT32_HIDDEN_BIT_MASK;
} else {
++exp;
};
frac2 = b.parts.fraction;
 
if (b.parts.exp > 0) {
frac2 |= FLOAT32_HIDDEN_BIT_MASK;
} else {
++exp;
};
 
frac1 <<= 1; /* one bit space for rounding */
 
frac1 = frac1 * frac2;
/* round and return */
while ((exp < FLOAT32_MAX_EXPONENT) && (frac1 >= ( 1 << (FLOAT32_FRACTION_SIZE + 2)))) {
/* 23 bits of fraction + one more for hidden bit (all shifted 1 bit left)*/
++exp;
frac1 >>= 1;
};
 
/* rounding */
/* ++frac1; FIXME: not works - without it is ok */
frac1 >>= 1; /* shift off rounding space */
if ((exp < FLOAT32_MAX_EXPONENT) && (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 1)))) {
++exp;
frac1 >>= 1;
};
 
if (exp >= FLOAT32_MAX_EXPONENT ) {
/* TODO: fix overflow */
/* return infinity*/
result.parts.exp = FLOAT32_MAX_EXPONENT;
result.parts.fraction = 0x0;
return result;
}
exp -= FLOAT32_FRACTION_SIZE;
 
if (exp <= FLOAT32_FRACTION_SIZE) {
/* denormalized number */
frac1 >>= 1; /* denormalize */
while ((frac1 > 0) && (exp < 0)) {
frac1 >>= 1;
++exp;
};
if (frac1 == 0) {
/* FIXME : underflow */
result.parts.exp = 0;
result.parts.fraction = 0;
return result;
};
};
result.parts.exp = exp;
result.parts.fraction = frac1 & ( (1 << FLOAT32_FRACTION_SIZE) - 1);
return result;
}
 
/** Multiply two 64 bit float numbers
*
*/
float64 mulFloat64(float64 a, float64 b)
{
float64 result;
uint64_t frac1, frac2;
int32_t exp;
 
result.parts.sign = a.parts.sign ^ b.parts.sign;
if (isFloat64NaN(a) || isFloat64NaN(b) ) {
/* TODO: fix SigNaNs */
if (isFloat64SigNaN(a)) {
result.parts.fraction = a.parts.fraction;
result.parts.exp = a.parts.exp;
return result;
};
if (isFloat64SigNaN(b)) { /* TODO: fix SigNaN */
result.parts.fraction = b.parts.fraction;
result.parts.exp = b.parts.exp;
return result;
};
/* set NaN as result */
result.binary = FLOAT64_NAN;
return result;
};
if (isFloat64Infinity(a)) {
if (isFloat64Zero(b)) {
/* FIXME: zero * infinity */
result.binary = FLOAT64_NAN;
return result;
}
result.parts.fraction = a.parts.fraction;
result.parts.exp = a.parts.exp;
return result;
}
 
if (isFloat64Infinity(b)) {
if (isFloat64Zero(a)) {
/* FIXME: zero * infinity */
result.binary = FLOAT64_NAN;
return result;
}
result.parts.fraction = b.parts.fraction;
result.parts.exp = b.parts.exp;
return result;
}
 
/* exp is signed so we can easy detect underflow */
exp = a.parts.exp + b.parts.exp - FLOAT64_BIAS;
frac1 = a.parts.fraction;
 
if (a.parts.exp > 0) {
frac1 |= FLOAT64_HIDDEN_BIT_MASK;
} else {
++exp;
};
frac2 = b.parts.fraction;
 
if (b.parts.exp > 0) {
frac2 |= FLOAT64_HIDDEN_BIT_MASK;
} else {
++exp;
};
 
frac1 <<= (64 - FLOAT64_FRACTION_SIZE - 1);
frac2 <<= (64 - FLOAT64_FRACTION_SIZE - 2);
 
mul64integers(frac1, frac2, &frac1, &frac2);
 
frac2 |= (frac1 != 0);
if (frac2 & (0x1ll << 62)) {
frac2 <<= 1;
exp--;
}
 
result = finishFloat64(exp, frac2, result.parts.sign);
return result;
}
 
/** Multiply two 64 bit numbers and return result in two parts
* @param a first operand
* @param b second operand
* @param lo lower part from result
* @param hi higher part of result
*/
void mul64integers(uint64_t a,uint64_t b, uint64_t *lo, uint64_t *hi)
{
uint64_t low, high, middle1, middle2;
uint32_t alow, blow;
 
alow = a & 0xFFFFFFFF;
blow = b & 0xFFFFFFFF;
a >>= 32;
b >>= 32;
low = ((uint64_t)alow) * blow;
middle1 = a * blow;
middle2 = alow * b;
high = a * b;
 
middle1 += middle2;
high += (((uint64_t)(middle1 < middle2)) << 32) + (middle1 >> 32);
middle1 <<= 32;
low += middle1;
high += (low < middle1);
*lo = low;
*hi = high;
return;
}
 
 
/tags/0.1.1/uspace/softfloat/generic/other.c
0,0 → 1,29
/*
* Copyright (C) 2005 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.
*/
 
 
/tags/0.1.1/uspace/softfloat/include/mul.h
0,0 → 1,39
/*
* Copyright (C) 2005 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 __MUL_H__
#define __MUL_H__
 
float32 mulFloat32(float32 a, float32 b);
 
float64 mulFloat64(float64 a, float64 b);
 
void mul64integers(uint64_t a,uint64_t b, uint64_t *lo, uint64_t *hi);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/sftypes.h
0,0 → 1,102
/*
* Copyright (C) 2005 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 __SFTYPES_H__
#define __SFTYPES_H__
 
#include <endian.h>
#include <stdint.h>
 
typedef union {
float f;
uint32_t binary;
 
struct {
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t sign:1;
uint32_t exp:8;
uint32_t fraction:23;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
uint32_t fraction:23;
uint32_t exp:8;
uint32_t sign:1;
#else
#error "Unknown endians."
#endif
} parts __attribute__ ((packed));
} float32;
typedef union {
double d;
uint64_t binary;
struct {
#if __BYTE_ORDER == __BIG_ENDIAN
uint64_t sign:1;
uint64_t exp:11;
uint64_t fraction:52;
#elif __BYTE_ORDER == __LITTLE_ENDIAN
uint64_t fraction:52;
uint64_t exp:11;
uint64_t sign:1;
#else
#error "Unknown endians."
#endif
} parts __attribute__ ((packed));
} float64;
 
#define FLOAT32_MAX 0x7f800000
#define FLOAT32_MIN 0xff800000
#define FLOAT64_MAX
#define FLOAT64_MIN
 
/* For recognizing NaNs or infinity use isFloat32NaN and is Float32Inf, comparing with this constants is not sufficient */
#define FLOAT32_NAN 0x7FC00001
#define FLOAT32_SIGNAN 0x7F800001
#define FLOAT32_INF 0x7F800000
 
#define FLOAT64_NAN 0x7FF8000000000001ll
#define FLOAT64_SIGNAN 0x7FF0000000000001ll
#define FLOAT64_INF 0x7FF0000000000000ll
 
#define FLOAT32_FRACTION_SIZE 23
#define FLOAT64_FRACTION_SIZE 52
 
#define FLOAT32_HIDDEN_BIT_MASK 0x800000
#define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000ll
 
#define FLOAT32_MAX_EXPONENT 0xFF
#define FLOAT64_MAX_EXPONENT 0x7FF
 
#define FLOAT32_BIAS 0x7F
#define FLOAT64_BIAS 0x3FF
#define FLOAT80_BIAS 0x3FFF
 
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/softfloat.h
0,0 → 1,164
/*
* Copyright (C) 2005 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 __SOFTFLOAT_H__
#define __SOFTFLOAT_H__
 
float __addsf3(float a, float b);
double __adddf3(double a, double b);
long double __addtf3(long double a, long double b);
long double __addxf3(long double a, long double b);
float __subsf3(float a, float b);
double __subdf3(double a, double b);
long double __subtf3(long double a, long double b);
long double __subxf3(long double a, long double b);
float __mulsf3(float a, float b);
double __muldf3(double a, double b);
long double __multf3(long double a, long double b);
long double __mulxf3(long double a, long double b);
float __divsf3(float a, float b);
double __divdf3(double a, double b);
long double __divtf3(long double a, long double b);
long double __divxf3(long double a, long double b);
float __negsf2(float a);
double __negdf2(double a);
long double __negtf2(long double a);
long double __negxf2(long double a);
double __extendsfdf2(float a);
long double __extendsftf2(float a);
long double __extendsfxf2(float a);
long double __extenddftf2(double a);
long double __extenddfxf2(double a);
double __truncxfdf2(long double a);
double __trunctfdf2(long double a);
float __truncxfsf2(long double a);
float __trunctfsf2(long double a);
float __truncdfsf2(double a);
int __fixsfsi(float a);
int __fixdfsi(double a);
int __fixtfsi(long double a);
int __fixxfsi(long double a);
long __fixsfdi(float a);
long __fixdfdi(double a);
long __fixtfdi(long double a);
long __fixxfdi(long double a);
long long __fixsfti(float a);
long long __fixdfti(double a);
long long __fixtfti(long double a);
long long __fixxfti(long double a);
unsigned int __fixunssfsi(float a);
unsigned int __fixunsdfsi(double a);
unsigned int __fixunstfsi(long double a);
unsigned int __fixunsxfsi(long double a);
unsigned long __fixunssfdi(float a);
unsigned long __fixunsdfdi(double a);
unsigned long __fixunstfdi(long double a);
unsigned long __fixunsxfdi(long double a);
unsigned long long __fixunssfti(float a);
unsigned long long __fixunsdfti(double a);
unsigned long long __fixunstfti(long double a);
unsigned long long __fixunsxfti(long double a);
float __floatsisf(int i);
double __floatsidf(int i);
long double __floatsitf(int i);
long double __floatsixf(int i);
float __floatdisf(long i);
double __floatdidf(long i);
long double __floatditf(long i);
long double __floatdixf(long i);
float __floattisf(long long i);
double __floattidf(long long i);
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);
int __unordsf2(float a, float b);
int __unorddf2(double a, double b);
int __unordtf2(long double a, long double b);
int __eqsf2(float a, float b);
int __eqdf2(double a, double b);
int __eqtf2(long double a, long double b);
int __nesf2(float a, float b);
int __nedf2(double a, double b);
int __netf2(long double a, long double b);
int __gesf2(float a, float b);
int __gedf2(double a, double b);
int __getf2(long double a, long double b);
int __ltsf2(float a, float b);
int __ltdf2(double a, double b);
int __lttf2(long double a, long double b);
int __lesf2(float a, float b);
int __ledf2(double a, double b);
int __letf2(long double a, long double b);
int __gtsf2(float a, float b);
int __gtdf2(double a, double b);
int __gttf2(long double a, long double b);
/* Not implemented yet*/
float __powisf2(float a, int b);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/div.h
0,0 → 1,38
/*
* Copyright (C) 2005 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 __DIV_H__
#define __DIV_H__
 
float32 divFloat32(float32 a, float32 b);
float64 divFloat64(float64 a, float64 b);
 
uint64_t divFloat64estim(uint64_t a, uint64_t b);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/conversion.h
0,0 → 1,61
/*
* Copyright (C) 2005 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 __CONVERSION_H__
#define __CONVERSION_H__
 
float64 convertFloat32ToFloat64(float32 a);
 
float32 convertFloat64ToFloat32(float64 a);
 
uint32_t float32_to_uint32(float32 a);
int32_t float32_to_int32(float32 a);
 
uint64_t float32_to_uint64(float32 a);
int64_t float32_to_int64(float32 a);
 
uint64_t float64_to_uint64(float64 a);
int64_t float64_to_int64(float64 a);
 
uint32_t float64_to_uint32(float64 a);
int32_t float64_to_int32(float64 a);
 
float32 uint32_to_float32(uint32_t i);
float32 int32_to_float32(int32_t i);
 
float32 uint64_to_float32(uint64_t i);
float32 int64_to_float32(int64_t i);
 
float64 uint32_to_float64(uint32_t i);
float64 int32_to_float64(int32_t i);
 
float64 uint64_to_float64(uint64_t i);
float64 int64_to_float64(int64_t i);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/common.h
0,0 → 1,43
/*
* Copyright (C) 2005 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 __COMMON_H__
#define __COMMON_H__
 
#include<sftypes.h>
 
float64 finishFloat64(int32_t cexp, uint64_t cfrac, char sign);
 
int countZeroes64(uint64_t i);
int countZeroes32(uint32_t i);
int countZeroes8(uint8_t i);
 
void roundFloat32(int32_t *exp, uint32_t *fraction);
void roundFloat64(int32_t *exp, uint64_t *fraction);
 
#endif
/tags/0.1.1/uspace/softfloat/include/sub.h
0,0 → 1,37
/*
* Copyright (C) 2005 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 __SUB_H__
#define __SUB_H__
 
float32 subFloat32(float32 a, float32 b);
 
float64 subFloat64(float64 a, float64 b);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/add.h
0,0 → 1,37
/*
* Copyright (C) 2005 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 __ADD_H__
#define __ADD_H__
 
float32 addFloat32(float32 a, float32 b);
 
float64 addFloat64(float64 a, float64 b);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/comparison.h
0,0 → 1,49
/*
* Copyright (C) 2005 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 __COMPARISON_H__
#define __COMPARISON_H__
 
inline int isFloat32NaN(float32 f);
inline int isFloat32SigNaN(float32 f);
 
inline int isFloat32Infinity(float32 f);
inline int isFloat32Zero(float32 f);
 
inline int isFloat64NaN(float64 d);
inline int isFloat64SigNaN(float64 d);
 
inline int isFloat64Infinity(float64 d);
inline int isFloat64Zero(float64 d);
 
inline int isFloat32eq(float32 a, float32 b);
inline int isFloat32lt(float32 a, float32 b);
inline int isFloat32gt(float32 a, float32 b);
 
#endif
 
/tags/0.1.1/uspace/softfloat/include/other.h
0,0 → 1,33
/*
* Copyright (C) 2005 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 __OTHER_H__
#define __OTHER_H__
 
#endif
 
/tags/0.1.1/uspace/softfloat/arch/sparc64/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_FUNCTIONS_H__
 
#define float32_to_int(X) float32_to_int32(X);
#define float32_to_long(X) float32_to_int64(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_int64(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_uint64(X);
#define float32_to_ulonglong(X) float32_to_uint64(X);
 
#define float64_to_uint(X) float64_to_uint32(X);
#define float64_to_ulong(X) float64_to_uint64(X);
#define float64_to_ulonglong(X) float64_to_uint64(X);
 
#define int_to_float32(X) int32_to_float32(X);
#define long_to_float32(X) int64_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) int64_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) uint64_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) uint64_to_float64(X);
#define ulonglong_to_float64(X) uint64_to_float64(X);
 
#endif
 
/tags/0.1.1/uspace/softfloat/arch/ia64/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_FUNCTIONS_H__
 
#define float32_to_int(X) float32_to_int32(X);
#define float32_to_long(X) float32_to_int64(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_int64(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_uint64(X);
#define float32_to_ulonglong(X) float32_to_uint64(X);
 
#define float64_to_uint(X) float64_to_uint32(X);
#define float64_to_ulong(X) float64_to_uint64(X);
#define float64_to_ulonglong(X) float64_to_uint64(X);
 
#define int_to_float32(X) int32_to_float32(X);
#define long_to_float32(X) int64_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) int64_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) uint64_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) uint64_to_float64(X);
#define ulonglong_to_float64(X) uint64_to_float64(X);
 
#endif
 
/tags/0.1.1/uspace/softfloat/arch/mips32eb/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_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);
 
#define float64_to_uint(X) float64_to_uint32(X);
#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
 
/tags/0.1.1/uspace/softfloat/arch/ppc32/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_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);
 
#define float64_to_uint(X) float64_to_uint32(X);
#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
 
/tags/0.1.1/uspace/softfloat/arch/amd64/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_FUNCTIONS_H__
 
#define float32_to_int(X) float32_to_int32(X);
#define float32_to_long(X) float32_to_int64(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_int64(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_uint64(X);
#define float32_to_ulonglong(X) float32_to_uint64(X);
 
#define float64_to_uint(X) float64_to_uint32(X);
#define float64_to_ulong(X) float64_to_uint64(X);
#define float64_to_ulonglong(X) float64_to_uint64(X);
 
#define int_to_float32(X) int32_to_float32(X);
#define long_to_float32(X) int64_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) int64_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) uint64_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) uint64_to_float64(X);
#define ulonglong_to_float64(X) uint64_to_float64(X);
 
#endif
 
/tags/0.1.1/uspace/softfloat/arch/mips32/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_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);
 
#define float64_to_uint(X) float64_to_uint32(X);
#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
 
/tags/0.1.1/uspace/softfloat/arch/ia32/include/functions.h
0,0 → 1,65
/*
* 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 __SOFTFLOAT_FUNCTIONS_H__
#define __SOFTFLOAT_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);
 
#define float64_to_uint(X) float64_to_uint32(X);
#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