Re: * 4 converted to << 2 for networking code

Matthias Andree (matthias.andree@stud.uni-dortmund.de)
Wed, 10 Jan 2001 23:21:23 +0100


On Wed, 10 Jan 2001, antirez wrote:

> Hi all,
>
> The attached patch converts many occurences of '* 4' in the networking code
> (often used to convert in bytes the TCP data offset and the IP header len)
> to the faster '<< 2'. Since this was a quite repetitive work it's better
> if someone double-check it before to apply the patch.
> The patch is for linux-2.4.
>
> Please, CC: me for replies since I'm not subscribed to the list.

You'd better be. As Alan Cox pointed out some time ago, this is the
compiler's duty, to be more precise, it's the peephole (local)
optimizer's task, if it's actually implemented in the core or the
backend, I cannot currently tell, and I don't care.

But see a minimal program
main(int argc) {
j(argc * 4);
}

run gcc -O2 -S thissource.c and then -O0 and compare. On an
amigaos-m68k configured gcc 2.7.2.3, this directly throws asll #2,d0
(arithmetic shift left by 2 positions, fill with trailing zeroes), -O2
saves some moving around. (I cannot read 386 assembly language, thus
m68k ;)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/