Christophe Riccio 14 tahun lalu
induk
melakukan
8864136e87
2 mengubah file dengan 14 tambahan dan 23 penghapusan
  1. 12 21
      glm/gtx/integer.inl
  2. 2 2
      test/gtx/gtx_integer.cpp

+ 12 - 21
glm/gtx/integer.inl

@@ -55,31 +55,22 @@ namespace detail
 	}
 }//namespace detail
 
+#if(GLM_COMPILER & (GLM_COMPILER_VC | GLM_COMPILER_GCC))
+
+GLM_FUNC_QUALIFIER unsigned int log2(unsigned int x)
+{
+	return x <= 1 ? 0 : unsigned(32) - nlz(x - 1u);
+}
+
+#else
+
 GLM_FUNC_QUALIFIER unsigned int log2(unsigned int x)
 {
 	return unsigned(32) - nlz(x - 1u);
-	//if(x <= 1)
-	//	return 0;
-	//return unsigned(32) - findLSB(x) - 1u;
-	
-	
-/*
-	// Henry Gordon Dietz: http://aggregate.org/MAGIC/
-
-	register int y = (x & (x - 1));
-
-	y |= -y;
-	y >>= (WORDBITS - 1);
-	x |= (x >> 1);
-	x |= (x >> 2);
-	x |= (x >> 4);
-	x |= (x >> 8);
-	x |= (x >> 16);
-	
-	return detail::ones32(x) - 1 - y;
-*/
 }
 
+#endif
+
 // Henry Gordon Dietz: http://aggregate.org/MAGIC/
 unsigned int floor_log2(unsigned int x)
 {
@@ -172,7 +163,7 @@ GLM_FUNC_QUALIFIER uint mod(uint x, uint y)
 
 GLM_FUNC_QUALIFIER unsigned int nlz(unsigned int x) 
 {
-	return 32u - findMSB(x);
+	return 31u - findMSB(x);
 }
 
 #else

+ 2 - 2
test/gtx/gtx_integer.cpp

@@ -38,7 +38,7 @@ int test_log2()
 		double B = glm::log2(double(i));
 
 		Error += glm::equalEpsilon(double(A), B, 1.0) ? 0 : 1;
-		assert(!Error);
+		//assert(!Error);
 	}
 
 	return Error;
@@ -49,7 +49,7 @@ int test_nlz()
 	int Error = 0;
 
 	for(std::size_t i = 1; i < 33; ++i)
-		printf("%d, %d\n", glm::nlz(i), 31 - glm::findMSB(i));
+		printf("%d, %d\n", glm::nlz(i), 31u - glm::findMSB(i));
 
 	return Error;
 }