* Alfie On Wed, Jul 23, 2025 at 09:51:50AM +0100, Alfie Richards wrote: > On 23/07/2025 09:45, Yury Khrustalev wrote: > > gcc/testsuite/ChangeLog: > > > > * g++.target/aarch64/mv-cpu-features.C: new test. > > ... > > > > +extern "C" void > > +__init_cpu_features_resolver (unsigned long hwcap, const ifunc_arg_t *arg); > > + > > +extern "C" void * > > +fun_resolver (uint64_t a0, const ifunc_arg_t *a1) > > +{ > > + ifunc_arg_t arg = {}; > > + arg.size = sizeof (ifunc_arg_t); > > + arg.hwcap = HWCAP_ATOMICS; > > + arg.hwcap2 = HWCAP2_RNG; > > + __init_cpu_features_resolver (arg.hwcap | _IFUNC_ARG_HWCAP, &arg); > > + return (void *)(uintptr_t)impl; > > +} > > + > > +extern "C" int fun (void) __attribute__((ifunc ("fun_resolver"))); > > + > > +int main () > > +{ > > + int res = fun (); > > + if (res == 0 && foo () == 2) > > + return 0; > > > The FMV part of this test doesn't seem quite right.
This tests triggers FMV automatic resovler and checks that it selects the right implementation when both features are present. Sorry, I should have added a comment! > For FMV it is using the auto-generated resolver, which will use > __init_cpu_features_resolver and get a real read on the host's arch. To ensure we have stable test results, I use manual ifunc resolver that calls __init_cpu_features_resolver() with a custom set of hwcap values. We set one bit in hwcap and one bit in hwcap2, the rest are zero. Because __init_cpu_features_resolver() will only call __init_cpu_features_constructor() once during runtime, the subsequent invocation of the automatic FMV resolver will not read the real hwcap bits from OS. > This > test then seems to check that the lse version is selected. So it seems like > this would only work on systems with lse? > > The ifunc part looks good to my eye. Thanks, Yury