Switch win32 to row_gcc for clangcl.

Bug: libyuv:900, libyuv:848, b/178283356, b/185922513
Change-Id: I7697953753391c555a778198db36412c853fb29e
Reviewed-on: https://chromium-review.googlesource.com/c/libyuv/libyuv/+/2844962
Reviewed-by: richard winterton <rrwinterton@gmail.com>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
diff --git a/include/libyuv/compare_row.h b/include/libyuv/compare_row.h
index 01e1d23..18c5fa4 100644
--- a/include/libyuv/compare_row.h
+++ b/include/libyuv/compare_row.h
@@ -18,9 +18,7 @@
 extern "C" {
 #endif
 
-// TODO: Fix Win32 build
-// https://bugs.chromium.org/p/libyuv/issues/detail?id=900
-#if defined(__pnacl__) || defined(__CLR_VER) || defined(_M_IX86) || \
+#if defined(__pnacl__) || defined(__CLR_VER) || \
     (defined(__native_client__) && defined(__x86_64__)) || \
     (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
 #define LIBYUV_DISABLE_X86
@@ -56,21 +54,22 @@
 #endif
 
 // The following are available for Visual C and clangcl 32 bit:
-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \
+#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && \
+     defined(_MSC_VER) && !defined(__clang__) && \
     (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2))
 #define HAS_HASHDJB2_AVX2
 #define HAS_SUMSQUAREERROR_AVX2
 #endif
 
-// The following are available for GCC and clangcl 64 bit:
+// The following are available for GCC and clangcl:
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 #define HAS_HAMMINGDISTANCE_SSSE3
 #endif
 
-// The following are available for GCC and clangcl 64 bit:
+// The following are available for GCC and clangcl:
 #if !defined(LIBYUV_DISABLE_X86) && defined(CLANG_HAS_AVX2) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 #define HAS_HAMMINGDISTANCE_AVX2
 #endif
 
diff --git a/include/libyuv/planar_functions.h b/include/libyuv/planar_functions.h
index 1343788..fdecdee 100644
--- a/include/libyuv/planar_functions.h
+++ b/include/libyuv/planar_functions.h
@@ -23,9 +23,7 @@
 #endif
 
 // TODO(fbarchard): Move cpu macros to row.h
-// TODO: Fix Win32 build
-// https://bugs.chromium.org/p/libyuv/issues/detail?id=900
-#if defined(__pnacl__) || defined(__CLR_VER) || defined(_M_IX86) || \
+#if defined(__pnacl__) || defined(__CLR_VER) || \
     (defined(__native_client__) && defined(__x86_64__)) || \
     (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
 #define LIBYUV_DISABLE_X86
diff --git a/include/libyuv/rotate_row.h b/include/libyuv/rotate_row.h
index 1929e25..5a9cf93 100644
--- a/include/libyuv/rotate_row.h
+++ b/include/libyuv/rotate_row.h
@@ -18,9 +18,7 @@
 extern "C" {
 #endif
 
-// TODO: Fix Win32 build
-// https://bugs.chromium.org/p/libyuv/issues/detail?id=900
-#if defined(__pnacl__) || defined(__CLR_VER) || defined(_M_IX86) || \
+#if defined(__pnacl__) || defined(__CLR_VER) || \
     (defined(__native_client__) && defined(__x86_64__)) || \
     (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
 #define LIBYUV_DISABLE_X86
@@ -34,8 +32,9 @@
 #define LIBYUV_DISABLE_X86
 #endif
 #endif
-// The following are available for Visual C and clangcl 32 bit:
-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER)
+// The following are available for Visual C 32 bit:
+#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \
+    !defined(__clang__)
 #define HAS_TRANSPOSEWX8_SSSE3
 #define HAS_TRANSPOSEUVWX8_SSE2
 #endif
diff --git a/include/libyuv/row.h b/include/libyuv/row.h
index 1836cb8..0b094b2 100644
--- a/include/libyuv/row.h
+++ b/include/libyuv/row.h
@@ -20,9 +20,7 @@
 extern "C" {
 #endif
 
-// TODO: Fix Win32 build
-// https://bugs.chromium.org/p/libyuv/issues/detail?id=900
-#if defined(__pnacl__) || defined(__CLR_VER) || defined(_M_IX86) || \
+#if defined(__pnacl__) || defined(__CLR_VER) || \
     (defined(__native_client__) && defined(__x86_64__)) || \
     (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
 #define LIBYUV_DISABLE_X86
@@ -247,10 +245,10 @@
 #endif
 #endif
 
-// The following are available for AVX2 Visual C and clangcl 32 bit:
+// The following are available for AVX2 Visual C 32 bit:
 // TODO(fbarchard): Port to gcc.
 #if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER) && \
-    (defined(VISUALC_HAS_AVX2) || defined(CLANG_HAS_AVX2))
+    !defined(__clang__) && defined(VISUALC_HAS_AVX2)
 #define HAS_ARGB1555TOARGBROW_AVX2
 #define HAS_ARGB4444TOARGBROW_AVX2
 #define HAS_ARGBTOARGB1555ROW_AVX2
@@ -272,7 +270,7 @@
 // The following are available for gcc/clang x86 platforms:
 // TODO(fbarchard): Port to Visual C
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 #define HAS_ABGRTOAR30ROW_SSSE3
 #define HAS_ARGBTOAR30ROW_SSSE3
 #define HAS_ARGBTOAR64ROW_SSSE3
@@ -319,7 +317,7 @@
 // The following are available for AVX2 gcc/clang x86 platforms:
 // TODO(fbarchard): Port to Visual C
 #if !defined(LIBYUV_DISABLE_X86) &&                                       \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) && \
+    (defined(__x86_64__) || defined(__i386__)) && \
     (defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2))
 #define HAS_ABGRTOAR30ROW_AVX2
 #define HAS_ABGRTOUVROW_AVX2
@@ -379,7 +377,7 @@
 // TODO(fbarchard): Port to GCC and Visual C
 // TODO(fbarchard): re-enable HAS_ARGBTORGB24ROW_AVX512VBMI. Issue libyuv:789
 #if !defined(LIBYUV_DISABLE_X86) &&                                       \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER))) && \
+    (defined(__x86_64__) || defined(__i386__)) && \
     (defined(CLANG_HAS_AVX512))
 #define HAS_ARGBTORGB24ROW_AVX512VBMI
 #endif
@@ -551,24 +549,14 @@
 #define HAS_BGRATOYROW_MSA
 #define HAS_HALFFLOATROW_MSA
 #define HAS_I400TOARGBROW_MSA
-//#define HAS_I422ALPHATOARGBROW_MSA
-//#define HAS_I422TOARGBROW_MSA
-//#define HAS_I422TORGB24ROW_MSA
-//#define HAS_I422TORGBAROW_MSA
 #define HAS_I422TOUYVYROW_MSA
 #define HAS_I422TOYUY2ROW_MSA
-//#define HAS_I444TOARGBROW_MSA
-//#define HAS_I422TOARGB1555ROW_MSA
-//#define HAS_I422TORGB565ROW_MSA
 #define HAS_INTERPOLATEROW_MSA
 #define HAS_J400TOARGBROW_MSA
 #define HAS_MERGEUVROW_MSA
 #define HAS_MIRRORROW_MSA
 #define HAS_MIRRORUVROW_MSA
 #define HAS_MIRRORSPLITUVROW_MSA
-//#define HAS_NV12TOARGBROW_MSA
-//#define HAS_NV12TORGB565ROW_MSA
-//#define HAS_NV21TOARGBROW_MSA
 #define HAS_RAWTOARGBROW_MSA
 #define HAS_RAWTORGB24ROW_MSA
 #define HAS_RAWTOUVROW_MSA
@@ -588,10 +576,8 @@
 #define HAS_SOBELXYROW_MSA
 #define HAS_SOBELYROW_MSA
 #define HAS_SPLITUVROW_MSA
-//#define HAS_UYVYTOARGBROW_MSA
 #define HAS_UYVYTOUVROW_MSA
 #define HAS_UYVYTOYROW_MSA
-//#define HAS_YUY2TOARGBROW_MSA
 #define HAS_YUY2TOUV422ROW_MSA
 #define HAS_YUY2TOUVROW_MSA
 #define HAS_YUY2TOYROW_MSA
@@ -641,8 +627,6 @@
 #define HAS_I400TOARGBROW_MMI
 #define HAS_I422TOUYVYROW_MMI
 #define HAS_I422TOYUY2ROW_MMI
-//#define HAS_I422TOARGBROW_MMI
-//#define HAS_I444TOARGBROW_MMI
 #define HAS_INTERPOLATEROW_MMI
 #define HAS_J400TOARGBROW_MMI
 #define HAS_MERGERGBROW_MMI
@@ -673,20 +657,6 @@
 #define HAS_YUY2TOUV422ROW_MMI
 #define HAS_YUY2TOUVROW_MMI
 #define HAS_YUY2TOYROW_MMI
-//#define HAS_I210TOARGBROW_MMI
-//#define HAS_I422TOARGB4444ROW_MMI
-//#define HAS_I422TOARGB1555ROW_MMI
-//#define HAS_I422TORGB565ROW_MMI
-//#define HAS_NV21TORGB24ROW_MMI
-//#define HAS_NV12TORGB24ROW_MMI
-//#define HAS_I422ALPHATOARGBROW_MMI
-//#define HAS_I422TORGB24ROW_MMI
-//#define HAS_NV12TOARGBROW_MMI
-//#define HAS_NV21TOARGBROW_MMI
-//#define HAS_NV12TORGB565ROW_MMI
-//#define HAS_YUY2TOARGBROW_MMI
-//#define HAS_UYVYTOARGBROW_MMI
-//#define HAS_I422TORGBAROW_MMI
 #endif
 
 #if defined(_MSC_VER) && !defined(__CLR_VER) && !defined(__clang__)
diff --git a/include/libyuv/scale_row.h b/include/libyuv/scale_row.h
index 63af79b..833af1c 100644
--- a/include/libyuv/scale_row.h
+++ b/include/libyuv/scale_row.h
@@ -19,9 +19,7 @@
 extern "C" {
 #endif
 
-// TODO: Fix Win32 build
-// https://bugs.chromium.org/p/libyuv/issues/detail?id=900
-#if defined(__pnacl__) || defined(__CLR_VER) || defined(_M_IX86) || \
+#if defined(__pnacl__) || defined(__CLR_VER) || \
     (defined(__native_client__) && defined(__x86_64__)) || \
     (defined(__i386__) && !defined(__SSE__) && !defined(__clang__))
 #define LIBYUV_DISABLE_X86
@@ -77,7 +75,7 @@
 // The following are available for gcc/clang x86 platforms:
 // TODO(fbarchard): Port to Visual C
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 #define HAS_SCALEUVROWDOWN2BOX_SSSE3
 #define HAS_SCALEROWUP2LINEAR_SSE2
 #define HAS_SCALEROWUP2LINEAR_SSSE3
@@ -96,8 +94,8 @@
 // The following are available for gcc/clang x86 platforms, but
 // require clang 3.4 or gcc 4.7.
 // TODO(fbarchard): Port to Visual C
-#if !defined(LIBYUV_DISABLE_X86) &&                                     \
-    (defined(__x86_64__) || defined(__i386__)) && !defined(_MSC_VER) && \
+#if !defined(LIBYUV_DISABLE_X86) &&                  \
+    (defined(__x86_64__) || defined(__i386__)) &&    \
     (defined(CLANG_HAS_AVX2) || defined(GCC_HAS_AVX2))
 #define HAS_SCALEUVROWDOWN2BOX_AVX2
 #define HAS_SCALEROWUP2LINEAR_AVX2
diff --git a/source/compare_gcc.cc b/source/compare_gcc.cc
index 6700f96..7dcbf7d 100644
--- a/source/compare_gcc.cc
+++ b/source/compare_gcc.cc
@@ -20,7 +20,7 @@
 
 // This module is for GCC x86 and x64.
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 
 #if defined(__x86_64__)
 uint32_t HammingDistance_SSE42(const uint8_t* src_a,
diff --git a/source/compare_win.cc b/source/compare_win.cc
index d57d3d9..9bb27f1 100644
--- a/source/compare_win.cc
+++ b/source/compare_win.cc
@@ -22,8 +22,9 @@
 extern "C" {
 #endif
 
-// This module is for 32 bit Visual C x86 and clangcl
-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER)
+// This module is for 32 bit Visual C x86
+#if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \
+    !defined(__clang__) && defined(_M_IX86)
 
 uint32_t HammingDistance_SSE42(const uint8_t* src_a,
                                const uint8_t* src_b,
@@ -77,8 +78,7 @@
   }
 }
 
-// Visual C 2012 required for AVX2.
-#if _MSC_VER >= 1700
+#ifdef HAS_SUMSQUAREERROR_AVX2
 // C4752: found Intel(R) Advanced Vector Extensions; consider using /arch:AVX.
 #pragma warning(disable : 4752)
 __declspec(naked) uint32_t
@@ -118,7 +118,7 @@
     ret
   }
 }
-#endif  // _MSC_VER >= 1700
+#endif  // HAS_SUMSQUAREERROR_AVX2
 
 uvec32 kHash16x33 = {0x92d9e201, 0, 0, 0};  // 33 ^ 16
 uvec32 kHashMul0 = {
@@ -196,7 +196,7 @@
 }
 
 // Visual C 2012 required for AVX2.
-#if _MSC_VER >= 1700
+#ifdef HAS_HASHDJB2_AVX2
 __declspec(naked) uint32_t
     HashDjb2_AVX2(const uint8_t* src, int count, uint32_t seed) {
   __asm {
@@ -231,7 +231,7 @@
     ret
   }
 }
-#endif  // _MSC_VER >= 1700
+#endif  // HAS_HASHDJB2_AVX2
 
 #endif  // !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86)
 
diff --git a/source/planar_functions.cc b/source/planar_functions.cc
index 1fba98f..7cea06c 100644
--- a/source/planar_functions.cc
+++ b/source/planar_functions.cc
@@ -2642,12 +2642,12 @@
     height = 1;
     src_stride_argb0 = src_stride_argb1 = dst_stride_argb = 0;
   }
-#if defined(HAS_ARGBADDROW_SSE2) && (defined(_MSC_VER) && !defined(__clang__))
+#if defined(HAS_ARGBADDROW_SSE2)
   if (TestCpuFlag(kCpuHasSSE2)) {
     ARGBAddRow = ARGBAddRow_SSE2;
   }
 #endif
-#if defined(HAS_ARGBADDROW_SSE2) && !(defined(_MSC_VER) && !defined(__clang__))
+#if defined(HAS_ARGBADDROW_SSE2)
   if (TestCpuFlag(kCpuHasSSE2)) {
     ARGBAddRow = ARGBAddRow_Any_SSE2;
     if (IS_ALIGNED(width, 4)) {
diff --git a/source/rotate_gcc.cc b/source/rotate_gcc.cc
index fd359d4..8401d4f 100644
--- a/source/rotate_gcc.cc
+++ b/source/rotate_gcc.cc
@@ -18,7 +18,7 @@
 
 // This module is for GCC x86 and x64.
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 
 // Transpose 8x8. 32 or 64 bit, but not NaCL for 64 bit.
 #if defined(HAS_TRANSPOSEWX8_SSSE3)
diff --git a/source/rotate_win.cc b/source/rotate_win.cc
index e887dd5..a78873f 100644
--- a/source/rotate_win.cc
+++ b/source/rotate_win.cc
@@ -16,8 +16,9 @@
 extern "C" {
 #endif
 
-// This module is for 32 bit Visual C x86 and clangcl
-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER)
+// This module is for 32 bit Visual C x86
+#if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \
+    !defined(__clang__) && defined(_M_IX86)
 
 __declspec(naked) void TransposeWx8_SSSE3(const uint8_t* src,
                                           int src_stride,
diff --git a/source/row_common.cc b/source/row_common.cc
index 3e71ce3..f9e9a01 100644
--- a/source/row_common.cc
+++ b/source/row_common.cc
@@ -22,15 +22,14 @@
 extern "C" {
 #endif
 
-// These 2 macros control YUV to RGB using unsigned math to extend range.
-// They can be used separately to enable new code and old data (clamped)
+// This macro control YUV to RGB using unsigned math to extend range of
+// YUV to RGB coefficients to 0 to 4 instead of 0 to 2 for more accuracy on B:
 // LIBYUV_UNLIMITED_DATA
-// LIBYUV_UNLIMITED_CODE
 
-// The following ifdef from row_win makes the C code match the row_win code,
-// which is 7 bit fixed point.
+// The following macro from row_win makes the C code match the row_win code,
+// which is 7 bit fixed point for ARGBToI420:
 #if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \
-    (defined(_M_IX86) || (defined(_M_X64) && !defined(__clang__)))
+    !defined(__clang__) && (defined(_M_IX86) || defined(_M_X64))
 #define LIBYUV_RGB7 1
 #endif
 
@@ -3642,7 +3641,7 @@
 // Maximum temporary width for wrappers to process at a time, in pixels.
 #define MAXTWIDTH 2048
 
-#if !(defined(_MSC_VER) && defined(_M_IX86)) && \
+#if !(defined(_MSC_VER) && !defined(__clang__) && defined(_M_IX86)) && \
     defined(HAS_I422TORGB565ROW_SSSE3)
 // row_win.cc has asm version, but GCC uses 2 step wrapper.
 void I422ToRGB565Row_SSSE3(const uint8_t* src_y,
diff --git a/source/row_gcc.cc b/source/row_gcc.cc
index d21c153..d6c2853 100644
--- a/source/row_gcc.cc
+++ b/source/row_gcc.cc
@@ -17,7 +17,7 @@
 
 // This module is for GCC x86 and x64.
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 
 #if defined(HAS_ARGBTOYROW_SSSE3) || defined(HAS_ARGBGRAYROW_SSSE3)
 
diff --git a/source/row_win.cc b/source/row_win.cc
index 07aca7b..8d633c3 100644
--- a/source/row_win.cc
+++ b/source/row_win.cc
@@ -10,9 +10,9 @@
 
 #include "libyuv/row.h"
 
-// This module is for Visual C 32/64 bit and clangcl 32 bit
+// This module is for Visual C 32/64 bit
 #if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \
-    (defined(_M_IX86) || (defined(_M_X64) && !defined(__clang__)))
+    !defined(__clang__) && (defined(_M_IX86) || defined(_M_X64))
 
 #if defined(_M_X64)
 #include <emmintrin.h>
diff --git a/source/scale_gcc.cc b/source/scale_gcc.cc
index b1d39cf..ebc6deb 100644
--- a/source/scale_gcc.cc
+++ b/source/scale_gcc.cc
@@ -18,7 +18,7 @@
 
 // This module is for GCC x86 and x64.
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 
 // Offsets for source bytes 0 to 9
 static const uvec8 kShuf0 = {0,   1,   3,   4,   5,   7,   8,   9,
diff --git a/source/scale_win.cc b/source/scale_win.cc
index c5fc86f..ea1f95c 100644
--- a/source/scale_win.cc
+++ b/source/scale_win.cc
@@ -16,8 +16,9 @@
 extern "C" {
 #endif
 
-// This module is for 32 bit Visual C x86 and clangcl
-#if !defined(LIBYUV_DISABLE_X86) && defined(_M_IX86) && defined(_MSC_VER)
+// This module is for 32 bit Visual C x86
+#if !defined(LIBYUV_DISABLE_X86) && defined(_MSC_VER) && \
+    !defined(__clang__) && defined(_M_IX86)
 
 // Offsets for source bytes 0 to 9
 static const uvec8 kShuf0 = {0,   1,   3,   4,   5,   7,   8,   9,
diff --git a/unit_test/color_test.cc b/unit_test/color_test.cc
index 0a68cc7..f6b1f6f 100644
--- a/unit_test/color_test.cc
+++ b/unit_test/color_test.cc
@@ -23,7 +23,7 @@
 // TODO(fbarchard): clang x86 has a higher accuracy YUV to RGB.
 // Port to Visual C and other CPUs
 #if !defined(LIBYUV_DISABLE_X86) && \
-    (defined(__x86_64__) || (defined(__i386__) && !defined(_MSC_VER)))
+    (defined(__x86_64__) || defined(__i386__))
 #define ERROR_FULL 5
 #define ERROR_J420 4
 #else