Re: duplicated modulo

Hendrik Visage <[email protected]> Mon, 4 Apr 2011 10:26:05 +0200
Newsgroups org.kernel.vger.linux-c-programming
Message-ID <[email protected]>
On Fri, Apr 1, 2011 at 11:41 AM, Nicolas Kaiser <[email protected]> wrote:
> I'm curious: a duplicated modulo operation can't possibly make
> any difference, can it?
>
> diff -u -p ./arch/powerpc/platforms/powermac/nvram.c /tmp/nothing/arch/powerpc/platforms/powermac/nvram.c
> --- ./arch/powerpc/platforms/powermac/nvram.c   2011-03-31 09:52:41.674292401 +0200
> +++ /tmp/nothing/arch/powerpc/platforms/powermac/nvram.c
> @@ -246,7 +246,6 @@ static u32 core99_calc_adler(u8 *buffer)
>        high = 0;
>        for (cnt=0; cnt<(NVRAM_SIZE-CORE99_ADLER_START); cnt++) {
>                if ((cnt % 5000) == 0) {
> -                       high  %= 65521UL;
>                        high %= 65521UL;
>                }
>                low += buffer[cnt];

The emphasis should be on "shouldn't" not "possibly" ;)

As other mentioned, you could have issues with going to different types etc.

However, the major reason *I* would remove it, is that the division
operation is an expensive operation, and then you still need to get
the remainder too and also since it's mostly superfluous thus adding
bloat.
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html