emulating a 64 bit divide with 2 32 bit registers in ansi c
Author 
Message 
kalle kur #1 / 7

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 


Tom St Deni #2 / 7

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 64bit register, than the division code becomes easier [tip use the double and subtract method] Tom

Sat, 04 Sep 2004 19:19:38 GMT 


kalle kur #3 / 7

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 64bit 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 


CBFalcone #4 / 7

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 64bit 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 


kalle kur #5 / 7

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 64bit 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 


CBFalcone #6 / 7

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 64bit 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 


kalle kur #7 / 7

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 64bit 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 


