Index: softfloat/generic/sub.c
===================================================================
--- softfloat/generic/sub.c	(revision 12c6f2dd96214d6bf7bc23f4e96554f665e93934)
+++ softfloat/generic/sub.c	(revision a96c570080a40421b42a4256974140cf8d4119be)
@@ -27,6 +27,7 @@
  */
 
-#include "sftypes.h"
-#include "sub.h"
+#include<sftypes.h>
+#include<sub.h>
+#include<comparison.h>
 
 /** Subtract two float32 numbers with same signs
@@ -35,11 +36,11 @@
 {
 	int expdiff;
-	__u32 exp1,exp2,mant1,mant2;
+	__u32 exp1, exp2, mant1, mant2;
 	float32 result;
 
 	result.f = 0;
 	
-	expdiff=a.parts.exp - b.parts.exp;
-	if ((expdiff<0)||((expdiff==0)&&(a.parts.mantisa<b.parts.mantisa))) {
+	expdiff = a.parts.exp - b.parts.exp;
+	if ((expdiff < 0 ) || ((expdiff == 0) && (a.parts.mantisa < b.parts.mantisa))) {
 		if (isFloat32NaN(b)) {
 			//TODO: fix SigNaN
@@ -49,6 +50,6 @@
 		};
 		
-		if (b.parts.exp==0xFF) { 
-			b.parts.sign=!b.parts.sign; /* num -(+-inf) = -+inf */
+		if (b.parts.exp == FLOAT32_MAX_EXPONENT) { 
+			b.parts.sign = !b.parts.sign; /* num -(+-inf) = -+inf */
 			return b;
 		}
@@ -56,19 +57,19 @@
 		result.parts.sign = !a.parts.sign; 
 		
