The PowerPC __builtin_cpu_supports and __builtin_cpu_is built-in functions require GLIBC 2.23, since they use fixed words at the end of thread control area to store the HWCAP and HWCAP2 bits. If the compiler was not configured with the appropriate GLIBC, the compiler will generate a 0 as the result of the built-in function call.
I've been adding the target_clone attribute support to GCC, and the resolver function uses __builtin_cpu_supports to detect which hardware ISA is being used. On systems with an older GLIBC, only the default clone function will get called because __builtin_cpu_supports returns 0. This adds a target supports option in dejagnu so that future tests can use this to determine whether or not to test target_clones. I have verified that this patch works with the patches I plan to submit tomorrow for enhancing the PowerPC target_clone support. Can I install this into the trunk? Given that GCC 7 supports __builtin_cpu_is and __builtin_cpu_supports, I would ask if I could backport this to GCC 7.x as well to allow future tests to be back ported. 2017-06-27 Michael Meissner <meiss...@linux.vnet.ibm.com> PR target/81193 * lib/target-supports.exp (check_ppc_cpu_supports_hw_available): New test to make sure __builtin_cpu_supports works on power7 and newer. Index: gcc/testsuite/lib/target-supports.exp =================================================================== --- gcc/testsuite/lib/target-supports.exp (revision 249606) +++ gcc/testsuite/lib/target-supports.exp (working copy) @@ -1930,6 +1930,37 @@ proc check_effective_target_powerpc64_no } {-O2}] } +# Return 1 if the target supports the __builtin_cpu_supports built-in, +# including having a new enough library to support the test. Cache the result. +# Require at least a power7 to run on. + +proc check_ppc_cpu_supports_hw_available { } { + return [check_cached_effective_target ppc_cpu_supports_hw_available { + # Some simulators are known to not support VSX/power8 instructions. + # For now, disable on Darwin + if { [istarget powerpc-*-eabi] + || [istarget powerpc*-*-eabispe] + || [istarget *-*-darwin*]} { + expr 0 + } else { + set options "-mvsx" + check_runtime_nocache ppc_cpu_supports_hw_available { + int main() + { + #ifdef __MACH__ + asm volatile ("xxlor vs0,vs0,vs0"); + #else + asm volatile ("xxlor 0,0,0"); + #endif + if (!__builtin_cpu_supports ("vsx")) + return 1; + return 0; + } + } $options + } + }] +} + # Return 1 if the target supports executing power8 vector instructions, 0 # otherwise. Cache the result. @@ -6922,6 +6953,7 @@ proc is-effective-target { arg } { "ppc_float128_sw" { set selected [check_ppc_float128_sw_available] } "ppc_float128_hw" { set selected [check_ppc_float128_hw_available] } "ppc_recip_hw" { set selected [check_ppc_recip_hw_available] } + "ppc_cpu_supports_hw" { set selected [check_ppc_cpu_supports_hw_available] } "dfp_hw" { set selected [check_dfp_hw_available] } "htm_hw" { set selected [check_htm_hw_available] } "named_sections" { set selected [check_named_sections_available] } -- Michael Meissner, IBM IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA email: meiss...@linux.vnet.ibm.com, phone: +1 (978) 899-4797