Optimize mirror addressing mode

The previous implementation required a total of 8 instructions. The new
version only takes 6.

Note that the previously used Frac() function includes a Min() operation
which ensures that it never returns results greater or equal to 1.0. It
also handles Inf values. The new mirror addressing implementation has an
explicit Min() which serves similar purposes.

Bug: b/194635449
Change-Id: I3f16beb0ecd93e5bafccacd7b5823710c6ace55e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/61168
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Pipeline/SamplerCore.cpp b/src/Pipeline/SamplerCore.cpp
index c6f82ff..9ffddb9 100644
--- a/src/Pipeline/SamplerCore.cpp
+++ b/src/Pipeline/SamplerCore.cpp
@@ -2266,9 +2266,7 @@
 	}
 	else
 	{
-		const int halfBits = 0x3EFFFFFF;  // Value just under 0.5f
-		const int oneBits = 0x3F7FFFFF;   // Value just under 1.0f
-		const int twoBits = 0x3FFFFFFF;   // Value just under 2.0f
+		const int oneBits = 0x3F7FFFFF;  // Value just under 1.0f
 
 		Float4 coord = uvw;
 
@@ -2332,10 +2330,10 @@
 					break;
 				case ADDRESSING_MIRROR:
 					{
-						Float4 half = As<Float4>(Int4(halfBits));
 						Float4 one = As<Float4>(Int4(oneBits));
-						Float4 two = As<Float4>(Int4(twoBits));
-						coord = one - Abs(two * Frac(coord * half) - one);
+						coord = coord * Float4(0.5f);
+						coord = Float4(2.0f) * Abs(coord - Round(coord));
+						coord = Min(coord, one);
 					}
 					break;
 				case ADDRESSING_MIRRORONCE: