about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012-04-11 14:20:45 -0400
committerRich Felker <dalias@aerifal.cx>2012-04-11 14:20:45 -0400
commit5837a0bb6b5cf516f79527e837368af0b494d51a (patch)
treea2cefcd2db2ce4011fe7d248b58b0513cd4b7a9c
parent1bdd5c8b9868ebc092074e078604acb80546e43f (diff)
downloadmusl-5837a0bb6b5cf516f79527e837368af0b494d51a.tar.gz
musl-5837a0bb6b5cf516f79527e837368af0b494d51a.tar.xz
musl-5837a0bb6b5cf516f79527e837368af0b494d51a.zip
simplify/debloat radix point alignment code in floatscan
now that this is the first operation, it can rely on the circular
buffer contents not being wrapped when it begins. we limit the number
of digits read slightly in the initial parsing loops too so that this
code does not have to consider the case where it might cause the
circular buffer to wrap; this is perfectly fine because KMAX is chosen
as a power of two for circular-buffer purposes and is much larger than
it otherwise needs to be, anyway.

these changes should not affect performance at all.
-rw-r--r--src/internal/floatscan.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/src/internal/floatscan.c b/src/internal/floatscan.c
index d5444daa..6390d46a 100644
--- a/src/internal/floatscan.c
+++ b/src/internal/floatscan.c
@@ -77,7 +77,7 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
 		if (c == '.') {
 			if (lrp!=-1) break;
 			lrp = dc;
-		} else if (k < KMAX) {
+		} else if (k < KMAX-2) {
 			dc++;
 			if (j) x[k] = x[k]*10 + c-'0';
 			else x[k] = c-'0';
@@ -88,7 +88,7 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
 			gotdig=1;
 		} else {
 			dc++;
-			x[KMAX-1] |= c-'0';
+			if (c!='0') x[KMAX-3] |= 1;
 		}
 	}
 	if (lrp==-1) lrp=dc;
@@ -146,7 +146,7 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
 		int rpm9 = rp>=0 ? rp%9 : rp%9+9;
 		int p10 = p10s[rpm9-1];
 		uint32_t carry = 0;
-		for (k=a; k!=z; k=(k+1 & MASK)) {
+		for (k=a; k!=z; k++) {
 			uint32_t tmp = x[k] % p10;
 			x[k] = x[k]/p10 + carry;
 			carry = 1000000000/p10 * tmp;
@@ -155,12 +155,7 @@ static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int po
 				rp -= 9;
 			}
 		}
-		if (carry) {
-			if ((z+1 & MASK) != a) {
-				x[z] = carry;
-				z = (z+1 & MASK);
-			} else x[z-1 & MASK] |= 1;
-		}
+		if (carry) x[z++] = carry;
 		rp += 9-rpm9;
 	}