Backed out 7 changesets (bug 1881620) for causing frequent media crashes. CLOSED...
[gecko.git] / mozglue / build / ppc.cpp
blob20ef1213862b8cd316f37bd17152384e561fb3a7
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* compile-time and runtime tests for whether to use Power ISA-specific
6 * extensions */
8 #include "ppc.h"
9 #include "mozilla/Unused.h"
11 #include <stdio.h>
12 #include <stdlib.h>
14 #if defined(XP_LINUX)
15 // Use the getauxval() function if available.
16 // ARCH_3_00 wasn't defined until glibc 2.23, so include just in case.
17 # include <sys/auxv.h>
18 # ifndef PPC_FEATURE2_ARCH_3_00
19 # define PPC_FEATURE2_ARCH_3_00 0x00800000
20 # endif
21 #endif
23 const unsigned PPC_FLAG_VMX = 1;
24 const unsigned PPC_FLAG_VSX = 2;
25 const unsigned PPC_FLAG_VSX3 = 4;
27 static signed get_ppc_cpu_flags(void) {
28 // This could be expensive, so cache the result.
29 static signed cpu_flags = -1;
31 if (cpu_flags > -1) { // already checked
32 return cpu_flags;
34 cpu_flags = 0;
36 #if defined(XP_LINUX)
37 // Try getauxval().
38 unsigned long int cap = getauxval(AT_HWCAP);
39 unsigned long int cap2 = getauxval(AT_HWCAP2);
41 if (cap & PPC_FEATURE_HAS_ALTIVEC) {
42 cpu_flags |= PPC_FLAG_VMX;
44 if (cap & PPC_FEATURE_HAS_VSX) {
45 cpu_flags |= PPC_FLAG_VSX;
47 if (cap2 & PPC_FEATURE2_ARCH_3_00) {
48 cpu_flags |= PPC_FLAG_VSX3;
50 #else
51 // Non-Linux detection here. Currently, on systems other than Linux,
52 // no CPU SIMD features will be detected.
53 #endif
55 return cpu_flags;
58 namespace mozilla {
59 namespace ppc_private {
60 bool vmx_enabled = !!(get_ppc_cpu_flags() & PPC_FLAG_VMX);
61 bool vsx_enabled = !!(get_ppc_cpu_flags() & PPC_FLAG_VSX);
62 bool vsx3_enabled = !!(get_ppc_cpu_flags() & PPC_FLAG_VSX3);
63 } // namespace ppc_private
64 } // namespace mozilla