emulating a 64 bit divide with 2 32 bit registers in ansi c 
Author Message
 emulating a 64 bit divide with 2 32 bit registers in ansi c

Hi there!
Does anyone know how to do a efficient and simple division of a 64 bit
integer datatype composed of two 32 bit integers by a 32 bit integer?
Every single example I found so far either uses assembler which i cannot
use or built in 64 bit datatypes which i can't utilize either :(

I really would appreciate help with that!

Greetings



Sun, 05 Sep 2004 03:48:20 GMT  
 emulating a 64 bit divide with 2 32 bit registers in ansi c


Quote:
> Hi there!
> Does anyone know how to do a efficient and simple division of a 64 bit
> integer datatype composed of two 32 bit integers by a 32 bit integer?
> Every single example I found so far either uses assembler which i cannot
> use or built in 64 bit datatypes which i can't utilize either :(

> I really would appreciate help with that!

Write code to emulate a single 64-bit register, than the division code
becomes easier [tip use the double and subtract method]

Tom



Sat, 04 Sep 2004 19:19:38 GMT  
 emulating a 64 bit divide with 2 32 bit registers in ansi c

Quote:



>>Hi there!
>>Does anyone know how to do a efficient and simple division of a 64 bit
>>integer datatype composed of two 32 bit integers by a 32 bit integer?
>>Every single example I found so far either uses assembler which i cannot
>>use or built in 64 bit datatypes which i can't utilize either :(

>>I really would appreciate help with that!

> Write code to emulate a single 64-bit register, than the division code
> becomes easier [tip use the double and subtract method]

> Tom

hm, what do you mean by "double" and "substract" method? if you're
referring to storing it in a double and then substracting it, that's no
option. i can only use pure integers :(


Sun, 05 Sep 2004 04:32:48 GMT  
 emulating a 64 bit divide with 2 32 bit registers in ansi c

Quote:



> >>Does anyone know how to do a efficient and simple division of a
> >>64 bit integer datatype composed of two 32 bit integers by a 32
> >>bit integer? Every single example I found so far either uses
> >>assembler which i cannot use or built in 64 bit datatypes which
> >>i can't utilize either :(

> >>I really would appreciate help with that!

> > Write code to emulate a single 64-bit register, than the division
> > code becomes easier [tip use the double and subtract method]

> hm, what do you mean by "double" and "substract" method? if you're
> referring to storing it in a double and then substracting it,
> that's no option. i can only use pure integers :(

Test the relative magnitudes of two 32 bit quantities.  If the
divisor is smaller than the quotient, set the dividend bit and
subtract, else reset the dividend bit.  Now double the dividend,
shifting in the high bit of the lower 32 bit portion, while
doubling that and inserting the dividend bit.  Count operations.

Provided you don't have overflow, this will generate a 32 bit
quotient with a 32 bit remainder.  

--

   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)



Sat, 04 Sep 2004 23:10:41 GMT  
 emulating a 64 bit divide with 2 32 bit registers in ansi c

Quote:




>>>>Does anyone know how to do a efficient and simple division of a
>>>>64 bit integer datatype composed of two 32 bit integers by a 32
>>>>bit integer? Every single example I found so far either uses
>>>>assembler which i cannot use or built in 64 bit datatypes which
>>>>i can't utilize either :(

>>>>I really would appreciate help with that!

>>>Write code to emulate a single 64-bit register, than the division
>>>code becomes easier [tip use the double and subtract method]

>>hm, what do you mean by "double" and "substract" method? if you're
>>referring to storing it in a double and then substracting it,
>>that's no option. i can only use pure integers :(

> Test the relative magnitudes of two 32 bit quantities.  If the
> divisor is smaller than the quotient, set the dividend bit and
> subtract, else reset the dividend bit.  Now double the dividend,
> shifting in the high bit of the lower 32 bit portion, while
> doubling that and inserting the dividend bit.  Count operations.

> Provided you don't have overflow, this will generate a 32 bit
> quotient with a 32 bit remainder.  

