duplicated modulo
Subsystems (2)
I'm curious: a duplicated modulo operation can't possibly make any difference, can it?
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c renamed from arch/powerpc/platforms/powermac/nvram.c +0 -1
@@ -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
Quoted 8 lines · Nicolas Kaiser
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.c2011-03-31
09:52:41.674292401 +0200
+++/tmp/nothing/arch/powerpc/platforms/powermac/nvram.c
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c static u32 core99_calc_adler(u8 *buffer) · line 251
Quoted 7 lines
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c renamed from arch/powerpc/platforms/powermac/nvram.c +0
-1@@ -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.
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--
* "Michal Nazarewicz" <[email protected]>:
Quoted 19 lines · Nicolas Kaiser
Quoted 9 lines
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.c2011-03-31
09:52:41.674292401 +0200
+++/tmp/nothing/arch/powerpc/platforms/powermac/nvram.ctmp/nothing/arch/powerpc/platforms/powermac/nvram.c static u32 core99_calc_adler(u8 *buffer) · line 251
Quoted 7 lines
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c renamed from arch/powerpc/platforms/powermac/nvram.c +0
-1@@ -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
Quoted 7 lines · you
Sure. But I fail to see where between
a %= b;
a %= b;and
Quoted 7 lines
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.
Signature · 1 line
Bogdan Cristea
Am 01.04.2011 12:19, schrieb Nicolas Kaiser:
Quoted 28 lines
* "Michal Nazarewicz"<[email protected]>:
Quoted 19 lines · Nicolas Kaiser
Quoted 9 lines
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.c2011-03-31
09:52:41.674292401 +0200
+++/tmp/nothing/arch/powerpc/platforms/powermac/nvram.ctmp/nothing/arch/powerpc/platforms/powermac/nvram.c static u32 core99_calc_adler(u8 *buffer) · line 251
Quoted 7 lines
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c renamed from arch/powerpc/platforms/powermac/nvram.c +0
-1@@ -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
Quoted 7 lines
a = (a % b) % b;
and
a %= b;
would be a difference?
Perhaps an issue with signed / unsigned, or long vs. int?
Quoted 28 lines · Nicolas Kaiser
* "Michal Nazarewicz" <[email protected]>:
Quoted 19 lines · Nicolas Kaiser
Quoted 9 lines
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.c2011-03-31
09:52:41.674292401 +0200
+++/tmp/nothing/arch/powerpc/platforms/powermac/nvram.ctmp/nothing/arch/powerpc/platforms/powermac/nvram.c static u32 core99_calc_adler(u8 *buffer) · line 251
Quoted 7 lines
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c renamed from arch/powerpc/platforms/powermac/nvram.c +0
-1@@ -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
Quoted 7 lines
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.
Signature · 4 lines
Best regards, _ _ .o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o ..o | Computer Science, Michal "mina86" Nazarewicz (o o) ooo +-----<email/xmpp: [email protected]>-----ooO--(_)--Ooo--
Quoted 7 lines · Nicolas Kaiser
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
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c static u32 core99_calc_adler(u8 *buffer) · line 251
Quoted 7 lines
tmp/nothing/arch/powerpc/platforms/powermac/nvram.c renamed from arch/powerpc/platforms/powermac/nvram.c 2011-03-31 09:52:41.674292401 +0200 +0
-1@@ -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