-		mant1=b.parts.mantisa;
-		exp1=b.parts.exp;
-		mant2=a.parts.mantisa;
-		exp2=a.parts.exp;
-		expdiff*=-1;
+		mant1 = b.parts.mantisa;
+		exp1 = b.parts.exp;
+		mant2 = a.parts.mantisa;
+		exp2 = a.parts.exp;
+		expdiff *= -1;
 	} else {
 		if (isFloat32NaN(a)) {
 			//TODO: fix SigNaN
-			if ((isFloat32SigNaN(a))||(isFloat32SigNaN(b))) {
-			};
-			return a;
-		};
-		
-		if (a.parts.exp==0xFF) { 
-			if (b.parts.exp==0xFF) {
+			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
@@ -81,59 +82,174 @@
 		result.parts.sign = a.parts.sign;
 		
-		mant1=a.parts.mantisa;
-		exp1=a.parts.exp;
-		mant2=b.parts.mantisa;
-		exp2=b.parts.exp;	
-	};
-	
-	if (exp1==0) {
+		mant1 = a.parts.mantisa;
+		exp1 = a.parts.exp;
+		mant2 = b.parts.mantisa;
+		exp2 = b.parts.exp;	
+	};
+	
+	if (exp1 == 0) {
 		//both are denormalized
-		result.parts.mantisa=mant1-mant2;
-		if (result.parts.mantisa>mant1) {
+		result.parts.mantisa = mant1-mant2;
+		if (result.parts.mantisa > mant1) {
 			//TODO: underflow exception
 			return result;
 		};
-		result.parts.exp=0;
+		result.parts.exp = 0;
 		return result;
 	};
-	
-	// create some space for rounding
-	mant1<<=6;
-	mant2<<=6;
-	
-	mant1|=0x20000000; //add hidden bit
-	
-	
-	if (exp2==0) {
+
+	/* add hidden bit */
+	mant1 |= FLOAT32_HIDDEN_BIT_MASK; 
+	
+	if (exp2 == 0) {
+		/* denormalized */
 		--expdiff;	
 	} else {
-		mant2|=0x20000000; //hidden bit
-	};
-	
-	if (expdiff>24) {
+		/* normalized */
+		mant2 |= FLOAT32_HIDDEN_BIT_MASK;
+	};
+	
+	/* create some space for rounding */
+	mant1 <<= 6;
+	mant2 <<= 6;
+	
+	if (expdiff > FLOAT32_MANTISA_SIZE + 1) {
 	     goto done;	
 	     };
 	
-	mant1 = mant1-(mant2>>expdiff);
+	mant1 = mant1 - (mant2 >> expdiff);
 done:
 	//TODO: find first nonzero digit and shift result and detect possibly underflow
-	while ((exp1>0)&&(!(mant1&0x20000000))) {
-		exp1--;
+	while ((exp1 > 0) && (!(mant1 & (FLOAT32_HIDDEN_BIT_MASK << 6 )))) {
+		--exp1;
 		mant1 <<= 1;
 			/* TODO: fix underflow - mant1 == 0 does not necessary means underflow... */
 	};
 	
-	//rounding - if first bit after mantisa is set then round up	
+	/* rounding - if first bit after mantisa is set then round up */
 	mant1 += 0x20;
 
-	if (mant1&0x40000000) {
+	if (mant1 & (FLOAT32_HIDDEN_BIT_MASK << 7)) {
 		++exp1;
-		mant1>>=1;
-	};
-	
-	result.parts.mantisa = ((mant1&(~0x20000000))>>6); /*Clear hidden bit and shift */
+		mant1 >>= 1;
+	};
+	
+	/*Clear hidden bit and shift */
+	result.parts.mantisa = ((mant1 >> 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;
+	__u32 exp1, exp2;
+	__u64 mant1, mant2;
+	float64 result;
+
+	result.d = 0;
+	
+	expdiff = a.parts.exp - b.parts.exp;
+	if ((expdiff < 0 ) || ((expdiff == 0) && (a.parts.mantisa < b.parts.mantisa))) {
+		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; 
+		
+		mant1 = b.parts.mantisa;
+		exp1 = b.parts.exp;
+		mant2 = a.parts.mantisa;
+		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;
+		
+		mant1 = a.parts.mantisa;
+		exp1 = a.parts.exp;
+		mant2 = b.parts.mantisa;
+		exp2 = b.parts.exp;	
+	};
+	
+	if (exp1 == 0) {
+		//both are denormalized
+		result.parts.mantisa = mant1 - mant2;
+		if (result.parts.mantisa > mant1) {
+			//TODO: underflow exception
+			return result;
+		};
+		result.parts.exp = 0;
+		return result;
+	};
+
+	/* add hidden bit */
+	mant1 |= FLOAT64_HIDDEN_BIT_MASK; 
+	
+	if (exp2 == 0) {
+		/* denormalized */
+		--expdiff;	
+	} else {
+		/* normalized */
+		mant2 |= FLOAT64_HIDDEN_BIT_MASK;
+	};
+	
+	/* create some space for rounding */
+	mant1 <<= 6;
+	mant2 <<= 6;
+	
+	if (expdiff > FLOAT64_MANTISA_SIZE + 1) {
+	     goto done;	
+	     };
+	
+	mant1 = mant1 - (mant2 >> expdiff);
+done:
+	//TODO: find first nonzero digit and shift result and detect possibly underflow
+	while ((exp1 > 0) && (!(mant1 & (FLOAT64_HIDDEN_BIT_MASK << 6 )))) {
+		--exp1;
+		mant1 <<= 1;
+			/* TODO: fix underflow - mant1 == 0 does not necessary means underflow... */
+	};
+	
+	/* rounding - if first bit after mantisa is set then round up */
+	mant1 += 0x20;
+
+	if (mant1 & (FLOAT64_HIDDEN_BIT_MASK << 7)) {
+		++exp1;
+		mant1 >>= 1;
+	};
+	
+	/*Clear hidden bit and shift */
+	result.parts.mantisa = ((mant1 >> 6) & (~FLOAT64_HIDDEN_BIT_MASK)); 
+	result.parts.exp = exp1;
+	
+	return result;
+}
+
