Skip to contentSkip to conversation

Broken asm/div64.h macro

DISCUSSION Troy Benjegerdes 6 participants 13 messages Jan 26, 2002 – Jan 29, 2002

lore
Share & tools
lore
#0 lore raw

Our div64.h macro is quite broken, and causes printk to not be able to do a long long format.

Is there a 'fast' generic C algorithm we can replace it with, instead of mucking with ASM?

--
Troy Benjegerdes | master of mispeeling | 'da hozer' | [email protected] -----"If this message isn't misspelled, I didn't write it" -- Me ----- "Why do musicians compose symphonies and poets write poems? They do it because life wouldn't have any meaning for them if they didn't. That's why I draw cartoons. It's my life." -- Charles Schulz

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#1 lore raw
Quoted 5 lines · Troy Benjegerdes

Our div64.h macro is quite broken, and causes printk to not be able to do a long long format.

Is there a 'fast' generic C algorithm we can replace it with, instead of mucking with ASM?

Usually you can copy the asm version from the gcc sources (libgcc).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#2 lore raw
In reply to Troy Benjegerdes
Quoted 6 lines · Troy Benjegerdes

Our div64.h macro is quite broken, and causes printk to not be able to do a long long format.

Is there a 'fast' generic C algorithm we can replace it with, instead of mucking with ASM?

If depends on what you want from do_div. If you guarantee that in do_div(n,base) base will be constant it's fairly easy (provided GCC does proper constant propagation). I also have the expanded code for 10 explicitly somewhere in prepboot, I just wrote it for fun for my own printb(==printk for bootloader). I also wrote a generic 64 by 32 divide for the x86 ROM BIOS emulator (stupid looping, slow but ok for this, I short-circuit it for 32/32 divides which are the most common).

On a somewhat relared topic, there is also an inverse estimator to use mulhwu somewhere in the time code (mulhwu_scale_factor IIRC what I wrote:-)), but it's deliberately compact and slow.

Which flavour would you prefer ? (The one in do_div is only for 64 bit targets, someone clearly goofed on that one).

Regards,
Gabriel.

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#3 lore raw
In reply to Troy Benjegerdes
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Troy" == Troy Benjegerdes <[email protected]> writes:

Troy> Our div64.h macro is quite broken, and causes printk to not be able to do Troy> a long long format.

Troy> Is there a 'fast' generic C algorithm we can replace it with, instead of Troy> mucking with ASM?

Hmm, I sent a patchlet to lkml with Subject: [PATCH] 64-bit divide tweaks.

Doesn't it work for you ?

Regards,
-velco

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#4 lore raw
Quoted 11 lines · Momchil Velikov
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Troy" == Troy Benjegerdes <[email protected]> writes:

Troy> Our div64.h macro is quite broken, and causes printk to not be able to do Troy> a long long format.

Troy> Is there a 'fast' generic C algorithm we can replace it with, instead of Troy> mucking with ASM?

Hmm, I sent a patchlet to lkml with Subject: [PATCH] 64-bit divide tweaks.

Doesn't it work for you ?

Didn't seee it..

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

--
Troy Benjegerdes | master of mispeeling | 'da hozer' | [email protected] -----"If this message isn't misspelled, I didn't write it" -- Me ----- "Why do musicians compose symphonies and poets write poems? They do it because life wouldn't have any meaning for them if they didn't. That's why I draw cartoons. It's my life." -- Charles Schulz

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#5 lore raw
Quoted 8 lines · Troy Benjegerdes

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

libgcc.a has those libraries.

Kaoru

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#6 lore raw
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Kaoru" == Kaoru Fukui <[email protected]> writes:

Quoted 8 lines · Troy Benjegerdes
Quoted 8 lines

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

Kaoru> libgcc.a has those libraries.

Yeah, but we don't link with libgcc.a. (which I forgot).

I'll do something along the lines of
#ifndef __HAVE_ARCH_DO_DIV
...
#endif

... soon.

Regards,
-velco

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#7 lore raw
Quoted 13 lines · Momchil Velikov
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

"Kaoru" == Kaoru Fukui <[email protected]> writes:

Quoted 8 lines · Troy Benjegerdes
Quoted 8 lines

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

Quoted 3 lines

Kaoru> libgcc.a has those libraries.

Yeah, but we don't link with libgcc.a. (which I forgot).

Er, but isn't it (sort-of) considered a bug if the kernel links with libgcc.a ? I think the consensious on l-k would be yes.

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#8 lore raw
Quoted 13 lines · Tom Rini
Quoted 12 lines · Momchil Velikov
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kaoru" == Kaoru Fukui <[email protected]> writes:

Quoted 8 lines · Troy Benjegerdes
Quoted 8 lines

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

Quoted 6 lines
Quoted 3 lines

Kaoru> libgcc.a has those libraries.

