<div dir="ltr"><div dir="ltr">I've filed a bugzilla for this <a href="https://bugs.llvm.org/show_bug.cgi?id=40058">https://bugs.llvm.org/show_bug.cgi?id=40058</a><br clear="all"><div><div dir="ltr" class="gmail_signature">~Craig</div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Dec 17, 2018 at 3:48 PM Stefan Kanthak via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi @ll,<br>
<br>
compile with -O3 -m32 -march=i686 (see <<a href="https://godbolt.org/z/fjjUl6" rel="noreferrer" target="_blank">https://godbolt.org/z/fjjUl6</a>>)<br>
<br>
unsigned long lreverse(unsigned long x) // swap all bits<br>
{<br>
x = ((x & 0xAAAAAAAAUL) >> 1)<br>
| ((x & ~0xAAAAAAAAUL) << 1);<br>
x = ((x & 0xCCCCCCCCUL) >> 2)<br>
| ((x & ~0xCCCCCCCCUL) << 2);<br>
x = ((x & 0xF0F0F0F0UL) >> 4)<br>
| ((x & ~0xF0F0F0F0UL) << 4);<br>
x = ((x & 0xFF00FF00UL) >> 8)<br>
| ((x & ~0xFF00FF00UL) << 8);<br>
x = ((x & 0xFFFF0000UL) >> 16)<br>
| ((x & ~0xFFFF0000UL) << 16);<br>
<br>
return x;<br>
}<br>
<br>
lreverse: # @lreverse<br>
mov eax, dword ptr [esp + 4]<br>
mov ecx, eax<br>
shr ecx, 1<br>
and ecx, 1431655765<br>
and eax, 1431655765<br>
lea eax, [ecx + 2*eax]<br>
mov ecx, eax<br>
shr ecx, 2<br>
and ecx, 858993459<br>
and eax, 858993459<br>
lea eax, [ecx + 4*eax]<br>
mov ecx, eax<br>
shr ecx, 4<br>
and ecx, 252645135<br>
shl eax, 4<br>
and eax, -252645136<br>
or eax, ecx<br>
#ifndef _OPTIMISER_GONE_FISHING // until here, almost perfect;<br>
bswap eax // the next 7 instructions but can<br>
#else // be replaced by a single BSWAP<br>
mov ecx, eax<br>
shr ecx, 8<br>
and ecx, 16711935 <br>
shl eax, 8<br>
and eax, -16711936<br>
or eax, ecx<br>
rol eax, 16<br>
#endif<br>
ret<br>
<br>
<br>
unsigned long long llreverse(unsigned long long x)<br>
{<br>
#if 0<br>
x = ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1)<br>
| ((x & ~0xAAAAAAAAAAAAAAAAULL) << 1);<br>
x = ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2)<br>
| ((x & ~0xCCCCCCCCCCCCCCCCULL) << 2);<br>
x = ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4)<br>
| ((x & ~0xF0F0F0F0F0F0F0F0ULL) << 4);<br>
x = ((x & 0xFF00FF00FF00FF00ULL) >> 8)<br>
| ((x & ~0xFF00FF00FF00FF00ULL) << 8);<br>
x = ((x & 0xFFFF0000FFFF0000ULL) >> 16)<br>
| ((x & ~0xFFFF0000FFFF0000ULL) << 16);<br>
x = ((x & 0xFFFFFFFF00000000ULL) >> 32)<br>
| ((x & ~0xFFFFFFFF00000000ULL) << 32);<br>
<br>
return x;<br>
#else<br>
x = ((x >> 1) & ~0xAAAAAAAAAAAAAAAAULL)<br>
| ((x << 1) & 0xAAAAAAAAAAAAAAAAULL);<br>
x = ((x >> 2) & ~0xCCCCCCCCCCCCCCCCULL)<br>
| ((x << 2) & 0xCCCCCCCCCCCCCCCCULL);<br>
x = ((x >> 4) & ~0xF0F0F0F0F0F0F0F0ULL)<br>
| ((x << 4) & 0xF0F0F0F0F0F0F0F0ULL);<br>
x = ((x >> 8) & ~0xFF00FF00FF00FF00ULL)<br>
| ((x << 8) & 0xFF00FF00FF00FF00ULL);<br>
x = ((x >> 16) & ~0xFFFF0000FFFF0000ULL)<br>
| ((x << 16) & 0xFFFF0000FFFF0000ULL);<br>
<br>
return (x >> 32) | (x << 32);<br>
#endif<br>
}<br>
<br>
llreverse: # @llreverse<br>
push esi<br>
mov eax, dword ptr [esp + 8]<br>
mov ecx, dword ptr [esp + 12]<br>
mov edx, eax<br>
shr edx<br>
mov esi, ecx<br>
shr esi<br>
<br>
#ifdef OPTIMISER_GONE_FISHING<br>
and esi, 1431655765<br>
and edx, 1431655765<br>
and ecx, 1431655765<br>
and eax, 1431655765<br>
#else<br>
push ebx<br>
mov ebx, 1431655765<br>
and esi, ebx<br>
and edx, ebx<br>
and ecx, ebx<br>
and eax, ebx<br>
#endif<br>
lea edx, [edx + 2*eax]<br>
lea eax, [esi + 2*ecx]<br>
mov ecx, eax<br>
shr ecx, 2<br>
mov esi, edx<br>
shr esi, 2<br>
#ifdef OPTIMISER_GONE_FISHING<br>
and esi, 858993459<br>
and ecx, 858993459<br>
and edx, 858993459<br>
and eax, 858993459<br>
<br>
#else<br>
mov ebx, 858993459<br>
and esi, ebx<br>
and ecx, ebx<br>
and edx, ebx<br>
and eax, ebx<br>
#endif<br>
lea eax, [ecx + 4*eax]<br>
lea edx, [esi + 4*edx]<br>
mov ecx, edx<br>
shr ecx, 4<br>
mov esi, eax<br>
shr esi, 4<br>
<br>
#ifdef OPTIMISER_GONE_FISHING<br>
and esi, 252645135<br>
and ecx, 252645135<br>
<br>
#else<br>
mov ebx, 252645135<br>
and esi, ebx<br>
and ecx, ebx<br>
#endif<br>
shl edx, 4<br>
shl eax, 4<br>
<br>
#ifdef OPTIMISER_GONE_FISHING<br>
and eax, -252645136<br>
#else<br>
not ebx<br>
and eax, ebx<br>
#endif<br>
or eax, esi<br>
<br>
#ifdef OPTIMISER_GONE_FISHING<br>
and edx, -252645136<br>
#else<br>
and edx, ebx<br>
pop ebx<br>
#endif<br>
or edx, ecx<br>
#ifndef OPTIMISER_GONE_FISHING // until here, quite good;<br>
bswap eax // the next 14 instructions but can<br>
bswap edx // be replaced by a two BSWAPs<br>
#else<br>
mov ecx, eax<br>
shr ecx, 8<br>
mov esi, edx<br>
shr esi, 8<br>
and esi, 16711935<br>
and ecx, 16711935<br>
shl eax, 8<br>
shl edx, 8<br>
and edx, -16711936<br>
or edx, esi<br>
and eax, -16711936<br>
or eax, ecx<br>
rol edx, 16<br>
rol eax, 16<br>
#endif<br>
pop esi<br>
ret<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>