Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1242209 > unrolled thread
| Started by | Russell King - ARM Linux <linux@arm.linux.org.uk> |
|---|---|
| First post | 2015-10-08 13:20 +0200 |
| Last post | 2015-10-08 17:00 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v2 14/22] arm64: Cleanup HWCAP handling Russell King - ARM Linux <linux@arm.linux.org.uk> - 2015-10-08 13:20 +0200
Re: [PATCH v2 14/22] arm64: Cleanup HWCAP handling Catalin Marinas <catalin.marinas@arm.com> - 2015-10-08 15:10 +0200
Re: [PATCH v2 14/22] arm64: Cleanup HWCAP handling Edward Nevill <edward.nevill@linaro.org> - 2015-10-08 17:00 +0200
| From | Russell King - ARM Linux <linux@arm.linux.org.uk> |
|---|---|
| Date | 2015-10-08 13:20 +0200 |
| Subject | Re: [PATCH v2 14/22] arm64: Cleanup HWCAP handling |
| Message-ID | <qhhoS-1PL-37@gated-at.bofh.it> |
On Thu, Oct 08, 2015 at 12:10:00PM +0100, Catalin Marinas wrote:
> On Mon, Oct 05, 2015 at 06:02:03PM +0100, Suzuki K. Poulose wrote:
> > +static bool cpus_have_hwcap(const struct arm64_cpu_capabilities *cap)
> > +{
> > + switch(cap->hwcap_type) {
> > + case CAP_HWCAP:
> > + return !!(elf_hwcap & cap->hwcap);
> > +#ifdef CONFIG_COMPAT
> > + case CAP_COMPAT_HWCAP:
> > + return !!(compat_elf_hwcap & (u32)cap->hwcap);
> > + case CAP_COMPAT_HWCAP2:
> > + return !!(compat_elf_hwcap2 & (u32)cap->hwcap);
> > +#endif
> > + default:
> > + BUG();
> > + return false;
> > + }
> > +}
>
> Apart from the multiple returns, you don't really need !! since the
> return type is bool already.
That's wrong. a & b doesn't return 0 or 1, but the bitwise-and result.
http://yarchive.net/comp/linux/bool.html
especially hpa's response.
--
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | Catalin Marinas <catalin.marinas@arm.com> |
|---|---|
| Date | 2015-10-08 15:10 +0200 |
| Message-ID | <qhj7k-4pv-17@gated-at.bofh.it> |
| In reply to | #1242209 |
On Thu, Oct 08, 2015 at 12:17:09PM +0100, Russell King - ARM Linux wrote:
> On Thu, Oct 08, 2015 at 12:10:00PM +0100, Catalin Marinas wrote:
> > On Mon, Oct 05, 2015 at 06:02:03PM +0100, Suzuki K. Poulose wrote:
> > > +static bool cpus_have_hwcap(const struct arm64_cpu_capabilities *cap)
> > > +{
> > > + switch(cap->hwcap_type) {
> > > + case CAP_HWCAP:
> > > + return !!(elf_hwcap & cap->hwcap);
> > > +#ifdef CONFIG_COMPAT
> > > + case CAP_COMPAT_HWCAP:
> > > + return !!(compat_elf_hwcap & (u32)cap->hwcap);
> > > + case CAP_COMPAT_HWCAP2:
> > > + return !!(compat_elf_hwcap2 & (u32)cap->hwcap);
> > > +#endif
> > > + default:
> > > + BUG();
> > > + return false;
> > > + }
> > > +}
> >
> > Apart from the multiple returns, you don't really need !! since the
> > return type is bool already.
>
> That's wrong. a & b doesn't return 0 or 1, but the bitwise-and result.
a & b is indeed a bitwise operation and, in this particular case, its
type is an unsigned long. However, because the return type of the
function is a bool, the result of the bitwise operation (unsigned long)
is converted to a bool.
The above may be true only for gcc, I haven't checked other compilers,
nor the standard (AFAIK, it appeared in C99).
On AArch64, the compiler generates something like:
tst x0, x1
cset w0, ne
ret
On AArch32, Thumb-2, I get:
tst r2, r3
ite ne
movne r0, #1
moveq r0, #0
bx lr
So a bool type function always returns 0 or 1 and does the appropriate
conversion.
> http://yarchive.net/comp/linux/bool.html
>
> especially hpa's response.
This seems to be more about a union of int and bool rather than
automatic type conversion. But I can see in the simple test that Linus
did towards the end of the thread that x86 does something similar with
converting a char to a bool:
testb %al, %al
setne %al
ret
I stand by my original comment.
--
Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Edward Nevill <edward.nevill@linaro.org> |
|---|---|
| Date | 2015-10-08 17:00 +0200 |
| Message-ID | <qhkPL-6FW-3@gated-at.bofh.it> |
| In reply to | #1242329 |
On Thu, 2015-10-08 at 14:00 +0100, Catalin Marinas wrote:
> On Thu, Oct 08, 2015 at 12:17:09PM +0100, Russell King - ARM Linux wrote:
> > On Thu, Oct 08, 2015 at 12:10:00PM +0100, Catalin Marinas wrote:
> > > On Mon, Oct 05, 2015 at 06:02:03PM +0100, Suzuki K. Poulose wrote:
> > > > +static bool cpus_have_hwcap(const struct arm64_cpu_capabilities *cap)
> > > > +{
> > > > + switch(cap->hwcap_type) {
> > > > + case CAP_HWCAP:
> > > > + return !!(elf_hwcap & cap->hwcap);
> > > > +#ifdef CONFIG_COMPAT
> > > > + case CAP_COMPAT_HWCAP:
> > > > + return !!(compat_elf_hwcap & (u32)cap->hwcap);
> > > > + case CAP_COMPAT_HWCAP2:
> > > > + return !!(compat_elf_hwcap2 & (u32)cap->hwcap);
> > > > +#endif
> > > > + default:
> > > > + BUG();
> > > > + return false;
> > > > + }
> > > > +}
> > >
> > > Apart from the multiple returns, you don't really need !! since the
> > > return type is bool already.
> >
> > That's wrong. a & b doesn't return 0 or 1, but the bitwise-and result.
>
> a & b is indeed a bitwise operation and, in this particular case, its
> type is an unsigned long. However, because the return type of the
> function is a bool, the result of the bitwise operation (unsigned long)
> is converted to a bool.
Why not just write what you mean
return (elf_hwcap & cap->hwcap) != 0;
So much clearer. And every compiler will compile it correctly and
optimally. The !!() syntax is just so ugly it is untrue. Its like people
who write
if (strcmp(..., ...)) ...
Break their fingers!
Ed.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web