Skip to contentSkip to conversation

64 bit arithmetic?

DISCUSSION Colin D Bennett 2 participants 3 messages Jun 10, 2008 – Jun 11, 2008

lore
Share & tools
lore
#0 lore raw

I'm working on implementing a higher resolution timer using the x86 TSC. However, this entails 64-bit arithmetic since on a 2GHz machine it will overflow a 32-bit number every couple of seconds (the TSC counter CPU cycles since boot).

So to convert the TSC value into a value in milliseconds, I need to do 64-bit division, but when I try to build GRUB now, I get

undefined reference to `__udivdi3'

Is this expected? Should it be possible for me to do division on grub_uint64_t types?

BTW, I'm trying to add it to the kernel image, if this makes a difference.

Thanks,
Colin

#1 lore raw
Quoted 8 lines · Colin D Bennett

I'm working on implementing a higher resolution timer using the x86 TSC. However, this entails 64-bit arithmetic since on a 2GHz machine it will overflow a 32-bit number every couple of seconds (the TSC counter CPU cycles since boot).

So to convert the TSC value into a value in milliseconds, I need to do 64-bit division, but when I try to build GRUB now, I get

Quoted 7 lines

undefined reference to `__udivdi3'

Is this expected? Should it be possible for me to do division on grub_uint64_t types?

BTW, I'm trying to add it to the kernel image, if this makes a difference.

Hi.

You can use grub_divmod64, which is defined in kern/misc.c

Signature · 1 line
Bean
#2 lore raw
Quoted 15 lines · On Wed, 11 Jun 2008 00:54:35 +0800 Bean <[email protected]> wrote:
Quoted 13 lines · Colin D Bennett

I'm working on implementing a higher resolution timer using the x86 TSC. However, this entails 64-bit arithmetic since on a 2GHz machine it will overflow a 32-bit number every couple of seconds (the TSC counter CPU cycles since boot).

So to convert the TSC value into a value in milliseconds, I need to do 64-bit division, but when I try to build GRUB now, I get

undefined reference to `__udivdi3'

Is this expected? Should it be possible for me to do division on grub_uint64_t types?

Quoted 6 lines
Quoted 2 lines

BTW, I'm trying to add it to the kernel image, if this makes a difference.

Hi.

You can use grub_divmod64, which is defined in kern/misc.c

Thanks! That works perfectly.