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.

96 lines
2.5KB

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