[x265] [PATCH 1 of 3] primitives: convert Setup_Vector_Primitives to a CPU mask instead of ID

Steve Borho steve at borho.org
Thu Sep 26 23:50:00 CEST 2013


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1380171653 18000
#      Thu Sep 26 00:00:53 2013 -0500
# Node ID 8636384aba196197dbb6822ffc44d995e20bae99
# Parent  99be942b385521764bde47ce226913795e5e1cf7
primitives: convert Setup_Vector_Primitives to a CPU mask instead of ID

This allows the testbench to isolate the functions added for a given arch

diff -r 99be942b3855 -r 8636384aba19 source/common/primitives.cpp
--- a/source/common/primitives.cpp	Thu Sep 26 16:19:00 2013 -0500
+++ b/source/common/primitives.cpp	Thu Sep 26 00:00:53 2013 -0500
@@ -129,7 +129,7 @@
     Setup_C_Primitives(primitives);
 
 #if ENABLE_VECTOR_PRIMITIVES
-    Setup_Vector_Primitives(primitives, cpuid);
+    Setup_Vector_Primitives(primitives, (1 << (cpuid + 1)) - 1);
     if (param->logLevel >= X265_LOG_INFO) fprintf(stderr, " intrinsic");
 #endif
 
diff -r 99be942b3855 -r 8636384aba19 source/common/primitives.h
--- a/source/common/primitives.h	Thu Sep 26 16:19:00 2013 -0500
+++ b/source/common/primitives.h	Thu Sep 26 00:00:53 2013 -0500
@@ -304,7 +304,7 @@
 extern EncoderPrimitives primitives;
 
 void Setup_C_Primitives(EncoderPrimitives &p);
-void Setup_Vector_Primitives(EncoderPrimitives &p, int cpuid);
+void Setup_Vector_Primitives(EncoderPrimitives &p, int cpuMask);
 void Setup_Assembly_Primitives(EncoderPrimitives &p, int cpuid);
 }
 
diff -r 99be942b3855 -r 8636384aba19 source/common/vec/vec-primitives.cpp
--- a/source/common/vec/vec-primitives.cpp	Thu Sep 26 16:19:00 2013 -0500
+++ b/source/common/vec/vec-primitives.cpp	Thu Sep 26 00:00:53 2013 -0500
@@ -71,35 +71,35 @@
 }
 
 /* Use primitives for the best available vector architecture */
-void Setup_Vector_Primitives(EncoderPrimitives &p, int cpuid)
+void Setup_Vector_Primitives(EncoderPrimitives &p, int cpuMask)
 {
     /* These functions are defined by C++ files in this folder. Depending on your
      * compiler, some of them may be undefined.  The #if logic here must match the
      * file lists in CMakeLists.txt */
 #if defined(__INTEL_COMPILER)
-    if (cpuid > 2) Setup_Vec_Primitives_sse3(p);
-    if (cpuid > 3) Setup_Vec_Primitives_ssse3(p);
-    if (cpuid > 4) Setup_Vec_Primitives_sse41(p);
-    if (cpuid > 7) Setup_Vec_Primitives_avx2(p);
+    if (cpuMask & (1 << 3)) Setup_Vec_Primitives_sse3(p);
+    if (cpuMask & (1 << 4)) Setup_Vec_Primitives_ssse3(p);
+    if (cpuMask & (1 << 5)) Setup_Vec_Primitives_sse41(p);
+    if (cpuMask & (1 << 8)) Setup_Vec_Primitives_avx2(p);
 
 #elif defined(__GNUC__)
 #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3
-    if (cpuid > 2) Setup_Vec_Primitives_sse3(p);
-    if (cpuid > 3) Setup_Vec_Primitives_ssse3(p);
-    if (cpuid > 4) Setup_Vec_Primitives_sse41(p);
+    if (cpuMask & (1 << 3)) Setup_Vec_Primitives_sse3(p);
+    if (cpuMask & (1 << 4)) Setup_Vec_Primitives_ssse3(p);
+    if (cpuMask & (1 << 5)) Setup_Vec_Primitives_sse41(p);
 #endif
 #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 7
-    if (cpuid > 7) Setup_Vec_Primitives_avx2(p);
+    if (cpuMask & (1 << 8)) Setup_Vec_Primitives_avx2(p);
 #endif
 
 #elif defined(_MSC_VER)
-    if (cpuid > 2) Setup_Vec_Primitives_sse3(p);
-    if (cpuid > 3) Setup_Vec_Primitives_ssse3(p);
-    if (cpuid > 4) Setup_Vec_Primitives_sse41(p);
+    if (cpuMask & (1 << 3)) Setup_Vec_Primitives_sse3(p);
+    if (cpuMask & (1 << 4)) Setup_Vec_Primitives_ssse3(p);
+    if (cpuMask & (1 << 5)) Setup_Vec_Primitives_sse41(p);
 
 #if _MSC_VER >= 1700 // VC11
-    if (cpuid > 6 && hasXOP()) Setup_Vec_PixelPrimitives_xop(p);
-    if (cpuid > 7) Setup_Vec_Primitives_avx2(p);
+    if ((cpuMask & (1 << 7)) && hasXOP()) Setup_Vec_PixelPrimitives_xop(p);
+    if (cpuMask & (1 << 8)) Setup_Vec_Primitives_avx2(p);
 #endif
 
 #endif
diff -r 99be942b3855 -r 8636384aba19 source/test/testbench.cpp
--- a/source/test/testbench.cpp	Thu Sep 26 16:19:00 2013 -0500
+++ b/source/test/testbench.cpp	Thu Sep 26 00:00:53 2013 -0500
@@ -106,7 +106,7 @@
 #if ENABLE_VECTOR_PRIMITIVES
         EncoderPrimitives vecprim;
         memset(&vecprim, 0, sizeof(vecprim));
-        Setup_Vector_Primitives(vecprim, i);
+        Setup_Vector_Primitives(vecprim, 1 << i);
         printf("Testing intrinsic primitives: %s (%d)\n", CpuType[i], i);
         for (size_t h = 0; h < sizeof(harness) / sizeof(TestHarness*); h++)
         {
@@ -146,7 +146,7 @@
     EncoderPrimitives optprim;
     memset(&optprim, 0, sizeof(optprim));
 #if ENABLE_VECTOR_PRIMITIVES
-    Setup_Vector_Primitives(optprim, cpuid);
+    Setup_Vector_Primitives(optprim, (1 << (cpuid + 1)) - 1);
 #endif
 #if ENABLE_ASM_PRIMITIVES
     Setup_Assembly_Primitives(optprim, cpuid);


More information about the x265-devel mailing list