|
From: Chip Eastham on 1 Feb 2010 09:43 On Jan 31, 1:23 pm, Jeffrey Walton <noloa...(a)gmail.com> wrote: > Hi All, > > I'm looking at some code that is seg faulting while attempting to > perform a divide using a 64 bit dividend and divisor. The code is > written without a native 64 bit word, so: > > struct MY_INT_64 > { > int32 high; // signed > uint32 low; // unsigned > > } > > The code is generalized using Knuth's algorithm from AOCP (Volume 2, > p. 273). I think the best way to proceed is to use a canned > implementation specialized for 32 bit word sizes rather than vet out > the problems with the generalized implementation. > > Does anyone have a C/C++ implementation for 64 bit division using two > 32 bit registers? I only need the quotient, but I'll take something > that computes both q and r. > > Thanks, > JW I'm a bit confused about the requirements. A C implementation might tell something about the operand sizes, but "using two 32 bit registers" is not something one would get out of a high-level language. Is it your desire to have a C (or C++) subroutine that uses inline assembler? If I understand your struct MY_INT_64, you are trying to implement your non-native 64 bit integer as a signed operand. If the divisor and dividend are both to be of this type, I think more than two 32 bit registers are needed since the dividend itself would take up that much room. [If I remember the Knuth material you are talking about, there is a proposed algorithm for refining from 32-bit to 64-bit quotients. Is that what you have in mind?] regards, chip
From: Michael Press on 2 Feb 2010 16:29 In article <6b91375f-78b1-440f-9ccb-d3212f9a7cbe(a)30g2000vbj.googlegroups.com>, Jeffrey Walton <noloader(a)gmail.com> wrote: > Hi All, > > I'm looking at some code that is seg faulting while attempting to > perform a divide using a 64 bit dividend and divisor. The code is > written without a native 64 bit word, so: > > struct MY_INT_64 > { > int32 high; // signed > uint32 low; // unsigned > } > > The code is generalized using Knuth's algorithm from AOCP (Volume 2, > p. 273). I think the best way to proceed is to use a canned > implementation specialized for 32 bit word sizes rather than vet out > the problems with the generalized implementation. > > Does anyone have a C/C++ implementation for 64 bit division using two > 32 bit registers? I only need the quotient, but I'll take something > that computes both q and r. Look for lldiv() in stdlib. It returns the remainder and quotient. -- Michael Press
From: Tim Little on 2 Feb 2010 19:26 On 2010-02-01, Jeffrey Walton <noloader(a)gmail.com> wrote: > I believe 'long long' makes an assumption that the size is 64 bits, According to the current C standard, "long long int" is guaranteed to have at least 64 value bits, and hence suffices. - Tim
First
|
Prev
|
Pages: 1 2 Prev: What makes a trivial operator trivial ? Next: May empty entire math departments |