thanks :) already done, though with a 64 bit remainder.


Sun, 05 Sep 2004 08:35:49 GMT  
 emulating a 64 bit divide with 2 32 bit registers in ansi c

Quote:





> >>>>Does anyone know how to do a efficient and simple division of a
> >>>>64 bit integer datatype composed of two 32 bit integers by a 32
> >>>>bit integer? Every single example I found so far either uses
> >>>>assembler which i cannot use or built in 64 bit datatypes which
> >>>>i can't utilize either :(

> >>>>I really would appreciate help with that!

> >>>Write code to emulate a single 64-bit register, than the division
> >>>code becomes easier [tip use the double and subtract method]

> >>hm, what do you mean by "double" and "substract" method? if you're
> >>referring to storing it in a double and then substracting it,
> >>that's no option. i can only use pure integers :(

> > Test the relative magnitudes of two 32 bit quantities.  If the
> > divisor is smaller than the quotient, set the dividend bit and
> > subtract, else reset the dividend bit.  Now double the dividend,
> > shifting in the high bit of the lower 32 bit portion, while
> > doubling that and inserting the dividend bit.  Count operations.

> > Provided you don't have overflow, this will generate a 32 bit
> > quotient with a 32 bit remainder.

> thanks :) already done, though with a 64 bit remainder.

You can't get a 64 bit remainder with a 32 bit divisor.  The size
of the divisor is the only limiting factor, and it governs the
size of the adder needed.

--

   Available for consulting/temporary embedded and systems.
   (Remove "XXXX" from reply address. yahoo works unmodified)



Sun, 05 Sep 2004 00:43:22 GMT  
 emulating a 64 bit divide with 2 32 bit registers in ansi c

Quote:






>>>>>>Does anyone know how to do a efficient and simple division of a
>>>>>>64 bit integer datatype composed of two 32 bit integers by a 32
>>>>>>bit integer? Every single example I found so far either uses
>>>>>>assembler which i cannot use or built in 64 bit datatypes which
>>>>>>i can't utilize either :(

>>>>>>I really would appreciate help with that!

>>>>>Write code to emulate a single 64-bit register, than the division
>>>>>code becomes easier [tip use the double and subtract method]

>>>>hm, what do you mean by "double" and "substract" method? if you're
>>>>referring to storing it in a double and then substracting it,
>>>>that's no option. i can only use pure integers :(

>>>Test the relative magnitudes of two 32 bit quantities.  If the
>>>divisor is smaller than the quotient, set the dividend bit and
>>>subtract, else reset the dividend bit.  Now double the dividend,
>>>shifting in the high bit of the lower 32 bit portion, while
>>>doubling that and inserting the dividend bit.  Count operations.

>>>Provided you don't have overflow, this will generate a 32 bit
>>>quotient with a 32 bit remainder.

>>thanks :) already done, though with a 64 bit remainder.

> You can't get a 64 bit remainder with a 32 bit divisor.  The size
> of the divisor is the only limiting factor, and it governs the
> size of the adder needed.

hmm, i didn't make myself clear: the algorithm i use uses a fake 64 bit
remainder to do all the operations. In the end there is only a 32 bit
remainder left, of course :)

regards



Sun, 05 Sep 2004 09:48:40 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Looking for: multiply and divide of 32 bit integers (64 bit result)

2. top 32 bits of 64-bit product of two 32-bit integers

3. Help: porting 32-bit app to 64-bit Dec Alpha

4. 64-bit integer on a 32-bit machine

5. Calling 64 bit lib. from 32 bit program

6. converting signed 64 bit - 32 bit

7. 64 bit operation on 32 bit PC

8. 64-bit chips, 32-bit compatibility?

9. REQUEST: 64-bit integer math on 32-bit processor

10. Accessing 32-bit com componet from 64-bit application

11. 32-bit vs 64-bit

12. Tool 2 port 32 bit programms 2 64 bit

 

 
Powered by phpBB® Forum Software