Yeah, but we don't link with libgcc.a. (which I forgot).

Er, but isn't it (sort-of) considered a bug if the kernel links with libgcc.a ? I think the consensious on l-k would be yes.

So you copy the code from the libgcc sources, cfr. arch/m68k/lib/.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#9 lore raw
Quoted 14 lines · Geert Uytterhoeven
Quoted 13 lines · Tom Rini
Quoted 12 lines · Momchil Velikov
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kaoru" == Kaoru Fukui <[email protected]> writes:

Quoted 8 lines · Troy Benjegerdes
Quoted 8 lines

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Kaoru> libgcc.a has those libraries.

Yeah, but we don't link with libgcc.a. (which I forgot).

Er, but isn't it (sort-of) considered a bug if the kernel links with libgcc.a ? I think the consensious on l-k would be yes.

So you copy the code from the libgcc sources, cfr. arch/m68k/lib/.

Or optimize that, yes. But linking directly is a no-no. :)

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#10 lore raw
Quoted 17 lines · Tom Rini
Quoted 16 lines · Geert Uytterhoeven
Quoted 15 lines · Tom Rini
Quoted 14 lines · Momchil Velikov
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kaoru" == Kaoru Fukui <[email protected]> writes:

Quoted 8 lines · Troy Benjegerdes
Quoted 8 lines

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

Kaoru> libgcc.a has those libraries.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Yeah, but we don't link with libgcc.a. (which I forgot).

Er, but isn't it (sort-of) considered a bug if the kernel links with libgcc.a ? I think the consensious on l-k would be yes.

So you copy the code from the libgcc sources, cfr. arch/m68k/lib/.

Or optimize that, yes. But linking directly is a no-no. :)

Yes,it's should has the source in the kernel.

However,the other archies(arm,cris,sh) use libgcc.a with static link.
Those makefiles have
LIBGCC := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)

If it's static link, it is same result isn't it?

Kaoru

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#11 lore raw
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

So you copy the code from the libgcc sources, cfr. arch/m68k/lib/.

Or optimize that, yes. But linking directly is a no-no. :)

Quoted 8 lines

Yes,it's should has the source in the kernel.

However,the other archies(arm,cris,sh) use libgcc.a with static link.
Those makefiles have
LIBGCC := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)

If it's static link, it is same result isn't it?

libgcc is a no-no.. it's big, and also encourages users to do silly things like long long divides and multiples in kernel fast-paths.

I posted a patch to linux-kernel (subject was 64 bit divides, or something), regarding a cleanup for the whole asm/div64.h macro mess.

--
Troy Benjegerdes | master of mispeeling | 'da hozer' | [email protected] -----"If this message isn't misspelled, I didn't write it" -- Me ----- "Why do musicians compose symphonies and poets write poems? They do it because life wouldn't have any meaning for them if they didn't. That's why I draw cartoons. It's my life." -- Charles Schulz

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/

#12 lore raw
In reply to Kaoru Fukui
Quoted 25 lines · Kaoru Fukui
Quoted 24 lines · Tom Rini
Quoted 22 lines · Geert Uytterhoeven
Quoted 13 lines · Tom Rini
Quoted 12 lines · Momchil Velikov
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Kaoru" == Kaoru Fukui <[email protected]> writes:

Quoted 8 lines · Troy Benjegerdes
Quoted 8 lines

Did you actually try compiling PPC this way??

vsprintf.o(.text+0x494): undefined reference to `__umoddi3' vsprintf.o(.text+0x494): relocation truncated to fit: R_PPC_REL24 __umoddi3
vsprintf.o(.text+0x4ac): undefined reference to `__udivdi3' vsprintf.o(.text+0x4ac): relocation truncated to fit: R_PPC_REL24 __udivdi3

Quoted 6 lines
Quoted 3 lines

Kaoru> libgcc.a has those libraries.

Yeah, but we don't link with libgcc.a. (which I forgot).

Er, but isn't it (sort-of) considered a bug if the kernel links with libgcc.a ? I think the consensious on l-k would be yes.

So you copy the code from the libgcc sources, cfr. arch/m68k/lib/.

Quoted 8 lines
Quoted 1 line

Or optimize that, yes. But linking directly is a no-no. :)

Yes,it's should has the source in the kernel.

However,the other archies(arm,cris,sh) use libgcc.a with static link.
Those makefiles have
LIBGCC := $(shell $(CC) $(CFLAGS) --print-libgcc-file-name)

ARM doesn't do this anymore, since it required having the correct target libgcc around. SH is planning on moving away from this in 2.5.x from what I understand.

Quoted 1 line

If it's static link, it is same result isn't it?

Sort of. It depends on a certain libgcc, which is bad.

--
Tom Rini (TR1265)
http://gate.crashing.org/~trini/

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/