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.

145 lines
4.1KB

  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. #ifdef PPC_FEATURE_HAS_VSX
  81. if (buf[i + 1] & PPC_FEATURE_HAS_VSX)
  82. ret |= AV_CPU_FLAG_VSX;
  83. #endif
  84. #ifdef PPC_FEATURE_ARCH_2_07
  85. if (buf[i + 1] & PPC_FEATURE_HAS_POWER8)
  86. ret |= AV_CPU_FLAG_POWER8;
  87. #endif
  88. goto out;
  89. }
  90. }
  91. }
  92. out:
  93. close(fd);
  94. return ret;
  95. #elif CONFIG_RUNTIME_CPUDETECT
  96. #define PVR_G4_7400 0x000C
  97. #define PVR_G5_970 0x0039
  98. #define PVR_G5_970FX 0x003C
  99. #define PVR_G5_970MP 0x0044
  100. #define PVR_G5_970GX 0x0045
  101. #define PVR_POWER6 0x003E
  102. #define PVR_POWER7 0x003F
  103. #define PVR_POWER8 0x004B
  104. #define PVR_CELL_PPU 0x0070
  105. int ret = 0;
  106. int proc_ver;
  107. // Support of mfspr PVR emulation added in Linux 2.6.17.
  108. __asm__ volatile("mfspr %0, 287" : "=r" (proc_ver));
  109. proc_ver >>= 16;
  110. if (proc_ver & 0x8000 ||
  111. proc_ver == PVR_G4_7400 ||
  112. proc_ver == PVR_G5_970 ||
  113. proc_ver == PVR_G5_970FX ||
  114. proc_ver == PVR_G5_970MP ||
  115. proc_ver == PVR_G5_970GX ||
  116. proc_ver == PVR_POWER6 ||
  117. proc_ver == PVR_POWER7 ||
  118. proc_ver == PVR_POWER8 ||
  119. proc_ver == PVR_CELL_PPU)
  120. ret = AV_CPU_FLAG_ALTIVEC;
  121. if (proc_ver == PVR_POWER7 ||
  122. proc_ver == PVR_POWER8)
  123. ret |= AV_CPU_FLAG_VSX;
  124. if (proc_ver == PVR_POWER8)
  125. ret |= AV_CPU_FLAG_POWER8;
  126. return ret;
  127. #else
  128. // Since we were compiled for AltiVec, just assume we have it
  129. // until someone comes up with a proper way (not involving signal hacks).
  130. return AV_CPU_FLAG_ALTIVEC;
  131. #endif /* __AMIGAOS4__ */
  132. #endif /* HAVE_ALTIVEC */
  133. return 0;
  134. }