This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] powerpc: New feature - HWCAP/HWCAP2 bits in the TCB
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: Kalle Olavi Niemitalo <kon at iki dot fi>
- Cc: libc-alpha <libc-alpha at sourceware dot org>
- Date: Fri, 10 Jul 2015 00:24:56 +0200
- Subject: Re: [PATCH] powerpc: New feature - HWCAP/HWCAP2 bits in the TCB
- Authentication-results: sourceware.org; auth=none
- References: <55760314 dot 6070601 at linux dot vnet dot ibm dot com> <559617FF dot 8010100 at redhat dot com> <20150703085542 dot GE32307 at domone> <55968AF8 dot 8060104 at redhat dot com> <20150703171121 dot GA23898 at domone> <1436283324 dot 12188 dot 25 dot camel at oc7878010663> <87egkhhtep dot fsf at Niukka dot kon dot iki dot fi>
On Fri, Jul 10, 2015 at 01:12:46AM +0300, Kalle Olavi Niemitalo wrote:
> Steven Munroe <munroesj@linux.vnet.ibm.comcom> writes:
>
> > if (__builtin_cpu_supports(ARCH_2_07) &&
> > __builtin_cpu_supports(VEC_CRYPTO))
> >
> > This is 3 instructions (lwz, andi., bc) as packed bits, but 5 or 6 as
> > byte Boolean.
>
> I would understand 3 instructions for "||" (test the zero flag) but
> how do you do it for "&&"? I have hardly any powerpc experience
> though, so perhaps there is some trick I don't realize.
>
> If not, and if "&&" is more common than "||" in HWCAP tests, then
> would it be worthwhile to invert the HWCAP bits in TCB? I guess
> it wouldn't, because such a format would increase the risk that
> the program crashes if the bits were not properly initialized
> before they were read.
A trick here is just like doing macro expansion. You need to realize
that arguments are masks so you test feature F by (get_hwcap & F) == F
Then this expands into
if (((get_hwcap & ARCH_2_07) == ARCH_2_07)
&& ((get_hwcap & VEC_CRYPTO) == VEC_CRYPTO))
Then you realize that its true if and only if all bits from ARCH_2_07
and VEC_CRYPTO masks are true. You could write that as
if ((get_hwcap & (ARCH_2_07 | VEC_CRYPTO)) == (ARCH_2_07 | VEC_CRYPTO))