[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+55aFxqnB4CmJQyE1_r7swFyWUYhSU7Eyvg+7uRpCXUtpU1jg@mail.gmail.com>
Date: Mon, 6 May 2013 19:33:09 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: "H. Peter Anvin" <hpa@...or.com>
Cc: linux-arch <linux-arch@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>
Subject: Re: The type of bitops
On Mon, May 6, 2013 at 6:36 PM, H. Peter Anvin <hpa@...or.com> wrote:
>>
>> That sounds insane. Just *how* could the size of the argument even
>> matter? Seriously, there's no *difference* between a 32-bit or a
>> 64-bit index. The code is the same, there's no possible reason to make
>> it be different.
>>
>
> The only reason on x86 would be to avoid the REX prefix. Hardly worth
> it, though.
Hmm. You *might* be able to do it by simply turning the inline
functions into statement expressions, and letting the compiler do the
types as it will. Use "(nr)+0" to make sure that the type is at least
"int", and then "Ir" as the asm constraint.
A quick test seems to imply that this works:
#define test_bit(nr, addr) \
({ int oldbit; \
asm volatile("bt %2,%1\n\t" \
"sbb %0,%0" \
: "=r" (oldbit) \
: "m" (*(unsigned long *)(addr)), \
"Ir" ((nr)+0)); \
oldbit; })
int test(int idx1, long idx2, void *addr)
{
return test_bit(idx1, addr) + test_bit(idx2, addr);
}
and I get
...
bt %edi,(%rdx)
...
bt %rsi,(%rdx)
...
for the int/long index respectively. So if the argument is an 'int',
it will avoid the rex prefix.
And I tested that using a "char" index does indeed do the right thing too:
movsbl %dil,%eax
bt %eax,(%rcx)
so that all seems surmountable.Whether it really matters, I dunno.
Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists