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.

131 lines
3.7KB

  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. #ifdef __APPLE__
  19. #include <sys/sysctl.h>
  20. #elif defined(__linux__)
  21. #include <asm/cputable.h>
  22. #include <linux/auxvec.h>
  23. #include <fcntl.h>
  24. #include <unistd.h>
  25. #elif defined(__OpenBSD__)
  26. #include <sys/param.h>
  27. #include <sys/sysctl.h>
  28. #include <machine/cpu.h>
  29. #elif defined(__AMIGAOS4__)
  30. #include <exec/exec.h>
  31. #include <interfaces/exec.h>
  32. #include <proto/exec.h>
  33. #endif /* __APPLE__ */
  34. #include "libavutil/cpu.h"
  35. #include "libavutil/cpu_internal.h"
  36. #include "config.h"
  37. /**
  38. * This function MAY rely on signal() or fork() in order to make sure AltiVec
  39. * is present.
  40. */
  41. int ff_get_cpu_flags_ppc(void)
  42. {
  43. #if HAVE_ALTIVEC
  44. #ifdef __AMIGAOS4__
  45. ULONG result = 0;
  46. extern struct ExecIFace *IExec;
  47. IExec->GetCPUInfoTags(GCIT_VectorUnit, &result, TAG_DONE);
  48. if (result == VECTORTYPE_ALTIVEC)
  49. return AV_CPU_FLAG_ALTIVEC;
  50. return 0;
  51. #elif defined(__APPLE__) || defined(__OpenBSD__)
  52. #ifdef __OpenBSD__
  53. int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};
  54. #else
  55. int sels[2] = {CTL_HW, HW_VECTORUNIT};
  56. #endif
  57. int has_vu = 0;
  58. size_t len = sizeof(has_vu);
  59. int err;
  60. err = sysctl(sels, 2, &has_vu, &len, NULL, 0);
  61. if (err == 0)
  62. return has_vu ? AV_CPU_FLAG_ALTIVEC : 0;
  63. return 0;
  64. #elif defined(__linux__)
  65. // The linux kernel could have the altivec support disabled
  66. // even if the cpu has it.
  67. int i, ret = 0;
  68. int fd = open("/proc/self/auxv", O_RDONLY);
  69. unsigned long buf[64] = { 0 };
  70. ssize_t count;
  71. if (fd < 0)
  72. return 0;
  73. while ((count = read(fd, buf, sizeof(buf))) > 0) {
  74. for (i = 0; i < count / sizeof(*buf); i += 2) {
  75. if (buf[i] == AT_NULL)
  76. goto out;
  77. if (buf[i] == AT_HWCAP) {
  78. if (buf[i + 1] & PPC_FEATURE_HAS_ALTIVEC)
  79. ret = AV_CPU_FLAG_ALTIVEC;
  80. goto out;
  81. }
  82. }
  83. }
  84. out:
  85. close(fd);
  86. return ret;
  87. #elif CONFIG_RUNTIME_CPUDETECT
  88. #define PVR_G4_7400 0x000C
  89. #define PVR_G5_970 0x0039
  90. #define PVR_G5_970FX 0x003C
  91. #define PVR_G5_970MP 0x0044
  92. #define PVR_G5_970GX 0x0045
  93. #define PVR_POWER6 0x003E
  94. #define PVR_POWER7 0x003F
  95. #define PVR_POWER8 0x004B
  96. #define PVR_CELL_PPU 0x0070
  97. int proc_ver;
  98. // Support of mfspr PVR emulation added in Linux 2.6.17.
  99. __asm__ volatile("mfspr %0, 287" : "=r" (proc_ver));
  100. proc_ver >>= 16;
  101. if (proc_ver & 0x8000 ||
  102. proc_ver == PVR_G4_7400 ||
  103. proc_ver == PVR_G5_970 ||
  104. proc_ver == PVR_G5_970FX ||
  105. proc_ver == PVR_G5_970MP ||
  106. proc_ver == PVR_G5_970GX ||
  107. proc_ver == PVR_POWER6 ||
  108. proc_ver == PVR_POWER7 ||
  109. proc_ver == PVR_POWER8 ||
  110. proc_ver == PVR_CELL_PPU)
  111. return AV_CPU_FLAG_ALTIVEC;
  112. return 0;
  113. #else
  114. // Since we were compiled for AltiVec, just assume we have it
  115. // until someone comes up with a proper way (not involving signal hacks).
  116. return AV_CPU_FLAG_ALTIVEC;
  117. #endif /* __AMIGAOS4__ */
  118. #endif /* HAVE_ALTIVEC */
  119. return 0;
  120. }