Re: [PATCH 1/12] random pt4: Create new rol32/ror32 bitops

From: H. Peter Anvin
Date: Mon Jan 24 2005 - 17:28:59 EST


Followup to: <200501230247_MC3-1-93FA-7A4E@xxxxxxxxxxxxxx>
By author: Chuck Ebbert <76306.1226@xxxxxxxxxxxxxx>
In newsgroup: linux.dev.kernel
>
> On Sat, 22 Jan 2005 at 20:13:24 -0800 Matt Mackall wrote:
>
> > So I think tweaks for x86 at least are unnecessary.
>
> So the compiler looks for that specific sequence of instructions:
>
> (a << b) | (a >> (sizeof(a) * 8 - b)
>
> and recognizes that it means rotation? Wow.
>

You know, there is a LOT of instructions like that. x86 has a single
instruction to do:

a = b + (c << 3) + 3600;

(Assuming a, b and c are in eax, ebx, and ecx, respecively, the
instruction is "leal 3600(%ebx,%ecx,3),%eax".)

The C compiler really needs to recognize these kinds of idioms, not
just in the source, but that occur natually as a result of code
generation and optimizations. The compiler lingo for this is
"peephole optimization."

-hpa
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/