Re: [PATCH 1/2] lzma support: decompression lib, initrd support

From: Paulo Marques
Date: Tue Jun 14 2005 - 07:40:40 EST


Andrew Morton wrote:
Christian Leber <christian@xxxxxxxx> wrote:
[...]
+ for (pb = 0; prop0 >= (9 * 5); pb++, prop0 -= (9 * 5));
+ for (lp = 0; prop0 >= 9; lp++, prop0 -= 9);

Put the ";" on a line of its own.

I'd have thought the above could be done arithmetically?

I just tried a small test program to see the speed/code size difference to this code, which is the arithmetic equivalent:

pb = prop0 / (9 * 5);
prop0 %= (9 * 5);
lp = prop0 / 9;
prop0 %= 9;

This code runs a lot faster than the original. This is not very important since it runs only once AFAICT.

As for the code size, it is smaller if compiled with -Os, but larger when compiled with -O2 or -O3.

When compiled with -Os, gcc uses the idiv instruction and it even uses its reminder so that it only does 2 idiv instructions to do the 4 operations above.

With -O2 or -O3, it does a hard to follow division "by hand" using several instructions, rendering the code about 2.5x larger (but amazingly a lot faster).

The tests were done with gcc 3.3.2.

--
Paulo Marques - www.grupopie.com

An expert is a person who has made all the mistakes that can be
made in a very narrow field.
Niels Bohr (1885 - 1962)
-
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/