* Re: duplicated modulo
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
2 siblings, 0 replies; 7+ messages in thread
From: Bogdan Cristea @ 2011-04-01 9:30 UTC (permalink / raw)
To: Nicolas Kaiser; +Cc: linux-c-programming
On Friday, April 01, 2011 12:19:16 pm you wrote:
> Sure. But I fail to see where between
>
> a %= b;
> a %= b;
>
> and
>
> a = (a % b) % b;
>
> and
>
> a %= b;
>
> would be a difference?
That is basic math. Once you have obtained the remainder of the division by b,
taking the second time the remainder makes no sense.
--
Bogdan Cristea
^ permalink raw reply [flat|nested] 7+ messages in thread
* duplicated modulo
@ 2011-04-01 9:41 Nicolas Kaiser
2011-04-01 9:50 ` Michal Nazarewicz
2011-04-04 8:26 ` Hendrik Visage
0 siblings, 2 replies; 7+ messages in thread
From: Nicolas Kaiser @ 2011-04-01 9:41 UTC (permalink / raw)
To: linux-c-programming
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];
Best regards,
Nicolas Kaiser
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: duplicated modulo
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-04 8:26 ` Hendrik Visage
1 sibling, 1 reply; 7+ messages in thread
From: Michal Nazarewicz @ 2011-04-01 9:50 UTC (permalink / raw)
To: linux-c-programming, Nicolas Kaiser
On Fri, 01 Apr 2011 11:41:13 +0200, Nicolas Kaiser 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];
It's not just a module. It's also an assignment.
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: duplicated modulo
2011-04-01 9:50 ` Michal Nazarewicz
@ 2011-04-01 10:19 ` Nicolas Kaiser
2011-04-01 9:30 ` Bogdan Cristea
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Nicolas Kaiser @ 2011-04-01 10:19 UTC (permalink / raw)
To: Michal Nazarewicz; +Cc: linux-c-programming
* "Michal Nazarewicz" <mina86@mina86.com>:
> On Fri, 01 Apr 2011 11:41:13 +0200, Nicolas Kaiser 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];
>
> It's not just a module. It's also an assignment.
Sure. But I fail to see where between
a %= b;
a %= b;
and
a = (a % b) % b;
and
a %= b;
would be a difference?
Best regards,
Nicolas Kaiser
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: duplicated modulo
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
2 siblings, 0 replies; 7+ messages in thread
From: Bastian Bloessl @ 2011-04-01 10:28 UTC (permalink / raw)
To: Nicolas Kaiser; +Cc: Michal Nazarewicz, linux-c-programming
Am 01.04.2011 12:19, schrieb Nicolas Kaiser:
> * "Michal Nazarewicz"<mina86@mina86.com>:
>> On Fri, 01 Apr 2011 11:41:13 +0200, Nicolas Kaiser 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];
>>
>> It's not just a module. It's also an assignment.
>
> Sure. But I fail to see where between
>
> a %= b;
> a %= b;
>
> and
>
> a = (a % b) % b;
>
> and
>
> a %= b;
>
> would be a difference?
Perhaps an issue with signed / unsigned, or long vs. int?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: duplicated modulo
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
2 siblings, 0 replies; 7+ messages in thread
From: Michal Nazarewicz @ 2011-04-01 11:20 UTC (permalink / raw)
To: Nicolas Kaiser; +Cc: linux-c-programming
On Fri, 01 Apr 2011 12:19:16 +0200, Nicolas Kaiser <nikai@nikai.net> wrote:
> * "Michal Nazarewicz" <mina86@mina86.com>:
>> On Fri, 01 Apr 2011 11:41:13 +0200, Nicolas Kaiser 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];
>>
>> It's not just a module. It's also an assignment.
>
> Sure. But I fail to see where between
>
> a %= b;
> a %= b;
>
> and
>
> a = (a % b) % b;
>
> and
>
> a %= b;
>
> would be a difference?
Ah, sorry, you are right. I should stop responding to mail just
after waking up.
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michal "mina86" Nazarewicz (o o)
ooo +-----<email/xmpp: mnazarewicz@google.com>-----ooO--(_)--Ooo--
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: duplicated modulo
2011-04-01 9:41 duplicated modulo Nicolas Kaiser
2011-04-01 9:50 ` Michal Nazarewicz
@ 2011-04-04 8:26 ` Hendrik Visage
1 sibling, 0 replies; 7+ messages in thread
From: Hendrik Visage @ 2011-04-04 8:26 UTC (permalink / raw)
To: Nicolas Kaiser; +Cc: linux-c-programming
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-04-04 8:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).