[Piglit] [PATCH 5/6] triangle-rasterization: Use log2u utility function

Ian Romanick idr at freedesktop.org
Mon Oct 10 22:51:37 UTC 2016


From: Ian Romanick <ian.d.romanick at intel.com>

The log2i code was broken for values < 0 anyway because -1 >> 1 == -1.
The result would have been an infinite loop.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: James Benton <jbenton at vmware.com>
---
 tests/general/triangle-rasterization.cpp | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/tests/general/triangle-rasterization.cpp b/tests/general/triangle-rasterization.cpp
index f93842f..e196280 100644
--- a/tests/general/triangle-rasterization.cpp
+++ b/tests/general/triangle-rasterization.cpp
@@ -153,16 +153,6 @@ int64_t iround(float v)
 	return (int64_t)v;
 }
 
-/* Calculate log2 for integers */
-int log2i(int x)
-{
-	int res = 0 ;
-	while (x >>= 1)
-		++res;
-	return res ;
-}
-
-
 /* Based on http://devmaster.net/forums/topic/1145-advanced-rasterization */
 void rast_triangle(uint8_t* buffer, uint32_t stride, const Triangle& tri)
 {
@@ -408,7 +398,7 @@ GLboolean test_triangle(const Triangle& tri)
 /* Generate a random triangle */
 void random_triangle(Triangle& tri)
 {
-	int size = 1 << (mersenne.value() % (log2i(fbo_width) + 1));
+	int size = 1 << (mersenne.value() % (log2u(fbo_width) + 1));
 
 	for (int i = 0; i < 3; ++i) {
 		tri[i].x = (mersenne.value() % (size * FIXED_ONE)) * (1.0f / FIXED_ONE);
-- 
2.5.5



More information about the Piglit mailing list