[Scummvm-cvs-logs] scummvm master -> a1bfbe65ba3f9e3d6cf690c6f48a4719a98ae45c

lordhoto lordhoto at gmail.com
Sun Jul 24 19:59:04 CEST 2011


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
b609100a56 COMMON: Let intLog2 return an int instead of uint32, since it should return -1 for 0.
a1bfbe65ba COMMON: Add an optimized intLog2 implementation for gcc using __builtin_clz.


Commit: b609100a563ffd7d393edf089fb2e8cb5f41a5cf
    https://github.com/scummvm/scummvm/commit/b609100a563ffd7d393edf089fb2e8cb5f41a5cf
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-07-24T10:53:48-07:00

Commit Message:
COMMON: Let intLog2 return an int instead of uint32, since it should return -1 for 0.

Changed paths:
    common/math.h



diff --git a/common/math.h b/common/math.h
index ebe01fb..e1af433 100644
--- a/common/math.h
+++ b/common/math.h
@@ -58,7 +58,7 @@ static const char LogTable256[256] = {
 	LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7)
 };
 
-inline uint32 intLog2(uint32 v) {
+inline int intLog2(uint32 v) {
 	register uint32 t, tt;
 
 	if ((tt = v >> 16))


Commit: a1bfbe65ba3f9e3d6cf690c6f48a4719a98ae45c
    https://github.com/scummvm/scummvm/commit/a1bfbe65ba3f9e3d6cf690c6f48a4719a98ae45c
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-07-24T10:54:49-07:00

Commit Message:
COMMON: Add an optimized intLog2 implementation for gcc using __builtin_clz.

This is done as discussed here:
https://github.com/scummvm/scummvm/commit/54f25aa84373715001c56155673fb59cfe44b573

Changed paths:
    common/math.h



diff --git a/common/math.h b/common/math.h
index e1af433..9542cb6 100644
--- a/common/math.h
+++ b/common/math.h
@@ -50,6 +50,20 @@ struct Complex {
 	float re, im;
 };
 
+#ifdef __GNUC__
+inline int intLog2(uint32 v) {
+	// This is a slightly optimized implementation of log2 for natural numbers
+	// targeting gcc. It also saves some binary size over our fallback
+	// implementation, since it does not need any table.
+	if (v == 0)
+		return -1;
+	else
+		// This is really "sizeof(unsigned int) * CHAR_BIT - 1" but using 8
+		// instead of CHAR_BIT is sane enough and it saves us from including
+		// limits.h
+		return (sizeof(unsigned int) * 8 - 1) - __builtin_clz(v);
+}
+#else
 // See http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
 static const char LogTable256[256] = {
 #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n
@@ -66,6 +80,7 @@ inline int intLog2(uint32 v) {
 	else
 		return (t =  v >> 8) ?  8 + LogTable256[t] : LogTable256[v];
 }
+#endif
 
 inline float rad2deg(float rad) {
 	return rad * 180.0 / M_PI;






More information about the Scummvm-git-logs mailing list