react-native-vision-camera-spoof-detector 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/.gitattributes +2 -0
  2. package/.gitignore +27 -0
  3. package/CHANGELOG.md +2 -2
  4. package/CONTRIBUTING.md +2 -2
  5. package/README.md +442 -443
  6. package/android/build.gradle +12 -4
  7. package/android/src/main/cpp/CMakeLists.txt +101 -94
  8. package/android/src/main/cpp/libyuv/.clang-format +6 -6
  9. package/android/src/main/cpp/libyuv/.gn +40 -40
  10. package/android/src/main/cpp/libyuv/.vpython3 +410 -410
  11. package/android/src/main/cpp/libyuv/AUTHORS +7 -7
  12. package/android/src/main/cpp/libyuv/Android.bp +202 -202
  13. package/android/src/main/cpp/libyuv/Android.mk +106 -106
  14. package/android/src/main/cpp/libyuv/BUILD.gn +490 -490
  15. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +70 -70
  16. package/android/src/main/cpp/libyuv/CMakeLists.txt +259 -252
  17. package/android/src/main/cpp/libyuv/DEPS +935 -935
  18. package/android/src/main/cpp/libyuv/DIR_METADATA +3 -3
  19. package/android/src/main/cpp/libyuv/LICENSE +29 -29
  20. package/android/src/main/cpp/libyuv/OWNERS +11 -11
  21. package/android/src/main/cpp/libyuv/PATENTS +23 -23
  22. package/android/src/main/cpp/libyuv/PRESUBMIT.py +65 -65
  23. package/android/src/main/cpp/libyuv/README.chromium +11 -11
  24. package/android/src/main/cpp/libyuv/README.md +19 -19
  25. package/android/src/main/cpp/libyuv/build_overrides/build.gni +60 -60
  26. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +19 -19
  27. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +17 -17
  28. package/android/src/main/cpp/libyuv/codereview.settings +5 -5
  29. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +409 -409
  30. package/android/src/main/cpp/libyuv/docs/environment_variables.md +64 -64
  31. package/android/src/main/cpp/libyuv/docs/feature_detection.md +108 -108
  32. package/android/src/main/cpp/libyuv/docs/filtering.md +196 -196
  33. package/android/src/main/cpp/libyuv/docs/formats.md +208 -208
  34. package/android/src/main/cpp/libyuv/docs/getting_started.md +296 -296
  35. package/android/src/main/cpp/libyuv/docs/rotation.md +107 -107
  36. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +29 -29
  37. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +68 -68
  38. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +111 -111
  39. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +112 -112
  40. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +1117 -1117
  41. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +2335 -2335
  42. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +203 -203
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +394 -394
  44. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +147 -147
  45. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +99 -99
  46. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +1949 -1949
  47. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +195 -195
  48. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +1131 -1131
  49. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +296 -296
  50. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +37 -37
  51. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +265 -265
  52. package/android/src/main/cpp/libyuv/include/libyuv/row.h +6738 -6738
  53. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +2154 -2154
  54. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +336 -336
  55. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +76 -76
  56. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +42 -42
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +1726 -1726
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +51 -51
  59. package/android/src/main/cpp/libyuv/include/libyuv/version.h +16 -16
  60. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +222 -222
  61. package/android/src/main/cpp/libyuv/include/libyuv.h +33 -33
  62. package/android/src/main/cpp/libyuv/infra/config/OWNERS +3 -3
  63. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +17 -17
  64. package/android/src/main/cpp/libyuv/infra/config/README.md +2 -2
  65. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +6 -6
  66. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +144 -144
  67. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +1185 -1185
  68. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +9 -9
  69. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +246 -246
  70. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +385 -385
  71. package/android/src/main/cpp/libyuv/infra/config/main.star +402 -402
  72. package/android/src/main/cpp/libyuv/infra/config/project.cfg +16 -16
  73. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +111 -111
  74. package/android/src/main/cpp/libyuv/libyuv.gni +34 -34
  75. package/android/src/main/cpp/libyuv/libyuv.gyp +149 -149
  76. package/android/src/main/cpp/libyuv/libyuv.gypi +87 -87
  77. package/android/src/main/cpp/libyuv/linux.mk +96 -96
  78. package/android/src/main/cpp/libyuv/public.mk +13 -13
  79. package/android/src/main/cpp/libyuv/pylintrc +49 -49
  80. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +74 -74
  81. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +56 -56
  82. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +15 -15
  83. package/android/src/main/cpp/libyuv/source/compare.cc +435 -435
  84. package/android/src/main/cpp/libyuv/source/compare_common.cc +74 -74
  85. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +362 -362
  86. package/android/src/main/cpp/libyuv/source/compare_neon.cc +96 -96
  87. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +223 -223
  88. package/android/src/main/cpp/libyuv/source/compare_win.cc +241 -241
  89. package/android/src/main/cpp/libyuv/source/convert.cc +4746 -4746
  90. package/android/src/main/cpp/libyuv/source/convert_argb.cc +9179 -9179
  91. package/android/src/main/cpp/libyuv/source/convert_from.cc +866 -866
  92. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +3671 -3671
  93. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +602 -602
  94. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +391 -391
  95. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +288 -288
  96. package/android/src/main/cpp/libyuv/source/cpu_id.cc +496 -496
  97. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +580 -580
  98. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +71 -71
  99. package/android/src/main/cpp/libyuv/source/planar_functions.cc +5663 -5663
  100. package/android/src/main/cpp/libyuv/source/rotate.cc +1241 -1241
  101. package/android/src/main/cpp/libyuv/source/rotate_any.cc +76 -76
  102. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +259 -259
  103. package/android/src/main/cpp/libyuv/source/rotate_common.cc +208 -208
  104. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +505 -505
  105. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +233 -233
  106. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +219 -219
  107. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +273 -273
  108. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +174 -174
  109. package/android/src/main/cpp/libyuv/source/rotate_win.cc +253 -253
  110. package/android/src/main/cpp/libyuv/source/row_any.cc +2519 -2519
  111. package/android/src/main/cpp/libyuv/source/row_common.cc +4461 -4461
  112. package/android/src/main/cpp/libyuv/source/row_gcc.cc +9570 -9570
  113. package/android/src/main/cpp/libyuv/source/row_lasx.cc +2343 -2343
  114. package/android/src/main/cpp/libyuv/source/row_lsx.cc +3030 -3030
  115. package/android/src/main/cpp/libyuv/source/row_neon.cc +4026 -4026
  116. package/android/src/main/cpp/libyuv/source/row_neon64.cc +5617 -5617
  117. package/android/src/main/cpp/libyuv/source/row_rvv.cc +2599 -2599
  118. package/android/src/main/cpp/libyuv/source/row_sme.cc +1183 -1183
  119. package/android/src/main/cpp/libyuv/source/row_sve.cc +1088 -1088
  120. package/android/src/main/cpp/libyuv/source/row_win.cc +6453 -6453
  121. package/android/src/main/cpp/libyuv/source/scale.cc +2710 -2710
  122. package/android/src/main/cpp/libyuv/source/scale_any.cc +991 -991
  123. package/android/src/main/cpp/libyuv/source/scale_argb.cc +1158 -1158
  124. package/android/src/main/cpp/libyuv/source/scale_common.cc +1977 -1977
  125. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +2947 -2947
  126. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +739 -739
  127. package/android/src/main/cpp/libyuv/source/scale_neon.cc +1449 -1449
  128. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +1552 -1552
  129. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +82 -82
  130. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +1971 -1971
  131. package/android/src/main/cpp/libyuv/source/scale_sme.cc +555 -555
  132. package/android/src/main/cpp/libyuv/source/scale_uv.cc +1159 -1159
  133. package/android/src/main/cpp/libyuv/source/scale_win.cc +1392 -1392
  134. package/android/src/main/cpp/libyuv/source/test.sh +35 -35
  135. package/android/src/main/cpp/libyuv/source/video_common.cc +62 -62
  136. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +4 -4
  137. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +931 -931
  138. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +164 -164
  139. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +21 -21
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +13 -13
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +13 -13
  142. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +38 -38
  143. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +3 -3
  144. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +9 -9
  145. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +3 -3
  146. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +15 -15
  147. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +25 -25
  148. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +43 -43
  149. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +848 -848
  150. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +739 -739
  151. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +2867 -2867
  152. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +2133 -2133
  153. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +427 -427
  154. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +63 -63
  155. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +160 -160
  156. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +4731 -4731
  157. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +334 -334
  158. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +962 -962
  159. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +590 -590
  160. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +465 -465
  161. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +280 -280
  162. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +1135 -1135
  163. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +249 -249
  164. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +12 -12
  165. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +7 -7
  166. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +5 -5
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +10 -10
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +7 -7
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +3 -3
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +3 -3
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +3 -3
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +23 -23
  173. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +581 -581
  174. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +232 -232
  175. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +112 -112
  176. package/android/src/main/cpp/libyuv/util/Makefile +9 -9
  177. package/android/src/main/cpp/libyuv/util/color.cc +120 -120
  178. package/android/src/main/cpp/libyuv/util/compare.cc +67 -67
  179. package/android/src/main/cpp/libyuv/util/cpuid.c +211 -211
  180. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +27 -27
  181. package/android/src/main/cpp/libyuv/util/psnr.cc +291 -291
  182. package/android/src/main/cpp/libyuv/util/psnr.h +47 -47
  183. package/android/src/main/cpp/libyuv/util/psnr_main.cc +620 -620
  184. package/android/src/main/cpp/libyuv/util/ssim.cc +364 -364
  185. package/android/src/main/cpp/libyuv/util/ssim.h +38 -38
  186. package/android/src/main/cpp/libyuv/util/yuvconstants.c +114 -114
  187. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +367 -367
  188. package/android/src/main/cpp/libyuv/winarm.mk +47 -47
  189. package/package.json +86 -84
  190. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  191. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  192. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  193. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  194. package/android/.gradle/8.9/gc.properties +0 -0
  195. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  196. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  197. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -1,496 +1,496 @@
