cpu.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "cpu.h"
  19. #include "config.h"
  20. static int flags, checked;
  21. void av_force_cpu_flags(int arg){
  22. flags = arg;
  23. checked = 1;
  24. }
  25. int av_get_cpu_flags(void)
  26. {
  27. if (checked)
  28. return flags;
  29. if (ARCH_ARM) flags = ff_get_cpu_flags_arm();
  30. if (ARCH_PPC) flags = ff_get_cpu_flags_ppc();
  31. if (ARCH_X86) flags = ff_get_cpu_flags_x86();
  32. checked = 1;
  33. return flags;
  34. }
  35. #ifdef TEST
  36. #undef printf
  37. #include <stdio.h>
  38. static const struct {
  39. int flag;
  40. const char *name;
  41. } cpu_flag_tab[] = {
  42. #if ARCH_ARM
  43. { AV_CPU_FLAG_IWMMXT, "iwmmxt" },
  44. #elif ARCH_PPC
  45. { AV_CPU_FLAG_ALTIVEC, "altivec" },
  46. #elif ARCH_X86
  47. { AV_CPU_FLAG_MMX, "mmx" },
  48. { AV_CPU_FLAG_MMX2, "mmx2" },
  49. { AV_CPU_FLAG_SSE, "sse" },
  50. { AV_CPU_FLAG_SSE2, "sse2" },
  51. { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" },
  52. { AV_CPU_FLAG_SSE3, "sse3" },
  53. { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" },
  54. { AV_CPU_FLAG_SSSE3, "ssse3" },
  55. { AV_CPU_FLAG_ATOM, "atom" },
  56. { AV_CPU_FLAG_SSE4, "sse4.1" },
  57. { AV_CPU_FLAG_SSE42, "sse4.2" },
  58. { AV_CPU_FLAG_AVX, "avx" },
  59. { AV_CPU_FLAG_XOP, "xop" },
  60. { AV_CPU_FLAG_FMA4, "fma4" },
  61. { AV_CPU_FLAG_3DNOW, "3dnow" },
  62. { AV_CPU_FLAG_3DNOWEXT, "3dnowext" },
  63. #endif
  64. { 0 }
  65. };
  66. int main(void)
  67. {
  68. int cpu_flags = av_get_cpu_flags();
  69. int i;
  70. printf("cpu_flags = 0x%08X\n", cpu_flags);
  71. printf("cpu_flags =");
  72. for (i = 0; cpu_flag_tab[i].flag; i++)
  73. if (cpu_flags & cpu_flag_tab[i].flag)
  74. printf(" %s", cpu_flag_tab[i].name);
  75. printf("\n");
  76. return 0;
  77. }
  78. #endif