Skip to contentSkip to conversation

from where comes "__moddi3"?

DISCUSSION Robert P. J. Day 7 participants 10 messages Jul 21, 2007

lore
Share & tools
lore
#0 lore raw

again, probably displaying my abject ignorance, but i wrote a
trivial module that tries to "var % 15", and i get:

WARNING: "__moddi3" undefined!

and, not surprisingly, when i try to insmod:

insmod: error inserting 'seq.ko': -1 Unknown symbol in module

(using 16 rather than 15 works fine, as i assume that the modulus call is simply replaced by an optimized bitwise comparison.)

so ... from where comes __moddi3? i know there are places in the
kernel source tree that do non-power-of-2 moduli, and they work fine, no? thanks.

rday

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================
#1 lore raw
Quoted 7 lines · Robert P. J. Day

again, probably displaying my abject ignorance, but i wrote a trivial module that tries to "var % 15", and i get:

WARNING: "__moddi3" undefined!

and, not surprisingly, when i try to insmod:

Quoted 8 lines

insmod: error inserting 'seq.ko': -1 Unknown symbol in module

(using 16 rather than 15 works fine, as i assume that the modulus call is simply replaced by an optimized bitwise comparison.)

so ... from where comes __moddi3? i know there are places in the
kernel source tree that do non-power-of-2 moduli, and they work fine, no? thanks.

let me guess, 32 bit kernel, and var is 64 bit?

gcc translates that into a libgcc call, which we _explicitly_ do not have because 64bit divisions are expensive!

use do_div().

16 works because gcc translates that into a right shift.

#2 lore raw
Quoted 10 lines · Peter Zijlstra
Quoted 9 lines · Robert P. J. Day

again, probably displaying my abject ignorance, but i wrote a trivial module that tries to "var % 15", and i get:

WARNING: "__moddi3" undefined!

and, not surprisingly, when i try to insmod:

insmod: error inserting 'seq.ko': -1 Unknown symbol in module

Quoted 8 lines
Quoted 6 lines

(using 16 rather than 15 works fine, as i assume that the modulus call is simply replaced by an optimized bitwise comparison.)

so ... from where comes __moddi3? i know there are places in the
kernel source tree that do non-power-of-2 moduli, and they work fine, no? thanks.

let me guess, 32 bit kernel, and var is 64 bit?

um ... yeah. duh. var type is actually loff_t. i should have realized that.

Quoted 4 lines

gcc translates that into a libgcc call, which we _explicitly_ do not have because 64bit divisions are expensive!

use do_div().

gotcha. thanks.

rday

Signature · 7 lines
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://fsdev.net/wiki/index.php?title=Main_Page
========================================================================
#3 lore raw
In reply to Peter Zijlstra
Quoted 5 lines · Peter Zijlstra

On Sat, 2007-07-21 at 15:21 -0400, Robert P. J. Day wrote:

use do_div().

16 works because gcc translates that into a right shift.

Right shift? Doesn't it just mask out everything but the low 4 bit?

MfG, JBG

Signature · 3 lines
      Jan-Benedict Glaw      [email protected]              +49-172-7608481
Signature of:             God put me on earth to accomplish a certain number of
the second  :            things. Right now I am so far behind I will never die.
#4 lore raw
Quoted 8 lines · Jan-Benedict Glaw
Quoted 5 lines · Peter Zijlstra

On Sat, 2007-07-21 at 15:21 -0400, Robert P. J. Day wrote:

use do_div().

16 works because gcc translates that into a right shift.

Right shift? Doesn't it just mask out everything but the low 4 bit?

Yeah, its bitwise and for modulo and shifts for mult and div.

Silly mistake on my side.

#5 lore raw
In reply to Robert P. J. Day
Quoted 5 lines · Robert P. J. Day

again, probably displaying my abject ignorance, but i wrote a
trivial module that tries to "var % 15", and i get:

WARNING: "__moddi3" undefined!

...which comes from libgcc1 which you obviously don't want to link against.

Does (var & 0x0f) not work for you?

Regards,

Signature · 1 line
Alex
#6 lore raw
Quoted 9 lines · Alexander Shishkin
Quoted 5 lines · Robert P. J. Day

again, probably displaying my abject ignorance, but i wrote a
trivial module that tries to "var % 15", and i get:

WARNING: "__moddi3" undefined!

...which comes from libgcc1 which you obviously don't want to link against.

Does (var & 0x0f) not work for you?

v & 0x0F <=> v % 16

Jan

#7 lore raw
Quoted 1 line · Jan Engelhardt

v & 0x0F <=> v % 16

Indeed. (Why would anyone want to mod/div by 15 anyway?). My bad.

Regards,

Signature · 1 line
Alex
#8 lore raw
Quoted 4 lines · Jan Engelhardt
Quoted 1 line

v & 0x0F <=> v % 16

Indeed. (Why would anyone want to mod/div by 15 anyway?). My bad.

Actually, it's the compiler's bad. That's a pretty fundamental equivalence that the compiler should recognize for native integral types.

DS

#9 lore raw
Quoted 5 lines · David Schwartz
Quoted 3 lines · Jan Engelhardt
Quoted 1 line

v & 0x0F <=> v % 16

Indeed. (Why would anyone want to mod/div by 15 anyway?). My bad.

Actually, it's the compiler's bad. That's a pretty fundamental equivalence that the compiler should recognize for native integral types.

for unsigned ones for sure yes... but the original question was about 15 not 16.