Page 1 of 1

Odd modulus problem w/GCC 4.1.2

Posted: Sun Mar 09, 2008 6:59 pm
by inx
I'm most likely missing something very basic, but I'm having a big problem using the % operator in GCC 4.1.2. The form of modulus that's manifesting itself in my setup retains some functionality, but is only mildly useful. It's kind of just behaving like a boolean "Is there a remainder?" function. It just seems to spit out 0 if there is no remainder, and the second operand if there is one. I.E. 42 % 24 = 0, but 30 % 12 = 12. Anyone have any insight?

Posted: Sun Mar 09, 2008 7:50 pm
by 01000101
well 30 % 12 should be 6... hmm, reinstall?

or maybe there is a different logic, 6*2 = 12, and that is the value given earlier. are you sure it is always the second value being returned?

either way, its a reinstallable issue.

Posted: Sun Mar 09, 2008 8:11 pm
by jzgriffin
I agree with 01000101. Try reinstalling. By the way, what distribution of GCC are you using? MinGW, DJGPP, a pre-compiled Linux package, or a source installation. If it's source, post your configure flags.

Posted: Sun Mar 09, 2008 10:17 pm
by inx
The 30 % 12 was kind of pulled out of thin air (although I did test that number for the sake of due diligence before posting lol). I first noticed it when some padding code wasn't working correctly, so it was more on the order of x % PAGE_SIZE, and always getting PAGE_SIZE if there was a remainder. I've been working around it since then, since I save cycles not caring what the remainder is on that, anyway. However, I'm trying to go back through my code now that I've gotten somewhat far along and replace some rudimentary linear lookups with hash tables, so I kind of need it now.

It's the prebuilt package from Debian 4.0r0. The problem doesn't occur in programs compiled normally (e.g. gcc -o foo foo.c) w/glibc et. al. It only occurs in my kernel code. My pertinent compilation parameters are '-Wall -Werror -nostartfiles -no-stdlib -no-stdinc -fno-builtin', if that helps.

Posted: Mon Mar 10, 2008 10:11 am
by Wave
Compile with -S and post the resulting .s file here so we can have a look at it together with the c source (try to reproduce it in a small file).