Minor replicate_swizzle optimization.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 20 Jul 2020 15:37:27 -0400
changeset 1289 f47a47343dbc
parent 1288 259d3bba6b66
child 1290 2febe5ae83ad
Minor replicate_swizzle optimization. Do it in two tests instead of three, and with two shifts instead of five.
profiles/mojoshader_profile_common.c
--- a/profiles/mojoshader_profile_common.c	Mon Jul 20 15:35:34 2020 -0400
+++ b/profiles/mojoshader_profile_common.c	Mon Jul 20 15:37:27 2020 -0400
@@ -331,9 +331,9 @@
 
 int replicate_swizzle(const int swizzle)
 {
-    return ( (((swizzle >> 0) & 0x3) == ((swizzle >> 2) & 0x3)) &&
-             (((swizzle >> 2) & 0x3) == ((swizzle >> 4) & 0x3)) &&
-             (((swizzle >> 4) & 0x3) == ((swizzle >> 6) & 0x3)) );
+    // elements 1|2 match 3|4 and element 1 matches element 2.
+    return ( (((swizzle >> 4) & 0xF) == ((swizzle >> 0) & 0xF)) &&
+             (((swizzle >> 0) & 0x3) == ((swizzle >> 2) & 0x3)) );
 } // replicate_swizzle
 
 int no_swizzle(const int swizzle)