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
9 #include "mozilla/Unused.h"
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
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
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
;
51 // Non-Linux detection here. Currently, on systems other than Linux,
52 // no CPU SIMD features will be detected.
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