You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
4.4KB

  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include <stdio.h>
  19. #include "config.h"
  20. #include "libavutil/cpu.h"
  21. #include "libavutil/avstring.h"
  22. #if HAVE_UNISTD_H
  23. #include <unistd.h>
  24. #endif
  25. #if !HAVE_GETOPT
  26. #include "compat/getopt.c"
  27. #endif
  28. static const struct {
  29. int flag;
  30. const char *name;
  31. } cpu_flag_tab[] = {
  32. #if ARCH_AARCH64
  33. { AV_CPU_FLAG_ARMV8, "armv8" },
  34. { AV_CPU_FLAG_NEON, "neon" },
  35. { AV_CPU_FLAG_VFP, "vfp" },
  36. #elif ARCH_ARM
  37. { AV_CPU_FLAG_ARMV5TE, "armv5te" },
  38. { AV_CPU_FLAG_ARMV6, "armv6" },
  39. { AV_CPU_FLAG_ARMV6T2, "armv6t2" },
  40. { AV_CPU_FLAG_VFP, "vfp" },
  41. { AV_CPU_FLAG_VFP_VM, "vfp_vm" },
  42. { AV_CPU_FLAG_VFPV3, "vfpv3" },
  43. { AV_CPU_FLAG_NEON, "neon" },
  44. { AV_CPU_FLAG_SETEND, "setend" },
  45. #elif ARCH_PPC
  46. { AV_CPU_FLAG_ALTIVEC, "altivec" },
  47. #elif ARCH_MIPS
  48. { AV_CPU_FLAG_MMI, "mmi" },
  49. { AV_CPU_FLAG_MSA, "msa" },
  50. #elif ARCH_X86
  51. { AV_CPU_FLAG_MMX, "mmx" },
  52. { AV_CPU_FLAG_MMXEXT, "mmxext" },
  53. { AV_CPU_FLAG_SSE, "sse" },
  54. { AV_CPU_FLAG_SSE2, "sse2" },
  55. { AV_CPU_FLAG_SSE2SLOW, "sse2slow" },
  56. { AV_CPU_FLAG_SSE3, "sse3" },
  57. { AV_CPU_FLAG_SSE3SLOW, "sse3slow" },
  58. { AV_CPU_FLAG_SSSE3, "ssse3" },
  59. { AV_CPU_FLAG_ATOM, "atom" },
  60. { AV_CPU_FLAG_SSE4, "sse4.1" },
  61. { AV_CPU_FLAG_SSE42, "sse4.2" },
  62. { AV_CPU_FLAG_AVX, "avx" },
  63. { AV_CPU_FLAG_AVXSLOW, "avxslow" },
  64. { AV_CPU_FLAG_XOP, "xop" },
  65. { AV_CPU_FLAG_FMA3, "fma3" },
  66. { AV_CPU_FLAG_FMA4, "fma4" },
  67. { AV_CPU_FLAG_3DNOW, "3dnow" },
  68. { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
  69. { AV_CPU_FLAG_CMOV, "cmov" },
  70. { AV_CPU_FLAG_AVX2, "avx2" },
  71. { AV_CPU_FLAG_BMI1, "bmi1" },
  72. { AV_CPU_FLAG_BMI2, "bmi2" },
  73. { AV_CPU_FLAG_AESNI, "aesni" },
  74. { AV_CPU_FLAG_AVX512, "avx512" },
  75. #endif
  76. { 0 }
  77. };
  78. static void print_cpu_flags(int cpu_flags, const char *type)
  79. {
  80. int i;
  81. printf("cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
  82. printf("cpu_flags_str(%s) =", type);
  83. for (i = 0; cpu_flag_tab[i].flag; i++)
  84. if (cpu_flags & cpu_flag_tab[i].flag)
  85. printf(" %s", cpu_flag_tab[i].name);
  86. printf("\n");
  87. }
  88. int main(int argc, char **argv)
  89. {
  90. int cpu_flags_raw = av_get_cpu_flags();
  91. int cpu_flags_eff;
  92. int cpu_count = av_cpu_count();
  93. char threads[5] = "auto";
  94. int i;
  95. for(i = 0; cpu_flag_tab[i].flag; i++) {
  96. unsigned tmp = 0;
  97. if (av_parse_cpu_caps(&tmp, cpu_flag_tab[i].name) < 0) {
  98. fprintf(stderr, "Table missing %s\n", cpu_flag_tab[i].name);
  99. return 4;
  100. }
  101. }
  102. if (cpu_flags_raw < 0)
  103. return 1;
  104. for (;;) {
  105. int c = getopt(argc, argv, "c:t:");
  106. if (c == -1)
  107. break;
  108. switch (c) {
  109. case 'c':
  110. {
  111. unsigned flags = av_get_cpu_flags();
  112. if (av_parse_cpu_caps(&flags, optarg) < 0)
  113. return 2;
  114. av_force_cpu_flags(flags);
  115. break;
  116. }
  117. case 't':
  118. {
  119. int len = av_strlcpy(threads, optarg, sizeof(threads));
  120. if (len >= sizeof(threads)) {
  121. fprintf(stderr, "Invalid thread count '%s'\n", optarg);
  122. return 2;
  123. }
  124. }
  125. }
  126. }
  127. cpu_flags_eff = av_get_cpu_flags();
  128. if (cpu_flags_eff < 0)
  129. return 3;
  130. print_cpu_flags(cpu_flags_raw, "raw");
  131. print_cpu_flags(cpu_flags_eff, "effective");
  132. printf("threads = %s (cpu_count = %d)\n", threads, cpu_count);
  133. return 0;
  134. }