linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hendrik Visage <hvjunk@gmail.com>
To: Nicolas Kaiser <nikai@nikai.net>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: duplicated modulo
Date: Mon, 4 Apr 2011 10:26:05 +0200	[thread overview]
Message-ID: <BANLkTikDWQcXY+5quaRk-Qz9PBxnDdXt0A@mail.gmail.com> (raw)
In-Reply-To: <20110401114113.6e2e91af@absol.kitzblitz>

On Fri, Apr 1, 2011 at 11:41 AM, Nicolas Kaiser <nikai@nikai.net> 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

      parent reply	other threads:[~2011-04-04  8:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-01  9:41 duplicated modulo Nicolas Kaiser
2011-04-01  9:50 ` Michal Nazarewicz
2011-04-01 10:19   ` Nicolas Kaiser
2011-04-01  9:30     ` Bogdan Cristea
2011-04-01 10:28     ` Bastian Bloessl
2011-04-01 11:20     ` Michal Nazarewicz
2011-04-04  8:26 ` Hendrik Visage [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BANLkTikDWQcXY+5quaRk-Qz9PBxnDdXt0A@mail.gmail.com \
    --to=hvjunk@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=nikai@nikai.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).