Fix conversion to RGB9E5 format

log() was used instead of log2().

Also replace pow(2.0f, x) with the equivalent exp2(x), and remove
overloaded functions from Math.hpp which are guaranteed by C++11.

Bug: b/138944025
Change-Id: I9e87ee9b2afd8791a40dd3e73191e1ed0740acf5
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/34668
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index f6d714f..8d50178 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -16,6 +16,7 @@
 
 #include "Pipeline/ShaderCore.hpp"
 #include "Reactor/Reactor.hpp"
+#include "System/Half.hpp"
 #include "System/Memory.hpp"
 #include "Vulkan/VkDebug.hpp"
 #include "Vulkan/VkImage.hpp"
diff --git a/src/Device/QuadRasterizer.cpp b/src/Device/QuadRasterizer.cpp
index 65470af..ce4dbf1 100644
--- a/src/Device/QuadRasterizer.cpp
+++ b/src/Device/QuadRasterizer.cpp
@@ -198,18 +198,18 @@
 			{
 				if(state.colorWriteActive(index))
 				{
-					cBuffer[index] += *Pointer<Int>(data + OFFSET(DrawData,colorPitchB[index])) << (1 + sw::log2(clusterCount));   // FIXME: Precompute
+					cBuffer[index] += *Pointer<Int>(data + OFFSET(DrawData,colorPitchB[index])) << (1 + log2i(clusterCount));   // FIXME: Precompute
 				}
 			}
 
 			if(state.depthTestActive)
 			{
-				zBuffer += *Pointer<Int>(data + OFFSET(DrawData,depthPitchB)) << (1 + sw::log2(clusterCount));   // FIXME: Precompute
+				zBuffer += *Pointer<Int>(data + OFFSET(DrawData,depthPitchB)) << (1 + log2i(clusterCount));   // FIXME: Precompute
 			}
 
 			if(state.stencilActive)
 			{
-				sBuffer += *Pointer<Int>(data + OFFSET(DrawData,stencilPitchB)) << (1 + sw::log2(clusterCount));   // FIXME: Precompute
+				sBuffer += *Pointer<Int>(data + OFFSET(DrawData,stencilPitchB)) << (1 + log2i(clusterCount));   // FIXME: Precompute
 			}
 
 			y += 2 * clusterCount;
diff --git a/src/System/Half.hpp b/src/System/Half.hpp
index a20629a..ec5fba9 100644
--- a/src/System/Half.hpp
+++ b/src/System/Half.hpp
@@ -77,19 +77,13 @@
 			const float blue_c = std::max<float>(0, std::min(g_sharedexp_max, rgb[2]));
 
 			const float max_c = std::max<float>(std::max<float>(red_c, green_c), blue_c);
-			const float exp_p =
-				std::max<float>(-g_sharedexp_bias - 1, floor(log(max_c))) + 1 + g_sharedexp_bias;
-			const int max_s = static_cast<int>(
-				floor((max_c / (pow(2.0f, exp_p - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
-			const int exp_s =
-				static_cast<int>((max_s < pow(2.0f, g_sharedexp_mantissabits)) ? exp_p : exp_p + 1);
+			const float exp_p = std::max<float>(-g_sharedexp_bias - 1, floor(log2(max_c))) + 1 + g_sharedexp_bias;
+			const int max_s = static_cast<int>(floor((max_c / exp2(exp_p - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
+			const int exp_s = static_cast<int>((max_s < exp2(g_sharedexp_mantissabits)) ? exp_p : exp_p + 1);
 
-			R = static_cast<unsigned int>(
-				floor((red_c / (pow(2.0f, exp_s - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
-			G = static_cast<unsigned int>(
-				floor((green_c / (pow(2.0f, exp_s - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
-			B = static_cast<unsigned int>(
-				floor((blue_c / (pow(2.0f, exp_s - g_sharedexp_bias - g_sharedexp_mantissabits))) + 0.5f));
+			R = static_cast<unsigned int>(floor((red_c / exp2(exp_s - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
+			G = static_cast<unsigned int>(floor((green_c / exp2(exp_s - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
+			B = static_cast<unsigned int>(floor((blue_c / exp2(exp_s - g_sharedexp_bias - g_sharedexp_mantissabits)) + 0.5f));
 			E = exp_s;
 		}
 
diff --git a/src/System/Math.hpp b/src/System/Math.hpp
index 2e7f344..7bd3890 100644
--- a/src/System/Math.hpp
+++ b/src/System/Math.hpp
@@ -16,7 +16,6 @@
 #define sw_Math_hpp
 
 #include "Types.hpp"
-#include "Half.hpp"
 
 #include "Vulkan/VkDebug.hpp"
 
@@ -138,17 +137,7 @@
 	#define MAX(x, y) ((x) > (y) ? (x) : (y))
 	#define MIN(x, y) ((x) < (y) ? (x) : (y))
 
-	inline float exp2(float x)
-	{
-		return exp2f(x);
-	}
-
-	inline int exp2(int x)
-	{
-		return 1 << x;
-	}
-
-	inline unsigned long log2(int x)
+	inline unsigned long log2i(int x)
 	{
 		#if defined(_MSC_VER)
 			unsigned long y;
@@ -159,18 +148,6 @@
 		#endif
 	}
 
-	inline int ilog2(float x)
-	{
-		unsigned int y = *(unsigned int*)&x;
-
-		return ((y & 0x7F800000) >> 23) - 127;
-	}
-
-	inline float log2(float x)
-	{
-		return logf(x) * 1.44269504f;   // 1.0 / log[e](2)
-	}
-
 	inline bool isPow2(int x)
 	{
 		return (x & -x) == x;