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.

137 lines
4.0KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "config.h"
  19. #if HAVE_UNISTD_H
  20. #include <unistd.h>
  21. #elif !HAVE_GETOPT
  22. #include "compat/getopt.c"
  23. #endif
  24. #include <stdint.h>
  25. #include <stdio.h>
  26. #include "libavutil/avstring.h"
  27. #include "libavutil/common.h"
  28. #include "libavutil/cpu.h"
  29. static const struct {
  30. int flag;
  31. const char *name;
  32. } cpu_flag_tab[] = {
  33. #if ARCH_AARCH64
  34. { AV_CPU_FLAG_ARMV8, "armv8" },
  35. { AV_CPU_FLAG_NEON, "neon" },
  36. { AV_CPU_FLAG_VFP, "vfp" },
  37. #elif ARCH_ARM
  38. { AV_CPU_FLAG_ARMV5TE, "armv5te" },
  39. { AV_CPU_FLAG_ARMV6, "armv6" },
  40. { AV_CPU_FLAG_ARMV6T2, "armv6t2" },
  41. { AV_CPU_FLAG_VFP, "vfp" },
  42. { AV_CPU_FLAG_VFP_VM, "vfp_vm" },
  43. { AV_CPU_FLAG_VFPV3, "vfpv3" },
  44. { AV_CPU_FLAG_NEON, "neon" },
  45. #elif ARCH_PPC
  46. { AV_CPU_FLAG_ALTIVEC, "altivec" },
  47. #elif ARCH_X86
  48. { AV_CPU_FLAG_MMX, "mmx" },
  49. { AV_CPU_FLAG_MMXEXT, "mmxext" },
  50. { AV_CPU_FLAG_SSE, "sse" },
  51. { AV_CPU_FLAG_SSE2, "sse2" },
  52. { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
  53. { AV_CPU_FLAG_SSE3, "sse3" },
  54. { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
  55. { AV_CPU_FLAG_SSSE3, "ssse3" },
  56. { AV_CPU_FLAG_ATOM, "atom" },
  57. { AV_CPU_FLAG_SSE4, "sse4.1" },
  58. { AV_CPU_FLAG_SSE42, "sse4.2" },
  59. { AV_CPU_FLAG_AVX, "avx" },
  60. { AV_CPU_FLAG_AVXSLOW, "avxslow" },
  61. { AV_CPU_FLAG_XOP, "xop" },
  62. { AV_CPU_FLAG_FMA3, "fma3" },
  63. { AV_CPU_FLAG_FMA4, "fma4" },
  64. { AV_CPU_FLAG_3DNOW, "3dnow" },
  65. { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
  66. { AV_CPU_FLAG_CMOV, "cmov" },
  67. { AV_CPU_FLAG_AVX2, "avx2" },
  68. { AV_CPU_FLAG_BMI1, "bmi1" },
  69. { AV_CPU_FLAG_BMI2, "bmi2" },
  70. #endif
  71. { 0 }
  72. };
  73. static void print_cpu_flags(int cpu_flags, const char *type)
  74. {
  75. int i;
  76. fprintf(stderr, "cpu_flags(%s) = 0x%08X\n", type, cpu_flags);
  77. fprintf(stderr, "cpu_flags_str(%s) =", type);
  78. for (i = 0; cpu_flag_tab[i].flag; i++)
  79. if (cpu_flags & cpu_flag_tab[i].flag)
  80. fprintf(stderr, " %s", cpu_flag_tab[i].name);
  81. fprintf(stderr, "\n");
  82. }
  83. int main(int argc, char **argv)
  84. {
  85. int cpu_flags_raw = av_get_cpu_flags();
  86. int cpu_flags_eff;
  87. int cpu_count = av_cpu_count();
  88. char threads[5] = "auto";
  89. if (cpu_flags_raw < 0)
  90. return 1;
  91. for (;;) {
  92. int c = getopt(argc, argv, "c:t:");
  93. if (c == -1)
  94. break;
  95. switch (c) {
  96. case 'c':
  97. {
  98. int cpuflags = av_parse_cpu_flags(optarg);
  99. if (cpuflags < 0)
  100. return 2;
  101. av_set_cpu_flags_mask(cpuflags);
  102. break;
  103. }
  104. case 't':
  105. {
  106. int len = av_strlcpy(threads, optarg, sizeof(threads));
  107. if (len >= sizeof(threads)) {
  108. fprintf(stderr, "Invalid thread count '%s'\n", optarg);
  109. return 2;
  110. }
  111. }
  112. }
  113. }
  114. cpu_flags_eff = av_get_cpu_flags();
  115. if (cpu_flags_eff < 0)
  116. return 3;
  117. print_cpu_flags(cpu_flags_raw, "raw");
  118. print_cpu_flags(cpu_flags_eff, "effective");
  119. fprintf(stderr, "threads = %s (cpu_count = %d)\n", threads, cpu_count);
  120. return 0;
  121. }