summaryrefslogtreecommitdiff
path: root/multimedia/svt-av1/files/patch-revert
blob: 48c6da4a92a2886a9e1790e99978c3df033d10aa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
Revert https://github.com/AOMediaCodec/SVT-AV1/commit/fedc119668a4
due to https://github.com/AOMediaCodec/SVT-AV1/issues/1613

--- CMakeLists.txt.orig	2020-11-29 07:10:56 UTC
+++ CMakeLists.txt
@@ -276,6 +276,5 @@ if(BUILD_TESTING)
 endif()
 
 add_subdirectory(third_party/fastfeat)
-add_subdirectory(third_party/cpuinfo)
 
 install(DIRECTORY ${PROJECT_SOURCE_DIR}/Source/API/ DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}/svt-av1" FILES_MATCHING PATTERN "*.h")
--- Source/Lib/Common/Codec/CMakeLists.txt.orig	2020-11-29 07:10:56 UTC
+++ Source/Lib/Common/Codec/CMakeLists.txt
@@ -32,16 +32,14 @@ include_directories(${PROJECT_SOURCE_DIR}/Source/API/
     ${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_AVX2/
     ${PROJECT_SOURCE_DIR}/Source/Lib/Common/ASM_AVX512/
     ${PROJECT_SOURCE_DIR}/Source/Lib/Encoder/Codec/
-    ${PROJECT_SOURCE_DIR}/third_party/fastfeat/
-    ${PROJECT_SOURCE_DIR}/third_party/cpuinfo/include/)
+    ${PROJECT_SOURCE_DIR}/third_party/fastfeat/)
 else ()
 # Include Encoder Subdirectories
 include_directories(${PROJECT_SOURCE_DIR}/Source/API/
     ${PROJECT_SOURCE_DIR}/Source/Lib/Common/Codec/
     ${PROJECT_SOURCE_DIR}/Source/Lib/Common/C_DEFAULT/
     ${PROJECT_SOURCE_DIR}/Source/Lib/Encoder/Codec/
-    ${PROJECT_SOURCE_DIR}/third_party/fastfeat/
-    ${PROJECT_SOURCE_DIR}/third_party/cpuinfo/include/)
+    ${PROJECT_SOURCE_DIR}/third_party/fastfeat/)
 endif ()
 file(GLOB all_files
     "*.h"
--- Source/Lib/Common/Codec/common_dsp_rtcd.c.orig	2020-11-29 07:10:56 UTC
+++ Source/Lib/Common/Codec/common_dsp_rtcd.c
@@ -17,9 +17,6 @@
 #include "EbPackUnPack_C.h"
 #include "EbAvcStyleMcp.h"
 
-// for get_cpu_flags
-#include "cpuinfo.h"
-
 /*
  * DSP deprecated flags
  */
@@ -69,31 +66,121 @@ int64_t svt_av1_block_error_c(const TranLow *coeff, co
 /**************************************
  * Instruction Set Support
  **************************************/
+#ifdef ARCH_X86_64
+// Helper Functions
+static INLINE void run_cpuid(int eax, int ecx, int* abcd) {
+#ifdef _WIN32
+    __cpuidex(abcd, eax, ecx);
+#else
+    int ebx = 0, edx = 0;
+#if defined(__i386__) && defined(__PIC__)
+    /* in case of PIC under 32-bit EBX cannot be clobbered */
+    __asm__("movl %%ebx, %%edi \n\t cpuid \n\t xchgl %%ebx, %%edi"
+            : "=D"(ebx),
+#else
+    __asm__("cpuid"
+    : "+b"(ebx),
+#endif
+    "+a"(eax),
+    "+c"(ecx),
+    "=d"(edx));
+    abcd[0] = eax;
+    abcd[1] = ebx;
+    abcd[2] = ecx;
+    abcd[3] = edx;
+#endif
+}
 
+static INLINE int32_t check_xcr0_ymm() {
+    uint32_t xcr0;
+#ifdef _WIN32
+    xcr0 = (uint32_t)_xgetbv(0); /* min VS2010 SP1 compiler is required */
+#else
+    __asm__("xgetbv" : "=a"(xcr0) : "c"(0) : "%edx");
+#endif
+    return ((xcr0 & 6) == 6); /* checking if xmm and ymm state are enabled in XCR0 */
+}
+
+static int32_t check_4thgen_intel_core_features() {
+    int       abcd[4];
+    const int fma_movbe_osxsave_mask = ((1 << 12) | (1 << 22) | (1 << 27));
+    const int avx2_bmi12_mask        = (1 << 5) | (1 << 3) | (1 << 8);
+
+    /* CPUID.(EAX=01H, ECX=0H):ECX.FMA[bit 12]==1   &&
+    CPUID.(EAX=01H, ECX=0H):ECX.MOVBE[bit 22]==1 &&
+    CPUID.(EAX=01H, ECX=0H):ECX.OSXSAVE[bit 27]==1 */
+    run_cpuid(1, 0, abcd);
+    if ((abcd[2] & fma_movbe_osxsave_mask) != fma_movbe_osxsave_mask) return 0;
+
+    if (!check_xcr0_ymm()) return 0;
+
+    /*  CPUID.(EAX=07H, ECX=0H):EBX.AVX2[bit 5]==1  &&
+    CPUID.(EAX=07H, ECX=0H):EBX.BMI1[bit 3]==1  &&
+    CPUID.(EAX=07H, ECX=0H):EBX.BMI2[bit 8]==1  */
+    run_cpuid(7, 0, abcd);
+    if ((abcd[1] & avx2_bmi12_mask) != avx2_bmi12_mask) return 0;
+    /* CPUID.(EAX=80000001H):ECX.LZCNT[bit 5]==1 */
+    run_cpuid(0x80000001, 0, abcd);
+    if ((abcd[2] & (1 << 5)) == 0) return 0;
+    return 1;
+}
+
+static INLINE int check_xcr0_zmm() {
+    uint32_t xcr0;
+    uint32_t zmm_ymm_xmm = (7 << 5) | (1 << 2) | (1 << 1);
+#ifdef _WIN32
+    xcr0 = (uint32_t)_xgetbv(0); /* min VS2010 SP1 compiler is required */
+#else
+    __asm__("xgetbv" : "=a"(xcr0) : "c"(0) : "%edx");
+#endif
+    return ((xcr0 & zmm_ymm_xmm) ==
+            zmm_ymm_xmm); /* check if xmm, ymm and zmm state are enabled in XCR0 */
+}
+
+static int32_t can_use_intel_avx512() {
+    int abcd[4];
+
+    /*  CPUID.(EAX=07H, ECX=0):EBX[bit 16]==1 AVX512F
+    CPUID.(EAX=07H, ECX=0):EBX[bit 17] AVX512DQ
+    CPUID.(EAX=07H, ECX=0):EBX[bit 28] AVX512CD
+    CPUID.(EAX=07H, ECX=0):EBX[bit 30] AVX512BW
+    CPUID.(EAX=07H, ECX=0):EBX[bit 31] AVX512VL */
+
+    const int avx512_ebx_mask = (1u << 16) // AVX-512F
+        | (1u << 17) // AVX-512DQ
+        | (1u << 28) // AVX-512CD
+        | (1u << 30) // AVX-512BW
+        | (1u << 31); // AVX-512VL
+
+    if (!check_4thgen_intel_core_features()) return 0;
+
+    // ensure OS supports ZMM registers (and YMM, and XMM)
+    if (!check_xcr0_zmm()) return 0;
+
+    run_cpuid(7, 0, abcd);
+    if ((abcd[1] & avx512_ebx_mask) != avx512_ebx_mask) return 0;
+
+    return 1;
+}
+
 CPU_FLAGS get_cpu_flags() {
     CPU_FLAGS flags = 0;
 
-    // safe to call multiple times, and threadsafe
-    // also correctly checks whether the OS saves AVX(2|512) registers
-    cpuinfo_initialize();
+    /* To detail tests CPU features, requires more accurate implementation.
+        Documentation help:
+        https://docs.microsoft.com/en-us/cpp/intrinsics/cpuid-cpuidex?redirectedfrom=MSDN&view=vs-2019
+    */
 
-    flags |= cpuinfo_has_x86_mmx() ? CPU_FLAGS_MMX : 0;
-    flags |= cpuinfo_has_x86_sse() ? CPU_FLAGS_SSE : 0;
-    flags |= cpuinfo_has_x86_sse2() ? CPU_FLAGS_SSE2 : 0;
-    flags |= cpuinfo_has_x86_sse3() ? CPU_FLAGS_SSE3 : 0;
-    flags |= cpuinfo_has_x86_ssse3() ? CPU_FLAGS_SSSE3 : 0;
-    flags |= cpuinfo_has_x86_sse4_1() ? CPU_FLAGS_SSE4_1 : 0;
-    flags |= cpuinfo_has_x86_sse4_2() ? CPU_FLAGS_SSE4_2 : 0;
+    if (check_4thgen_intel_core_features()) {
+        flags |= CPU_FLAGS_MMX | CPU_FLAGS_SSE | CPU_FLAGS_SSE2 | CPU_FLAGS_SSE3 | CPU_FLAGS_SSSE3 |
+                 CPU_FLAGS_SSE4_1 | CPU_FLAGS_SSE4_2 | CPU_FLAGS_AVX | CPU_FLAGS_AVX2;
+    }
 
-    flags |= cpuinfo_has_x86_avx() ? CPU_FLAGS_AVX : 0;
-    flags |= cpuinfo_has_x86_avx2() ? CPU_FLAGS_AVX2 : 0;
+    if (can_use_intel_avx512()) {
+        flags |= CPU_FLAGS_AVX512F | CPU_FLAGS_AVX512DQ | CPU_FLAGS_AVX512CD | CPU_FLAGS_AVX512BW |
+                 CPU_FLAGS_AVX512VL;
+    }
 
-    flags |= cpuinfo_has_x86_avx512f() ? CPU_FLAGS_AVX512F : 0;
-    flags |= cpuinfo_has_x86_avx512dq() ? CPU_FLAGS_AVX512DQ : 0;
-    flags |= cpuinfo_has_x86_avx512cd() ? CPU_FLAGS_AVX512CD : 0;
-    flags |= cpuinfo_has_x86_avx512bw() ? CPU_FLAGS_AVX512BW : 0;
-    flags |= cpuinfo_has_x86_avx512vl() ? CPU_FLAGS_AVX512VL : 0;
-
     return flags;
 }
 
@@ -105,6 +192,7 @@ CPU_FLAGS get_cpu_flags_to_use() {
 #endif
     return flags;
 }
+#endif
 
 #ifdef ARCH_X86_64
 #ifndef NON_AVX512_SUPPORT
--- Source/Lib/Decoder/CMakeLists.txt.orig	2020-11-29 07:10:56 UTC
+++ Source/Lib/Decoder/CMakeLists.txt
@@ -98,8 +98,7 @@ endif()
 set_target_properties(SvtAv1Dec PROPERTIES VERSION ${DEC_VERSION})
 set_target_properties(SvtAv1Dec PROPERTIES SOVERSION ${DEC_VERSION_MAJOR})
 add_dependencies(SvtAv1Dec EbVersionHeaderGen)
-target_link_libraries(SvtAv1Dec PUBLIC ${PLATFORM_LIBS})
-target_link_libraries(SvtAv1Dec PRIVATE cpuinfo_public)
+target_link_libraries(SvtAv1Dec ${PLATFORM_LIBS})
 install(TARGETS SvtAv1Dec DESTINATION "${CMAKE_INSTALL_LIBDIR}")
 
 configure_file(pkg-config.pc.in ${CMAKE_BINARY_DIR}/SvtAv1Dec.pc @ONLY)
--- Source/Lib/Encoder/CMakeLists.txt.orig	2020-11-29 07:10:56 UTC
+++ Source/Lib/Encoder/CMakeLists.txt
@@ -129,8 +129,7 @@ endif()
 
 set_target_properties(SvtAv1Enc PROPERTIES VERSION ${ENC_VERSION})
 set_target_properties(SvtAv1Enc PROPERTIES SOVERSION ${ENC_VERSION_MAJOR})
-target_link_libraries(SvtAv1Enc PUBLIC ${PLATFORM_LIBS})
-target_link_libraries(SvtAv1Enc PRIVATE cpuinfo_public)
+target_link_libraries(SvtAv1Enc ${PLATFORM_LIBS})
 install(TARGETS SvtAv1Enc DESTINATION "${CMAKE_INSTALL_LIBDIR}")
 
 configure_file(pkg-config.pc.in ${CMAKE_BINARY_DIR}/SvtAv1Enc.pc @ONLY)
--- test/CMakeLists.txt.orig	2020-11-29 07:10:56 UTC
+++ test/CMakeLists.txt
@@ -86,7 +86,6 @@ set(lib_list
     $<TARGET_OBJECTS:ENCODER_ASM_AVX2>
     $<TARGET_OBJECTS:ENCODER_ASM_AVX512>
     $<TARGET_OBJECTS:ENCODER_GLOBALS>
-    cpuinfo_public
     gtest_all)
 if(UNIX)
   # App Source Files