This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Optimize manual byte swap implementations v2
Andreas Krebbel wrote:
>> Indeed, making it GET_MODE_SIZE (TYPE_MODE (type)) seems to make sense
>> (in the worst case for an n-byte type you have n-1 ORs and one shift,
>> all chained together making a depth of n).
>
> GET_MODE_SIZE (TYPE_MODE (type)) sounds good for the standard
> implementation but will not be sufficient for e.g. implementations like:
>
> ((in << 24)
> | (((uint8_t)(in >> 8) << 16))
> | (((uint8_t)(in >> 16) << 8))
> | (in >> 24));
I think this should be handled via folding, if it should. There are
also even trickier (and efficient!) ways to implement bswap, such as
AD AB BC CD
a = x ^ (x ROR 16); /* a = A^C B^D A^C B^D */
a &= ~0xFF0000; /* a = A^C 0 A^C B^D */
a >>= 8; /* a = 0 A^C 0 A^C */
return (x ROR 8) ^ a; /* x ROR 8 = D A B C */
but I don't expect your relatively simple pass to find them.
Paolo