1
- /*
2
- * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3
- *
4
- * Use of this source code is governed by a BSD-style license
5
- * that can be found in the LICENSE file in the root of the source
6
- * tree. An additional intellectual property rights grant can be found
7
- * in the file PATENTS. All contributing project authors may
8
- * be found in the AUTHORS file in the root of the source tree.
9
- */
10
-
11
- #include "libyuv/cpu_id.h"
12
-
13
- #if defined(_MSC_VER)
14
- #include <intrin.h> // For __cpuidex()
15
- #endif
16
- #if !defined(__pnacl__) && !defined(__CLR_VER) && \
17
- !defined(__native_client__) && (defined(_M_IX86) || defined(_M_X64)) && \
18
- defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
19
- #include <immintrin.h> // For _xgetbv()
20
- #endif
21
-
22
- // For ArmCpuCaps() but unittested on all platforms
23
- #include <stdio.h> // For fopen()
24
- #include <string.h>
25
-
26
- #if defined(__linux__) && (defined(__aarch64__) || defined(__loongarch__))
27
- #include <sys/auxv.h> // For getauxval()
28
- #endif
29
-
30
- #if defined(_WIN32) && defined(__aarch64__)
31
- #undef WIN32_LEAN_AND_MEAN
32
- #define WIN32_LEAN_AND_MEAN
33
- #undef WIN32_EXTRA_LEAN
34
- #define WIN32_EXTRA_LEAN
35
- #include <windows.h> // For IsProcessorFeaturePresent()
36
- #endif
37
-
38
- #if defined(__APPLE__) && defined(__aarch64__)
39
- #include <sys/sysctl.h> // For sysctlbyname()
40
- #endif
41
-
42
- #ifdef __cplusplus
43
- namespace libyuv {
44
- extern "C" {
45
- #endif
46
-
47
- // For functions that use the stack and have runtime checks for overflow,
48
- // use SAFEBUFFERS to avoid additional check.
49
- #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) && \
50
- !defined(__clang__)
51
- #define SAFEBUFFERS __declspec(safebuffers)
52
- #else
53
- #define SAFEBUFFERS
54
- #endif
55
-
56
- // cpu_info_ variable for SIMD instruction sets detected.
57
- LIBYUV_API int cpu_info_ = 0;
58
-
59
- // Low level cpuid for X86.
60
- #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
61
- defined(__x86_64__)) && \
62
- !defined(__pnacl__) && !defined(__CLR_VER)
63
- LIBYUV_API
64
- void CpuId(int info_eax, int info_ecx, int* cpu_info) {
65
- #if defined(_MSC_VER)
66
- // Visual C version uses intrinsic or inline x86 assembly.
67
- #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
68
- __cpuidex(cpu_info, info_eax, info_ecx);
69
- #elif defined(_M_IX86)
70
- __asm {
71
- mov eax, info_eax
72
- mov ecx, info_ecx
73
- mov edi, cpu_info
74
- cpuid
75
- mov [edi], eax
76
- mov [edi + 4], ebx
77
- mov [edi + 8], ecx
78
- mov [edi + 12], edx
79
- }
80
- #else // Visual C but not x86
81
- if (info_ecx == 0) {
82
- __cpuid(cpu_info, info_eax);
83
- } else {
84
- cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0u;
85
- }
86
- #endif
87
- // GCC version uses inline x86 assembly.
88
- #else // defined(_MSC_VER)
89
- int info_ebx, info_edx;
90
- asm volatile(
91
- #if defined(__i386__) && defined(__PIC__)
92
- // Preserve ebx for fpic 32 bit.
93
- "mov %%ebx, %%edi \n"
94
- "cpuid \n"
95
- "xchg %%edi, %%ebx \n"
96
- : "=D"(info_ebx),
97
- #else
98
- "cpuid \n"
99
- : "=b"(info_ebx),
100
- #endif // defined( __i386__) && defined(__PIC__)
101
- "+a"(info_eax), "+c"(info_ecx), "=d"(info_edx));
102
- cpu_info[0] = info_eax;
103
- cpu_info[1] = info_ebx;
104
- cpu_info[2] = info_ecx;
105
- cpu_info[3] = info_edx;
106
- #endif // defined(_MSC_VER)
107
- }
108
- #else // (defined(_M_IX86) || defined(_M_X64) ...
109
- LIBYUV_API
110
- void CpuId(int eax, int ecx, int* cpu_info) {
111
- (void)eax;
112
- (void)ecx;
113
- cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0;
114
- }
115
- #endif
116
-
117
- // For VS2010 and earlier emit can be used:
118
- // _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 // For VS2010 and earlier.
119
- // __asm {
120
- // xor ecx, ecx // xcr 0
121
- // xgetbv
122
- // mov xcr0, eax
123
- // }
124
- // For VS2013 and earlier 32 bit, the _xgetbv(0) optimizer produces bad code.
125
- // https://code.google.com/p/libyuv/issues/detail?id=529
126
- #if defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900)
127
- #pragma optimize("g", off)
128
- #endif
129
- #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
130
- defined(__x86_64__)) && \
131
- !defined(__pnacl__) && !defined(__CLR_VER) && !defined(__native_client__)
132
- // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers.
133
- static int GetXCR0() {
134
- int xcr0 = 0;
135
- #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
136
- xcr0 = (int)_xgetbv(0); // VS2010 SP1 required. NOLINT
137
- #elif defined(__i386__) || defined(__x86_64__)
138
- asm(".byte 0x0f, 0x01, 0xd0" : "=a"(xcr0) : "c"(0) : "%edx");
139
- #endif // defined(__i386__) || defined(__x86_64__)
140
- return xcr0;
141
- }
142
- #else
143
- // xgetbv unavailable to query for OSSave support. Return 0.
144
- #define GetXCR0() 0
145
- #endif // defined(_M_IX86) || defined(_M_X64) ..
146
- // Return optimization to previous setting.
147
- #if defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900)
148
- #pragma optimize("g", on)
149
- #endif
150
-
151
- static int cpuinfo_search(const char* cpuinfo_line,
152
- const char* needle,
153
- int needle_len) {
154
- const char* p = strstr(cpuinfo_line, needle);
155
- return p && (p[needle_len] == ' ' || p[needle_len] == '\n');
156
- }
157
-
158
- // Based on libvpx arm_cpudetect.c
159
- // For Arm, but public to allow testing on any CPU
160
- LIBYUV_API SAFEBUFFERS int ArmCpuCaps(const char* cpuinfo_name) {
161
- char cpuinfo_line[512];
162
- FILE* f = fopen(cpuinfo_name, "re");
163
- if (!f) {
164
- // Assume Neon if /proc/cpuinfo is unavailable.
165
- // This will occur for Chrome sandbox for Pepper or Render process.
166
- return kCpuHasNEON;
167
- }
168
- memset(cpuinfo_line, 0, sizeof(cpuinfo_line));
169
- int features = 0;
170
- while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f)) {
171
- if (memcmp(cpuinfo_line, "Features", 8) == 0) {
172
- if (cpuinfo_search(cpuinfo_line, " neon", 5)) {
173
- features |= kCpuHasNEON;
174
- }
175
- }
176
- }
177
- fclose(f);
178
- return features;
179
- }
180
-
181
- #ifdef __aarch64__
182
- #ifdef __linux__
183
- // Define hwcap values ourselves: building with an old auxv header where these
184
- // hwcap values are not defined should not prevent features from being enabled.
185
- #define YUV_AARCH64_HWCAP_ASIMDDP (1UL << 20)
186
- #define YUV_AARCH64_HWCAP_SVE (1UL << 22)
187
- #define YUV_AARCH64_HWCAP2_SVE2 (1UL << 1)
188
- #define YUV_AARCH64_HWCAP2_SVEF32MM (1UL << 10)
189
- #define YUV_AARCH64_HWCAP2_I8MM (1UL << 13)
190
- #define YUV_AARCH64_HWCAP2_SME (1UL << 23)
191
- #define YUV_AARCH64_HWCAP2_SME2 (1UL << 37)
192
-
193
- // For AArch64, but public to allow testing on any CPU.
194
- LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(unsigned long hwcap,
195
- unsigned long hwcap2) {
196
- // Neon is mandatory on AArch64, so enable regardless of hwcaps.
197
- int features = kCpuHasNEON;
198
-
199
- // Don't try to enable later extensions unless earlier extensions are also
200
- // reported available. Some of these constraints aren't strictly required by
201
- // the architecture, but are satisfied by all micro-architectures of
202
- // interest. This also avoids an issue on some emulators where true
203
- // architectural constraints are not satisfied, e.g. SVE2 may be reported as
204
- // available while SVE is not.
205
- if (hwcap & YUV_AARCH64_HWCAP_ASIMDDP) {
206
- features |= kCpuHasNeonDotProd;
207
- if (hwcap2 & YUV_AARCH64_HWCAP2_I8MM) {
208
- features |= kCpuHasNeonI8MM;
209
- if (hwcap & YUV_AARCH64_HWCAP_SVE) {
210
- features |= kCpuHasSVE;
211
- if (hwcap2 & YUV_AARCH64_HWCAP2_SVEF32MM) {
212
- features |= kCpuHasSVEF32MM;
213
- }
214
- if (hwcap2 & YUV_AARCH64_HWCAP2_SVE2) {
215
- features |= kCpuHasSVE2;
216
- }
217
- }
218
- // SME may be present without SVE
219
- if (hwcap2 & YUV_AARCH64_HWCAP2_SME) {
220
- features |= kCpuHasSME;
221
- if (hwcap2 & YUV_AARCH64_HWCAP2_SME2) {
222
- features |= kCpuHasSME2;
223
- }
224
- }
225
- }
226
- }
227
- return features;
228
- }
229
-
230
- #elif defined(_WIN32)
231
- // For AArch64, but public to allow testing on any CPU.
232
- LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() {
233
- // Neon is mandatory on AArch64, so enable unconditionally.
234
- int features = kCpuHasNEON;
235
-
236
- // For more information on IsProcessorFeaturePresent(), see:
237
- // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent#parameters
238
- #ifdef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE
239
- if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE)) {
240
- features |= kCpuHasNeonDotProd;
241
- }
242
- #endif
243
- // No Neon I8MM or SVE feature detection available here at time of writing.
244
- return features;
245
- }
246
-
247
- #elif defined(__APPLE__)
248
- static bool have_feature(const char* feature) {
249
- // For more information on sysctlbyname(), see:
250
- // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
251
- int64_t feature_present = 0;
252
- size_t size = sizeof(feature_present);
253
- if (sysctlbyname(feature, &feature_present, &size, NULL, 0) != 0) {
254
- return false;
255
- }
256
- return feature_present;
257
- }
258
-
259
- // For AArch64, but public to allow testing on any CPU.
260
- LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() {
261
- // Neon is mandatory on AArch64, so enable unconditionally.
262
- int features = kCpuHasNEON;
263
-
264
- if (have_feature("hw.optional.arm.FEAT_DotProd")) {
265
- features |= kCpuHasNeonDotProd;
266
- if (have_feature("hw.optional.arm.FEAT_I8MM")) {
267
- features |= kCpuHasNeonI8MM;
268
- if (have_feature("hw.optional.arm.FEAT_SME")) {
269
- features |= kCpuHasSME;
270
- if (have_feature("hw.optional.arm.FEAT_SME2")) {
271
- features |= kCpuHasSME2;
272
- }
273
- }
274
- }
275
- }
276
- // No SVE feature detection available here at time of writing.
277
- return features;
278
- }
279
-
280
- #else // !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__)
281
- // For AArch64, but public to allow testing on any CPU.
282
- LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() {
283
- // Neon is mandatory on AArch64, so enable unconditionally.
284
- int features = kCpuHasNEON;
285
-
286
- // TODO(libyuv:980) support feature detection on other platforms.
287
-
288
- return features;
289
- }
290
- #endif
291
- #endif // defined(__aarch64__)
292
-
293
- LIBYUV_API SAFEBUFFERS int RiscvCpuCaps(const char* cpuinfo_name) {
294
- char cpuinfo_line[512];
295
- int flag = 0;
296
- FILE* f = fopen(cpuinfo_name, "re");
297
- if (!f) {
298
- #if defined(__riscv_vector)
299
- // Assume RVV if /proc/cpuinfo is unavailable.
300
- // This will occur for Chrome sandbox for Pepper or Render process.
301
- return kCpuHasRVV;
302
- #else
303
- return 0;
304
- #endif
305
- }
306
- memset(cpuinfo_line, 0, sizeof(cpuinfo_line));
307
- while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f)) {
308
- if (memcmp(cpuinfo_line, "isa", 3) == 0) {
309
- // ISA string must begin with rv64{i,e,g} for a 64-bit processor.
310
- char* isa = strstr(cpuinfo_line, "rv64");
311
- if (isa) {
312
- size_t isa_len = strlen(isa);
313
- char* extensions;
314
- size_t extensions_len = 0;
315
- size_t std_isa_len;
316
- // Remove the new-line character at the end of string
317
- if (isa[isa_len - 1] == '\n') {
318
- isa[--isa_len] = '\0';
319
- }
320
- // 5 ISA characters
321
- if (isa_len < 5) {
322
- fclose(f);
323
- return 0;
324
- }
325
- // Skip {i,e,g} canonical checking.
326
- // Skip rvxxx
327
- isa += 5;
328
- // Find the very first occurrence of 's', 'x' or 'z'.
329
- // To detect multi-letter standard, non-standard, and
330
- // supervisor-level extensions.
331
- extensions = strpbrk(isa, "zxs");
332
- if (extensions) {
333
- // Multi-letter extensions are seperated by a single underscore
334
- // as described in RISC-V User-Level ISA V2.2.
335
- char* ext = strtok(extensions, "_");
336
- extensions_len = strlen(extensions);
337
- while (ext) {
338
- // Search for the ZVFH (Vector FP16) extension.
339
- if (!strcmp(ext, "zvfh")) {
340
- flag |= kCpuHasRVVZVFH;
341
- }
342
- ext = strtok(NULL, "_");
343
- }
344
- }
345
- std_isa_len = isa_len - extensions_len - 5;
346
- // Detect the v in the standard single-letter extensions.
347
- if (memchr(isa, 'v', std_isa_len)) {
348
- // The RVV implied the F extension.
349
- flag |= kCpuHasRVV;
350
- }
351
- }
352
- }
353
- #if defined(__riscv_vector)
354
- // Assume RVV if /proc/cpuinfo is from x86 host running QEMU.
355
- else if ((memcmp(cpuinfo_line, "vendor_id\t: GenuineIntel", 24) == 0) ||
356
- (memcmp(cpuinfo_line, "vendor_id\t: AuthenticAMD", 24) == 0)) {
357
- fclose(f);
358
- return kCpuHasRVV;
359
- }
360
- #endif
361
- }
362
- fclose(f);
363
- return flag;
364
- }
365
-
366
- #if defined(__loongarch__) && defined(__linux__)
367
- // Define hwcap values ourselves: building with an old auxv header where these
368
- // hwcap values are not defined should not prevent features from being enabled.
369
- #define YUV_LOONGARCH_HWCAP_LSX (1 << 4)
370
- #define YUV_LOONGARCH_HWCAP_LASX (1 << 5)
371
-
372
- LIBYUV_API SAFEBUFFERS int LoongArchCpuCaps(void) {
373
- int flag = 0;
374
- unsigned long hwcap = getauxval(AT_HWCAP);
375
-
376
- if (hwcap & YUV_LOONGARCH_HWCAP_LSX)
377
- flag |= kCpuHasLSX;
378
-
379
- if (hwcap & YUV_LOONGARCH_HWCAP_LASX)
380
- flag |= kCpuHasLASX;
381
- return flag;
382
- }
383
- #endif
384
-
385
- static SAFEBUFFERS int GetCpuFlags(void) {
386
- int cpu_info = 0;
387
- #if !defined(__pnacl__) && !defined(__CLR_VER) && \
388
- (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
389
- defined(_M_IX86))
390
- int cpu_info0[4] = {0, 0, 0, 0};
391
- int cpu_info1[4] = {0, 0, 0, 0};
392
- int cpu_info7[4] = {0, 0, 0, 0};
393
- int cpu_einfo7[4] = {0, 0, 0, 0};
394
- int cpu_info24[4] = {0, 0, 0, 0};
395
- int cpu_amdinfo21[4] = {0, 0, 0, 0};
396
- CpuId(0, 0, cpu_info0);
397
- CpuId(1, 0, cpu_info1);
398
- if (cpu_info0[0] >= 7) {
399
- CpuId(7, 0, cpu_info7);
400
- CpuId(7, 1, cpu_einfo7);
401
- CpuId(0x80000021, 0, cpu_amdinfo21);
402
- }
403
- if (cpu_info0[0] >= 0x24) {
404
- CpuId(0x24, 0, cpu_info24);
405
- }
406
- cpu_info = kCpuHasX86 | ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) |
407
- ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) |
408
- ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) |
409
- ((cpu_info1[2] & 0x00100000) ? kCpuHasSSE42 : 0) |
410
- ((cpu_info7[1] & 0x00000200) ? kCpuHasERMS : 0) |
411
- ((cpu_info7[3] & 0x00000010) ? kCpuHasFSMR : 0);
412
-
413
- // AVX requires OS saves YMM registers.
414
- if (((cpu_info1[2] & 0x1c000000) == 0x1c000000) && // AVX and OSXSave
415
- ((GetXCR0() & 6) == 6)) { // Test OS saves YMM registers
416
- cpu_info |= kCpuHasAVX | ((cpu_info7[1] & 0x00000020) ? kCpuHasAVX2 : 0) |
417
- ((cpu_info1[2] & 0x00001000) ? kCpuHasFMA3 : 0) |
418
- ((cpu_info1[2] & 0x20000000) ? kCpuHasF16C : 0) |
419
- ((cpu_einfo7[0] & 0x00000010) ? kCpuHasAVXVNNI : 0) |
420
- ((cpu_einfo7[3] & 0x00000010) ? kCpuHasAVXVNNIINT8 : 0);
421
-
422
- cpu_info |= ((cpu_amdinfo21[0] & 0x00008000) ? kCpuHasERMS : 0);
423
-
424
- // Detect AVX512bw
425
- if ((GetXCR0() & 0xe0) == 0xe0) {
426
- cpu_info |= ((cpu_info7[1] & 0x40000000) ? kCpuHasAVX512BW : 0) |
427
- ((cpu_info7[1] & 0x80000000) ? kCpuHasAVX512VL : 0) |
428
- ((cpu_info7[2] & 0x00000002) ? kCpuHasAVX512VBMI : 0) |
429
- ((cpu_info7[2] & 0x00000040) ? kCpuHasAVX512VBMI2 : 0) |
430
- ((cpu_info7[2] & 0x00000800) ? kCpuHasAVX512VNNI : 0) |
431
- ((cpu_info7[2] & 0x00001000) ? kCpuHasAVX512VBITALG : 0) |
432
- ((cpu_einfo7[3] & 0x00080000) ? kCpuHasAVX10 : 0) |
433
- ((cpu_info7[3] & 0x02000000) ? kCpuHasAMXINT8 : 0);
434
- if (cpu_info0[0] >= 0x24 && (cpu_einfo7[3] & 0x00080000)) {
435
- cpu_info |= ((cpu_info24[1] & 0xFF) >= 2) ? kCpuHasAVX10_2 : 0;
436
- }
437
- }
438
- }
439
- #endif
440
- #if defined(__loongarch__) && defined(__linux__)
441
- cpu_info = LoongArchCpuCaps();
442
- cpu_info |= kCpuHasLOONGARCH;
443
- #endif
444
- #if defined(__aarch64__)
445
- #if defined(__linux__)
446
- // getauxval is supported since Android SDK version 18, minimum at time of
447
- // writing is 21, so should be safe to always use this. If getauxval is
448
- // somehow disabled then getauxval returns 0, which will leave Neon enabled
449
- // since Neon is mandatory on AArch64.
450
- unsigned long hwcap = getauxval(AT_HWCAP);
451
- unsigned long hwcap2 = getauxval(AT_HWCAP2);
452
- cpu_info = AArch64CpuCaps(hwcap, hwcap2);
453
- #else
454
- cpu_info = AArch64CpuCaps();
455
- #endif
456
- cpu_info |= kCpuHasARM;
457
- #endif // __aarch64__
458
- #if defined(__arm__)
459
- // gcc -mfpu=neon defines __ARM_NEON__
460
- // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon.
461
- // For Linux, /proc/cpuinfo can be tested but without that assume Neon.
462
- // Linux arm parse text file for neon detect.
463
- #if defined(__linux__)
464
- cpu_info = ArmCpuCaps("/proc/cpuinfo");
465
- #elif defined(__ARM_NEON__)
466
- cpu_info = kCpuHasNEON;
467
- #else
468
- cpu_info = 0;
469
- #endif
470
- cpu_info |= kCpuHasARM;
471
- #endif // __arm__
472
- #if defined(__riscv) && defined(__linux__)
473
- cpu_info = RiscvCpuCaps("/proc/cpuinfo");
474
- cpu_info |= kCpuHasRISCV;
475
- #endif // __riscv
476
- cpu_info |= kCpuInitialized;
477
- return cpu_info;
478
- }
479
-
480
- // Note that use of this function is not thread safe.
481
- LIBYUV_API
482
- int MaskCpuFlags(int enable_flags) {
483
- int cpu_info = GetCpuFlags() & enable_flags;
484
- SetCpuFlags(cpu_info);
485
- return cpu_info;
486
- }
487
-
488
- LIBYUV_API
489
- int InitCpuFlags(void) {
490
- return MaskCpuFlags(-1);
491
- }
492
-
493
- #ifdef __cplusplus
494
- } // extern "C"
495
- } // namespace libyuv
496
- #endif
1
+ /*
2
+ * Copyright 2011 The LibYuv Project Authors. All rights reserved.
3
+ *
4
+ * Use of this source code is governed by a BSD-style license
5
+ * that can be found in the LICENSE file in the root of the source
6
+ * tree. An additional intellectual property rights grant can be found
7
+ * in the file PATENTS. All contributing project authors may
8
+ * be found in the AUTHORS file in the root of the source tree.
9
+ */
10
+
11
+ #include "libyuv/cpu_id.h"
12
+
13
+ #if defined(_MSC_VER)
14
+ #include <intrin.h> // For __cpuidex()
15
+ #endif
16
+ #if !defined(__pnacl__) && !defined(__CLR_VER) && \
17
+ !defined(__native_client__) && (defined(_M_IX86) || defined(_M_X64)) && \
18
+ defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
19
+ #include <immintrin.h> // For _xgetbv()
20
+ #endif
21
+
22
+ // For ArmCpuCaps() but unittested on all platforms
23
+ #include <stdio.h> // For fopen()
24
+ #include <string.h>
25
+
26
+ #if defined(__linux__) && (defined(__aarch64__) || defined(__loongarch__))
27
+ #include <sys/auxv.h> // For getauxval()
28
+ #endif
29
+
30
+ #if defined(_WIN32) && defined(__aarch64__)
31
+ #undef WIN32_LEAN_AND_MEAN
32
+ #define WIN32_LEAN_AND_MEAN
33
+ #undef WIN32_EXTRA_LEAN
34
+ #define WIN32_EXTRA_LEAN
35
+ #include <windows.h> // For IsProcessorFeaturePresent()
36
+ #endif
37
+
38
+ #if defined(__APPLE__) && defined(__aarch64__)
39
+ #include <sys/sysctl.h> // For sysctlbyname()
40
+ #endif
41
+
42
+ #ifdef __cplusplus
43
+ namespace libyuv {
44
+ extern "C" {
45
+ #endif
46
+
47
+ // For functions that use the stack and have runtime checks for overflow,
48
+ // use SAFEBUFFERS to avoid additional check.
49
+ #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219) && \
50
+ !defined(__clang__)
51
+ #define SAFEBUFFERS __declspec(safebuffers)
52
+ #else
53
+ #define SAFEBUFFERS
54
+ #endif
55
+
56
+ // cpu_info_ variable for SIMD instruction sets detected.
57
+ LIBYUV_API int cpu_info_ = 0;
58
+
59
+ // Low level cpuid for X86.
60
+ #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
61
+ defined(__x86_64__)) && \
62
+ !defined(__pnacl__) && !defined(__CLR_VER)
63
+ LIBYUV_API
64
+ void CpuId(int info_eax, int info_ecx, int* cpu_info) {
65
+ #if defined(_MSC_VER)
66
+ // Visual C version uses intrinsic or inline x86 assembly.
67
+ #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
68
+ __cpuidex(cpu_info, info_eax, info_ecx);
69
+ #elif defined(_M_IX86)
70
+ __asm {
71
+ mov eax, info_eax
72
+ mov ecx, info_ecx
73
+ mov edi, cpu_info
74
+ cpuid
75
+ mov [edi], eax
76
+ mov [edi + 4], ebx
77
+ mov [edi + 8], ecx
78
+ mov [edi + 12], edx
79
+ }
80
+ #else // Visual C but not x86
81
+ if (info_ecx == 0) {
82
+ __cpuid(cpu_info, info_eax);
83
+ } else {
84
+ cpu_info[3] = cpu_info[2] = cpu_info[1] = cpu_info[0] = 0u;
85
+ }
86
+ #endif
87
+ // GCC version uses inline x86 assembly.
88
+ #else // defined(_MSC_VER)
89
+ int info_ebx, info_edx;
90
+ asm volatile(
91
+ #if defined(__i386__) && defined(__PIC__)
92
+ // Preserve ebx for fpic 32 bit.
93
+ "mov %%ebx, %%edi \n"
94
+ "cpuid \n"
95
+ "xchg %%edi, %%ebx \n"
96
+ : "=D"(info_ebx),
97
+ #else
98
+ "cpuid \n"
99
+ : "=b"(info_ebx),
100
+ #endif // defined( __i386__) && defined(__PIC__)
101
+ "+a"(info_eax), "+c"(info_ecx), "=d"(info_edx));
102
+ cpu_info[0] = info_eax;
103
+ cpu_info[1] = info_ebx;
104
+ cpu_info[2] = info_ecx;
105
+ cpu_info[3] = info_edx;
106
+ #endif // defined(_MSC_VER)
107
+ }
108
+ #else // (defined(_M_IX86) || defined(_M_X64) ...
109
+ LIBYUV_API
110
+ void CpuId(int eax, int ecx, int* cpu_info) {
111
+ (void)eax;
112
+ (void)ecx;
113
+ cpu_info[0] = cpu_info[1] = cpu_info[2] = cpu_info[3] = 0;
114
+ }
115
+ #endif
116
+
117
+ // For VS2010 and earlier emit can be used:
118
+ // _asm _emit 0x0f _asm _emit 0x01 _asm _emit 0xd0 // For VS2010 and earlier.
119
+ // __asm {
120
+ // xor ecx, ecx // xcr 0
121
+ // xgetbv
122
+ // mov xcr0, eax
123
+ // }
124
+ // For VS2013 and earlier 32 bit, the _xgetbv(0) optimizer produces bad code.
125
+ // https://code.google.com/p/libyuv/issues/detail?id=529
126
+ #if defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900)
127
+ #pragma optimize("g", off)
128
+ #endif
129
+ #if (defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || \
130
+ defined(__x86_64__)) && \
131
+ !defined(__pnacl__) && !defined(__CLR_VER) && !defined(__native_client__)
132
+ // X86 CPUs have xgetbv to detect OS saves high parts of ymm registers.
133
+ static int GetXCR0() {
134
+ int xcr0 = 0;
135
+ #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 160040219)
136
+ xcr0 = (int)_xgetbv(0); // VS2010 SP1 required. NOLINT
137
+ #elif defined(__i386__) || defined(__x86_64__)
138
+ asm(".byte 0x0f, 0x01, 0xd0" : "=a"(xcr0) : "c"(0) : "%edx");
139
+ #endif // defined(__i386__) || defined(__x86_64__)
140
+ return xcr0;
141
+ }
142
+ #else
143
+ // xgetbv unavailable to query for OSSave support. Return 0.
144
+ #define GetXCR0() 0
145
+ #endif // defined(_M_IX86) || defined(_M_X64) ..
146
+ // Return optimization to previous setting.
147
+ #if defined(_M_IX86) && defined(_MSC_VER) && (_MSC_VER < 1900)
148
+ #pragma optimize("g", on)
149
+ #endif
150
+
151
+ static int cpuinfo_search(const char* cpuinfo_line,
152
+ const char* needle,
153
+ int needle_len) {
154
+ const char* p = strstr(cpuinfo_line, needle);
155
+ return p && (p[needle_len] == ' ' || p[needle_len] == '\n');
156
+ }
157
+
158
+ // Based on libvpx arm_cpudetect.c
159
+ // For Arm, but public to allow testing on any CPU
160
+ LIBYUV_API SAFEBUFFERS int ArmCpuCaps(const char* cpuinfo_name) {
161
+ char cpuinfo_line[512];
162
+ FILE* f = fopen(cpuinfo_name, "re");
163
+ if (!f) {
164
+ // Assume Neon if /proc/cpuinfo is unavailable.
165
+ // This will occur for Chrome sandbox for Pepper or Render process.
166
+ return kCpuHasNEON;
167
+ }
168
+ memset(cpuinfo_line, 0, sizeof(cpuinfo_line));
169
+ int features = 0;
170
+ while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f)) {
171
+ if (memcmp(cpuinfo_line, "Features", 8) == 0) {
172
+ if (cpuinfo_search(cpuinfo_line, " neon", 5)) {
173
+ features |= kCpuHasNEON;
174
+ }
175
+ }
176
+ }
177
+ fclose(f);
178
+ return features;
179
+ }
180
+
181
+ #ifdef __aarch64__
182
+ #ifdef __linux__
183
+ // Define hwcap values ourselves: building with an old auxv header where these
184
+ // hwcap values are not defined should not prevent features from being enabled.
185
+ #define YUV_AARCH64_HWCAP_ASIMDDP (1UL << 20)
186
+ #define YUV_AARCH64_HWCAP_SVE (1UL << 22)
187
+ #define YUV_AARCH64_HWCAP2_SVE2 (1UL << 1)
188
+ #define YUV_AARCH64_HWCAP2_SVEF32MM (1UL << 10)
189
+ #define YUV_AARCH64_HWCAP2_I8MM (1UL << 13)
190
+ #define YUV_AARCH64_HWCAP2_SME (1UL << 23)
191
+ #define YUV_AARCH64_HWCAP2_SME2 (1UL << 37)
192
+
193
+ // For AArch64, but public to allow testing on any CPU.
194
+ LIBYUV_API SAFEBUFFERS int AArch64CpuCaps(unsigned long hwcap,
195
+ unsigned long hwcap2) {
196
+ // Neon is mandatory on AArch64, so enable regardless of hwcaps.
197
+ int features = kCpuHasNEON;
198
+
199
+ // Don't try to enable later extensions unless earlier extensions are also
200
+ // reported available. Some of these constraints aren't strictly required by
201
+ // the architecture, but are satisfied by all micro-architectures of
202
+ // interest. This also avoids an issue on some emulators where true
203
+ // architectural constraints are not satisfied, e.g. SVE2 may be reported as
204
+ // available while SVE is not.
205
+ if (hwcap & YUV_AARCH64_HWCAP_ASIMDDP) {
206
+ features |= kCpuHasNeonDotProd;
207
+ if (hwcap2 & YUV_AARCH64_HWCAP2_I8MM) {
208
+ features |= kCpuHasNeonI8MM;
209
+ if (hwcap & YUV_AARCH64_HWCAP_SVE) {
210
+ features |= kCpuHasSVE;
211
+ if (hwcap2 & YUV_AARCH64_HWCAP2_SVEF32MM) {
212
+ features |= kCpuHasSVEF32MM;
213
+ }
214
+ if (hwcap2 & YUV_AARCH64_HWCAP2_SVE2) {
215
+ features |= kCpuHasSVE2;
216
+ }
217
+ }
218
+ // SME may be present without SVE
219
+ if (hwcap2 & YUV_AARCH64_HWCAP2_SME) {
220
+ features |= kCpuHasSME;
221
+ if (hwcap2 & YUV_AARCH64_HWCAP2_SME2) {
222
+ features |= kCpuHasSME2;
223
+ }
224
+ }
225
+ }
226
+ }
227
+ return features;
228
+ }
229
+
230
+ #elif defined(_WIN32)
231
+ // For AArch64, but public to allow testing on any CPU.
232
+ LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() {
233
+ // Neon is mandatory on AArch64, so enable unconditionally.
234
+ int features = kCpuHasNEON;
235
+
236
+ // For more information on IsProcessorFeaturePresent(), see:
237
+ // https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent#parameters
238
+ #ifdef PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE
239
+ if (IsProcessorFeaturePresent(PF_ARM_V82_DP_INSTRUCTIONS_AVAILABLE)) {
240
+ features |= kCpuHasNeonDotProd;
241
+ }
242
+ #endif
243
+ // No Neon I8MM or SVE feature detection available here at time of writing.
244
+ return features;
245
+ }
246
+
247
+ #elif defined(__APPLE__)
248
+ static bool have_feature(const char* feature) {
249
+ // For more information on sysctlbyname(), see:
250
+ // https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
251
+ int64_t feature_present = 0;
252
+ size_t size = sizeof(feature_present);
253
+ if (sysctlbyname(feature, &feature_present, &size, NULL, 0) != 0) {
254
+ return false;
255
+ }
256
+ return feature_present;
257
+ }
258
+
259
+ // For AArch64, but public to allow testing on any CPU.
260
+ LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() {
261
+ // Neon is mandatory on AArch64, so enable unconditionally.
262
+ int features = kCpuHasNEON;
263
+
264
+ if (have_feature("hw.optional.arm.FEAT_DotProd")) {
265
+ features |= kCpuHasNeonDotProd;
266
+ if (have_feature("hw.optional.arm.FEAT_I8MM")) {
267
+ features |= kCpuHasNeonI8MM;
268
+ if (have_feature("hw.optional.arm.FEAT_SME")) {
269
+ features |= kCpuHasSME;
270
+ if (have_feature("hw.optional.arm.FEAT_SME2")) {
271
+ features |= kCpuHasSME2;
272
+ }
273
+ }
274
+ }
275
+ }
276
+ // No SVE feature detection available here at time of writing.
277
+ return features;
278
+ }
279
+
280
+ #else // !defined(__linux__) && !defined(_WIN32) && !defined(__APPLE__)
281
+ // For AArch64, but public to allow testing on any CPU.
282
+ LIBYUV_API SAFEBUFFERS int AArch64CpuCaps() {
283
+ // Neon is mandatory on AArch64, so enable unconditionally.
284
+ int features = kCpuHasNEON;
285
+
286
+ // TODO(libyuv:980) support feature detection on other platforms.
287
+
288
+ return features;
289
+ }
290
+ #endif
291
+ #endif // defined(__aarch64__)
292
+
293
+ LIBYUV_API SAFEBUFFERS int RiscvCpuCaps(const char* cpuinfo_name) {
294
+ char cpuinfo_line[512];
295
+ int flag = 0;
296
+ FILE* f = fopen(cpuinfo_name, "re");
297
+ if (!f) {
298
+ #if defined(__riscv_vector)
299
+ // Assume RVV if /proc/cpuinfo is unavailable.
300
+ // This will occur for Chrome sandbox for Pepper or Render process.
301
+ return kCpuHasRVV;
302
+ #else
303
+ return 0;
304
+ #endif
305
+ }
306
+ memset(cpuinfo_line, 0, sizeof(cpuinfo_line));
307
+ while (fgets(cpuinfo_line, sizeof(cpuinfo_line), f)) {
308
+ if (memcmp(cpuinfo_line, "isa", 3) == 0) {
309
+ // ISA string must begin with rv64{i,e,g} for a 64-bit processor.
310
+ char* isa = strstr(cpuinfo_line, "rv64");
311
+ if (isa) {
312
+ size_t isa_len = strlen(isa);
313
+ char* extensions;
314
+ size_t extensions_len = 0;
315
+ size_t std_isa_len;
316
+ // Remove the new-line character at the end of string
317
+ if (isa[isa_len - 1] == '\n') {
318
+ isa[--isa_len] = '\0';
319
+ }
320
+ // 5 ISA characters
321
+ if (isa_len < 5) {
322
+ fclose(f);
323
+ return 0;
324
+ }
325
+ // Skip {i,e,g} canonical checking.
326
+ // Skip rvxxx
327
+ isa += 5;
328
+ // Find the very first occurrence of 's', 'x' or 'z'.
329
+ // To detect multi-letter standard, non-standard, and
330
+ // supervisor-level extensions.
331
+ extensions = strpbrk(isa, "zxs");
332
+ if (extensions) {
333
+ // Multi-letter extensions are seperated by a single underscore
334
+ // as described in RISC-V User-Level ISA V2.2.
335
+ char* ext = strtok(extensions, "_");
336
+ extensions_len = strlen(extensions);
337
+ while (ext) {
338
+ // Search for the ZVFH (Vector FP16) extension.
339
+ if (!strcmp(ext, "zvfh")) {
340
+ flag |= kCpuHasRVVZVFH;
341
+ }
342
+ ext = strtok(NULL, "_");
343
+ }
344
+ }
345
+ std_isa_len = isa_len - extensions_len - 5;
346
+ // Detect the v in the standard single-letter extensions.
347
+ if (memchr(isa, 'v', std_isa_len)) {
348
+ // The RVV implied the F extension.
349
+ flag |= kCpuHasRVV;
350
+ }
351
+ }
352
+ }
353
+ #if defined(__riscv_vector)
354
+ // Assume RVV if /proc/cpuinfo is from x86 host running QEMU.
355
+ else if ((memcmp(cpuinfo_line, "vendor_id\t: GenuineIntel", 24) == 0) ||
356
+ (memcmp(cpuinfo_line, "vendor_id\t: AuthenticAMD", 24) == 0)) {
357
+ fclose(f);
358
+ return kCpuHasRVV;
359
+ }
360
+ #endif
361
+ }
362
+ fclose(f);
363
+ return flag;
364
+ }
365
+
366
+ #if defined(__loongarch__) && defined(__linux__)
367
+ // Define hwcap values ourselves: building with an old auxv header where these
368
+ // hwcap values are not defined should not prevent features from being enabled.
369
+ #define YUV_LOONGARCH_HWCAP_LSX (1 << 4)
370
+ #define YUV_LOONGARCH_HWCAP_LASX (1 << 5)
371
+
372
+ LIBYUV_API SAFEBUFFERS int LoongArchCpuCaps(void) {
373
+ int flag = 0;
374
+ unsigned long hwcap = getauxval(AT_HWCAP);
375
+
376
+ if (hwcap & YUV_LOONGARCH_HWCAP_LSX)
377
+ flag |= kCpuHasLSX;
378
+
379
+ if (hwcap & YUV_LOONGARCH_HWCAP_LASX)
380
+ flag |= kCpuHasLASX;
381
+ return flag;
382
+ }
383
+ #endif
384
+
385
+ static SAFEBUFFERS int GetCpuFlags(void) {
386
+ int cpu_info = 0;
387
+ #if !defined(__pnacl__) && !defined(__CLR_VER) && \
388
+ (defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || \
389
+ defined(_M_IX86))
390
+ int cpu_info0[4] = {0, 0, 0, 0};
391
+ int cpu_info1[4] = {0, 0, 0, 0};
392
+ int cpu_info7[4] = {0, 0, 0, 0};
393
+ int cpu_einfo7[4] = {0, 0, 0, 0};
394
+ int cpu_info24[4] = {0, 0, 0, 0};
395
+ int cpu_amdinfo21[4] = {0, 0, 0, 0};
396
+ CpuId(0, 0, cpu_info0);
397
+ CpuId(1, 0, cpu_info1);
398
+ if (cpu_info0[0] >= 7) {
399
+ CpuId(7, 0, cpu_info7);
400
+ CpuId(7, 1, cpu_einfo7);
401
+ CpuId(0x80000021, 0, cpu_amdinfo21);
402
+ }
403
+ if (cpu_info0[0] >= 0x24) {
404
+ CpuId(0x24, 0, cpu_info24);
405
+ }
406
+ cpu_info = kCpuHasX86 | ((cpu_info1[3] & 0x04000000) ? kCpuHasSSE2 : 0) |
407
+ ((cpu_info1[2] & 0x00000200) ? kCpuHasSSSE3 : 0) |
408
+ ((cpu_info1[2] & 0x00080000) ? kCpuHasSSE41 : 0) |
409
+ ((cpu_info1[2] & 0x00100000) ? kCpuHasSSE42 : 0) |
410
+ ((cpu_info7[1] & 0x00000200) ? kCpuHasERMS : 0) |
411
+ ((cpu_info7[3] & 0x00000010) ? kCpuHasFSMR : 0);
412
+
413
+ // AVX requires OS saves YMM registers.
414
+ if (((cpu_info1[2] & 0x1c000000) == 0x1c000000) && // AVX and OSXSave
415
+ ((GetXCR0() & 6) == 6)) { // Test OS saves YMM registers
416
+ cpu_info |= kCpuHasAVX | ((cpu_info7[1] & 0x00000020) ? kCpuHasAVX2 : 0) |
417
+ ((cpu_info1[2] & 0x00001000) ? kCpuHasFMA3 : 0) |
418
+ ((cpu_info1[2] & 0x20000000) ? kCpuHasF16C : 0) |
419
+ ((cpu_einfo7[0] & 0x00000010) ? kCpuHasAVXVNNI : 0) |
420
+ ((cpu_einfo7[3] & 0x00000010) ? kCpuHasAVXVNNIINT8 : 0);
421
+
422
+ cpu_info |= ((cpu_amdinfo21[0] & 0x00008000) ? kCpuHasERMS : 0);
423
+
424
+ // Detect AVX512bw
425
+ if ((GetXCR0() & 0xe0) == 0xe0) {
426
+ cpu_info |= ((cpu_info7[1] & 0x40000000) ? kCpuHasAVX512BW : 0) |
427
+ ((cpu_info7[1] & 0x80000000) ? kCpuHasAVX512VL : 0) |
428
+ ((cpu_info7[2] & 0x00000002) ? kCpuHasAVX512VBMI : 0) |
429
+ ((cpu_info7[2] & 0x00000040) ? kCpuHasAVX512VBMI2 : 0) |
430
+ ((cpu_info7[2] & 0x00000800) ? kCpuHasAVX512VNNI : 0) |
431
+ ((cpu_info7[2] & 0x00001000) ? kCpuHasAVX512VBITALG : 0) |
432
+ ((cpu_einfo7[3] & 0x00080000) ? kCpuHasAVX10 : 0) |
433
+ ((cpu_info7[3] & 0x02000000) ? kCpuHasAMXINT8 : 0);
434
+ if (cpu_info0[0] >= 0x24 && (cpu_einfo7[3] & 0x00080000)) {
435
+ cpu_info |= ((cpu_info24[1] & 0xFF) >= 2) ? kCpuHasAVX10_2 : 0;
436
+ }
437
+ }
438
+ }
439
+ #endif
440
+ #if defined(__loongarch__) && defined(__linux__)
441
+ cpu_info = LoongArchCpuCaps();
442
+ cpu_info |= kCpuHasLOONGARCH;
443
+ #endif
444
+ #if defined(__aarch64__)
445
+ #if defined(__linux__)
446
+ // getauxval is supported since Android SDK version 18, minimum at time of
447
+ // writing is 21, so should be safe to always use this. If getauxval is
448
+ // somehow disabled then getauxval returns 0, which will leave Neon enabled
449
+ // since Neon is mandatory on AArch64.
450
+ unsigned long hwcap = getauxval(AT_HWCAP);
451
+ unsigned long hwcap2 = getauxval(AT_HWCAP2);
452
+ cpu_info = AArch64CpuCaps(hwcap, hwcap2);
453
+ #else
454
+ cpu_info = AArch64CpuCaps();
455
+ #endif
456
+ cpu_info |= kCpuHasARM;
457
+ #endif // __aarch64__
458
+ #if defined(__arm__)
459
+ // gcc -mfpu=neon defines __ARM_NEON__
460
+ // __ARM_NEON__ generates code that requires Neon. NaCL also requires Neon.
461
+ // For Linux, /proc/cpuinfo can be tested but without that assume Neon.
462
+ // Linux arm parse text file for neon detect.
463
+ #if defined(__linux__)
464
+ cpu_info = ArmCpuCaps("/proc/cpuinfo");
465
+ #elif defined(__ARM_NEON__)
466
+ cpu_info = kCpuHasNEON;
467
+ #else
468
+ cpu_info = 0;
469
+ #endif
470
+ cpu_info |= kCpuHasARM;
471
+ #endif // __arm__
472
+ #if defined(__riscv) && defined(__linux__)
473
+ cpu_info = RiscvCpuCaps("/proc/cpuinfo");
474
+ cpu_info |= kCpuHasRISCV;
475
+ #endif // __riscv
476
+ cpu_info |= kCpuInitialized;
477
+ return cpu_info;
478
+ }
479
+
480
+ // Note that use of this function is not thread safe.
481
+ LIBYUV_API
482
+ int MaskCpuFlags(int enable_flags) {
483
+ int cpu_info = GetCpuFlags() & enable_flags;
484
+ SetCpuFlags(cpu_info);
485
+ return cpu_info;
486
+ }
487
+
488
+ LIBYUV_API
489
+ int InitCpuFlags(void) {
490
+ return MaskCpuFlags(-1);
491
+ }
492
+
493
+ #ifdef __cplusplus
494
+ } // extern "C"
495
+ } // namespace libyuv
496
+ #endif