public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* getauxv and ARMv7 platform detection
@ 2019-05-21  2:52 Jeffrey Walton
  2019-05-21  6:03 ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Walton @ 2019-05-21  2:52 UTC (permalink / raw)
  To: libc-help

Hi Everyone,

I just noticed the following code was failing on ARMv7 platforms:

// For older machines, like GCC 4.3 on ARMv6
#ifndef HWCAP_ARMv7
# define HWCAP_ARMv7 (1 << 29)
#endif

inline bool CPU_QueryARMv7()
{
    if (getauxval(AT_HWCAP) & HWCAP_ARMv7) != 0)
        return true;
    return false;
}

Looking through Torvalds GitHub [1] I don't see a reliable define for
HWCAP_ARMv7 in hwcap.h.

I know I can fallback to NEON, but that misses earlier devices that
are ARMv7 but lacks NEON.

Searching is turning up a lot of spurious noise (for Aarch64/ARMv8),
and one hit for Mozilla working around the same problem [2].

My question is, how do we use getauxval to detect ARMv7 platforms?

Thanks in advance.

[1] https://github.com/torvalds/linux/blob/master/arch/arm/include/uapi/asm/hwcap.h
[2] https://hg.mozilla.org/releases/mozilla-aurora/rev/522951ff7046fd2bdf3916c973fbfde27be0af31

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getauxv and ARMv7 platform detection
  2019-05-21  2:52 getauxv and ARMv7 platform detection Jeffrey Walton
@ 2019-05-21  6:03 ` Florian Weimer
  2019-05-21  6:11   ` Jeffrey Walton
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2019-05-21  6:03 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: libc-help

* Jeffrey Walton:

> My question is, how do we use getauxval to detect ARMv7 platforms?

What is the actual problem you are trying to solve?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getauxv and ARMv7 platform detection
  2019-05-21  6:03 ` Florian Weimer
@ 2019-05-21  6:11   ` Jeffrey Walton
  2019-05-21  6:31     ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Walton @ 2019-05-21  6:11 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-help

On Tue, May 21, 2019 at 2:03 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Jeffrey Walton:
>
> > My question is, how do we use getauxval to detect ARMv7 platforms?
>
> What is the actual problem you are trying to solve?

I'm trying to detect if the platform is ARMv7 at runtime.

Jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getauxv and ARMv7 platform detection
  2019-05-21  6:11   ` Jeffrey Walton
@ 2019-05-21  6:31     ` Florian Weimer
  2019-05-21  6:45       ` Jeffrey Walton
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2019-05-21  6:31 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: libc-help

* Jeffrey Walton:

> On Tue, May 21, 2019 at 2:03 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Jeffrey Walton:
>>
>> > My question is, how do we use getauxval to detect ARMv7 platforms?
>>
>> What is the actual problem you are trying to solve?
>
> I'm trying to detect if the platform is ARMv7 at runtime.

Yes, but why?  Just to print a diagnostic?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getauxv and ARMv7 platform detection
  2019-05-21  6:31     ` Florian Weimer
@ 2019-05-21  6:45       ` Jeffrey Walton
  2019-05-21 20:53         ` Adhemerval Zanella
  0 siblings, 1 reply; 6+ messages in thread
From: Jeffrey Walton @ 2019-05-21  6:45 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-help

On Tue, May 21, 2019 at 2:31 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Jeffrey Walton:
>
> > On Tue, May 21, 2019 at 2:03 AM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * Jeffrey Walton:
> >>
> >> > My question is, how do we use getauxval to detect ARMv7 platforms?
> >>
> >> What is the actual problem you are trying to solve?
> >
> > I'm trying to detect if the platform is ARMv7 at runtime.
>
> Yes, but why?  Just to print a diagnostic?

We switch to ARMv7 and NEON implementations at runtime if the CPU
supports it. We can usually achieve 2x or 3x speedups over
ARMv{4|5|6}.

We've got SIGILL probes in place but they are an expensive fallback.
We prefer a faster and cleaner solution on Linux like getauxv().

We don't control how the library is built. Users and distros do their
own things. About the only thing we can count on is, -march=native is
useless (and sometimes segfaults the compiler), -march=XXX is missing
and -mfpu=YYY is missing.

Jeff

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getauxv and ARMv7 platform detection
  2019-05-21  6:45       ` Jeffrey Walton
@ 2019-05-21 20:53         ` Adhemerval Zanella
  0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2019-05-21 20:53 UTC (permalink / raw)
  To: libc-help



On 21/05/2019 03:45, Jeffrey Walton wrote:
> On Tue, May 21, 2019 at 2:31 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Jeffrey Walton:
>>
>>> On Tue, May 21, 2019 at 2:03 AM Florian Weimer <fweimer@redhat.com> wrote:
>>>>
>>>> * Jeffrey Walton:
>>>>
>>>>> My question is, how do we use getauxval to detect ARMv7 platforms?
>>>>
>>>> What is the actual problem you are trying to solve?
>>>
>>> I'm trying to detect if the platform is ARMv7 at runtime.
>>
>> Yes, but why?  Just to print a diagnostic?
> 
> We switch to ARMv7 and NEON implementations at runtime if the CPU
> supports it. We can usually achieve 2x or 3x speedups over
> ARMv{4|5|6}.
> 
> We've got SIGILL probes in place but they are an expensive fallback.
> We prefer a faster and cleaner solution on Linux like getauxv().
> 
> We don't control how the library is built. Users and distros do their
> own things. About the only thing we can count on is, -march=native is
> useless (and sometimes segfaults the compiler), -march=XXX is missing
> and -mfpu=YYY is missing.
> 

Unfortunately hwcap does not export this information, you will need to
parse /proc/cpuinfo 'CPU architecture' field and take some issues
in consideration.  Check google cpu_features project [1], it provides
such information through a library.

[1] https://github.com/google/cpu_features/blob/master/src/cpuinfo_arm.c

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-05-21 20:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-21  2:52 getauxv and ARMv7 platform detection Jeffrey Walton
2019-05-21  6:03 ` Florian Weimer
2019-05-21  6:11   ` Jeffrey Walton
2019-05-21  6:31     ` Florian Weimer
2019-05-21  6:45       ` Jeffrey Walton
2019-05-21 20:53         ` Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).