lkml.org 
[lkml]   [2013]   [May]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: The type of bitops
From
On Mon, May 6, 2013 at 6:36 PM, H. Peter Anvin <hpa@zytor.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


\
 
 \ /
  Last update: 2013-05-07 05:21    [W:0.065 / U:0.416 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site