react-native-vision-camera-spoof-detector 1.1.22 → 1.1.24

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 (201) hide show
  1. package/android/CMakeLists.txt +12 -0
  2. package/android/build.gradle +10 -9
  3. package/android/src/main/cpp/cpp-adapter.cpp +6 -3
  4. package/android/src/main/java/com/faceantispoof/FaceAntiSpoofingAdvanced.kt +83 -0
  5. package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt +26 -11
  6. package/package.json +1 -1
  7. package/android/src/main/cpp/CMakeLists.txt +0 -33
  8. package/android/src/main/cpp/FaceAntiSpoofJSI.cpp +0 -142
  9. package/android/src/main/cpp/FastYuvJni.cpp +0 -111
  10. package/android/src/main/cpp/fast_yuv.cpp +0 -342
  11. package/android/src/main/cpp/fast_yuv.h +0 -23
  12. package/android/src/main/cpp/libyuv/.clang-format +0 -6
  13. package/android/src/main/cpp/libyuv/.gn +0 -40
  14. package/android/src/main/cpp/libyuv/.vpython3 +0 -410
  15. package/android/src/main/cpp/libyuv/AUTHORS +0 -7
  16. package/android/src/main/cpp/libyuv/Android.bp +0 -202
  17. package/android/src/main/cpp/libyuv/Android.mk +0 -106
  18. package/android/src/main/cpp/libyuv/BUILD.gn +0 -490
  19. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +0 -70
  20. package/android/src/main/cpp/libyuv/CMakeLists.txt +0 -259
  21. package/android/src/main/cpp/libyuv/DEPS +0 -935
  22. package/android/src/main/cpp/libyuv/DIR_METADATA +0 -3
  23. package/android/src/main/cpp/libyuv/LICENSE +0 -29
  24. package/android/src/main/cpp/libyuv/OWNERS +0 -11
  25. package/android/src/main/cpp/libyuv/PATENTS +0 -24
  26. package/android/src/main/cpp/libyuv/PRESUBMIT.py +0 -65
  27. package/android/src/main/cpp/libyuv/README.chromium +0 -11
  28. package/android/src/main/cpp/libyuv/README.md +0 -19
  29. package/android/src/main/cpp/libyuv/build_overrides/build.gni +0 -60
  30. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +0 -19
  31. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +0 -17
  32. package/android/src/main/cpp/libyuv/codereview.settings +0 -5
  33. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +0 -409
  34. package/android/src/main/cpp/libyuv/docs/environment_variables.md +0 -64
  35. package/android/src/main/cpp/libyuv/docs/feature_detection.md +0 -108
  36. package/android/src/main/cpp/libyuv/docs/filtering.md +0 -196
  37. package/android/src/main/cpp/libyuv/docs/formats.md +0 -208
  38. package/android/src/main/cpp/libyuv/docs/getting_started.md +0 -296
  39. package/android/src/main/cpp/libyuv/docs/rotation.md +0 -107
  40. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +0 -29
  41. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +0 -68
  42. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +0 -111
  43. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +0 -112
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +0 -1117
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +0 -2335
  46. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +0 -203
  47. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +0 -394
  48. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +0 -147
  49. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +0 -99
  50. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +0 -1949
  51. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +0 -195
  52. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +0 -1131
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +0 -296
  54. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +0 -37
  55. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +0 -265
  56. package/android/src/main/cpp/libyuv/include/libyuv/row.h +0 -6738
  57. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +0 -2154
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +0 -336
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +0 -76
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +0 -42
  61. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +0 -1726
  62. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +0 -51
  63. package/android/src/main/cpp/libyuv/include/libyuv/version.h +0 -16
  64. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +0 -222
  65. package/android/src/main/cpp/libyuv/include/libyuv.h +0 -33
  66. package/android/src/main/cpp/libyuv/infra/config/OWNERS +0 -3
  67. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +0 -17
  68. package/android/src/main/cpp/libyuv/infra/config/README.md +0 -2
  69. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +0 -6
  70. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +0 -144
  71. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +0 -1185
  72. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +0 -9
  73. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +0 -246
  74. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +0 -385
  75. package/android/src/main/cpp/libyuv/infra/config/main.star +0 -402
  76. package/android/src/main/cpp/libyuv/infra/config/project.cfg +0 -16
  77. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +0 -111
  78. package/android/src/main/cpp/libyuv/libyuv.gni +0 -34
  79. package/android/src/main/cpp/libyuv/libyuv.gyp +0 -149
  80. package/android/src/main/cpp/libyuv/libyuv.gypi +0 -87
  81. package/android/src/main/cpp/libyuv/linux.mk +0 -96
  82. package/android/src/main/cpp/libyuv/public.mk +0 -13
  83. package/android/src/main/cpp/libyuv/pylintrc +0 -49
  84. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +0 -74
  85. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +0 -56
  86. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +0 -15
  87. package/android/src/main/cpp/libyuv/source/compare.cc +0 -435
  88. package/android/src/main/cpp/libyuv/source/compare_common.cc +0 -74
  89. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +0 -362
  90. package/android/src/main/cpp/libyuv/source/compare_neon.cc +0 -96
  91. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +0 -223
  92. package/android/src/main/cpp/libyuv/source/compare_win.cc +0 -241
  93. package/android/src/main/cpp/libyuv/source/convert.cc +0 -4746
  94. package/android/src/main/cpp/libyuv/source/convert_argb.cc +0 -9179
  95. package/android/src/main/cpp/libyuv/source/convert_from.cc +0 -866
  96. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +0 -3671
  97. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +0 -602
  98. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +0 -391
  99. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +0 -288
  100. package/android/src/main/cpp/libyuv/source/cpu_id.cc +0 -496
  101. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +0 -580
  102. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +0 -71
  103. package/android/src/main/cpp/libyuv/source/planar_functions.cc +0 -5663
  104. package/android/src/main/cpp/libyuv/source/rotate.cc +0 -1241
  105. package/android/src/main/cpp/libyuv/source/rotate_any.cc +0 -76
  106. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +0 -259
  107. package/android/src/main/cpp/libyuv/source/rotate_common.cc +0 -208
  108. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +0 -505
  109. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +0 -233
  110. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +0 -219
  111. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +0 -273
  112. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +0 -174
  113. package/android/src/main/cpp/libyuv/source/rotate_win.cc +0 -253
  114. package/android/src/main/cpp/libyuv/source/row_any.cc +0 -2519
  115. package/android/src/main/cpp/libyuv/source/row_common.cc +0 -4461
  116. package/android/src/main/cpp/libyuv/source/row_gcc.cc +0 -9570
  117. package/android/src/main/cpp/libyuv/source/row_lasx.cc +0 -2343
  118. package/android/src/main/cpp/libyuv/source/row_lsx.cc +0 -3030
  119. package/android/src/main/cpp/libyuv/source/row_neon.cc +0 -4026
  120. package/android/src/main/cpp/libyuv/source/row_neon64.cc +0 -5617
  121. package/android/src/main/cpp/libyuv/source/row_rvv.cc +0 -2599
  122. package/android/src/main/cpp/libyuv/source/row_sme.cc +0 -1183
  123. package/android/src/main/cpp/libyuv/source/row_sve.cc +0 -1088
  124. package/android/src/main/cpp/libyuv/source/row_win.cc +0 -6453
  125. package/android/src/main/cpp/libyuv/source/scale.cc +0 -2710
  126. package/android/src/main/cpp/libyuv/source/scale_any.cc +0 -991
  127. package/android/src/main/cpp/libyuv/source/scale_argb.cc +0 -1158
  128. package/android/src/main/cpp/libyuv/source/scale_common.cc +0 -1977
  129. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +0 -2947
  130. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +0 -739
  131. package/android/src/main/cpp/libyuv/source/scale_neon.cc +0 -1449
  132. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +0 -1552
  133. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +0 -82
  134. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +0 -1971
  135. package/android/src/main/cpp/libyuv/source/scale_sme.cc +0 -555
  136. package/android/src/main/cpp/libyuv/source/scale_uv.cc +0 -1159
  137. package/android/src/main/cpp/libyuv/source/scale_win.cc +0 -1392
  138. package/android/src/main/cpp/libyuv/source/test.sh +0 -35
  139. package/android/src/main/cpp/libyuv/source/video_common.cc +0 -62
  140. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +0 -4
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +0 -931
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +0 -164
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +0 -21
  144. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +0 -13
  145. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +0 -13
  146. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +0 -38
  147. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +0 -3
  148. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +0 -9
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +0 -3
  150. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +0 -15
  151. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +0 -25
  152. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +0 -43
  153. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +0 -848
  154. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +0 -739
  155. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +0 -2867
  156. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +0 -2133
  157. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +0 -427
  158. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +0 -63
  159. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +0 -160
  160. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +0 -4731
  161. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +0 -334
  162. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +0 -962
  163. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +0 -590
  164. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +0 -465
  165. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +0 -280
  166. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +0 -1135
  167. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +0 -249
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +0 -12
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +0 -7
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +0 -5
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +0 -10
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +0 -7
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +0 -4
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +0 -4
  175. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +0 -4
  176. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +0 -23
  177. package/android/src/main/cpp/libyuv/unit_test/testdata/test0.jpg +0 -0
  178. package/android/src/main/cpp/libyuv/unit_test/testdata/test1.jpg +0 -0
  179. package/android/src/main/cpp/libyuv/unit_test/testdata/test2.jpg +0 -0
  180. package/android/src/main/cpp/libyuv/unit_test/testdata/test3.jpg +0 -0
  181. package/android/src/main/cpp/libyuv/unit_test/testdata/test4.jpg +0 -0
  182. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +0 -581
  183. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +0 -232
  184. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +0 -112
  185. package/android/src/main/cpp/libyuv/util/Makefile +0 -9
  186. package/android/src/main/cpp/libyuv/util/color.cc +0 -120
  187. package/android/src/main/cpp/libyuv/util/compare.cc +0 -67
  188. package/android/src/main/cpp/libyuv/util/cpuid.c +0 -211
  189. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +0 -28
  190. package/android/src/main/cpp/libyuv/util/psnr.cc +0 -291
  191. package/android/src/main/cpp/libyuv/util/psnr.h +0 -47
  192. package/android/src/main/cpp/libyuv/util/psnr_main.cc +0 -620
  193. package/android/src/main/cpp/libyuv/util/ssim.cc +0 -364
  194. package/android/src/main/cpp/libyuv/util/ssim.h +0 -38
  195. package/android/src/main/cpp/libyuv/util/yuvconstants.c +0 -114
  196. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +0 -367
  197. package/android/src/main/cpp/libyuv/winarm.mk +0 -47
  198. package/android/src/main/java/com/faceantispoof/ByteBufferPool.kt +0 -68
  199. package/android/src/main/java/com/faceantispoof/FastYuv.kt +0 -51
  200. package/android/src/main/java/com/faceantispoof/YuvToFloatArrayConverter.kt +0 -584
  201. package/android/src/main/java/com/faceantispoof/YuvToRgbConverter.kt +0 -73
@@ -1,496 +0,0 @@
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