DSPRelated.com
Forums

Addition Algorithm

Started by Gie78 November 27, 2008
Hi all,

My DSP does not support a 64bit + 64bit = 64bit addition, it only supports
a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition.

Does anybody know a fast and smart algorithm to compute a 64bit + 64bit =
64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) +
32bit(High) 32bit(low) = 32bit(High) 32bit(low).

Best Regards,

Gie78


On Thu, 27 Nov 2008 16:29:59 -0600, "Gie78"
<Markus.Schweikhardt@web.de> wrote:

>Hi all, > >My DSP does not support a 64bit + 64bit = 64bit addition, it only supports >a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition. > >Does anybody know a fast and smart algorithm to compute a 64bit + 64bit = >64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + >32bit(High) 32bit(low) = 32bit(High) 32bit(low).
To do what you want, you have to add the carry bit out of the first 32 bit addition to the second 32 bit addition as a third input. If you have an ADDC (add with carry) instruction you can just say: ADD R5, R1, R3 ADDC R6, R2, R4 assuming Rx are 32 bit registers and R2, R1 has the first 64 bit value (with R2 having the high word) and same for R4, R3; The result goes to R6, R5. If you don't have an ADDC instruction you have to implement it yourself ie MOV R7, 0 ADD R5, R1, R3 JNC NEXT MOV R7, 1 NEXT: ADD R6, R2, R4 ADD R6, R6, R7 HTH Muzaffer Kal DSPIA INC. ASIC/FPGA Design Services http://www.dspia.com
On Nov 27, 5:29&#4294967295;pm, "Gie78" <Markus.Schweikha...@web.de> wrote:
> Hi all, > > My DSP does not support a 64bit + 64bit = 64bit addition, it only supports > a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition. > > Does anybody know a fast and smart algorithm to compute a 64bit + 64bit = > 64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + > 32bit(High) 32bit(low) = 32bit(High) 32bit(low). > > Best Regards, > > Gie78
It should be straightforward if you have an "add with carry" instruction. Look up "extended precision arithmetic". John

Gie78 wrote:

> Hi all, > > My DSP does not support a 64bit + 64bit = 64bit addition, it only supports > a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition.
It is not your DSP. It is the DSP of Analog Devices.
> Does anybody know a fast and smart algorithm to compute a 64bit + 64bit = > 64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + > 32bit(High) 32bit(low) = 32bit(High) 32bit(low).
Everybody knows. This algorithm is taught in the 2nd grade of the elementary school. VLV
Gie78 wrote:
> Hi all, > > My DSP does not support a 64bit + 64bit = 64bit addition, it only supports > a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition. > > Does anybody know a fast and smart algorithm to compute a 64bit + 64bit = > 64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + > 32bit(High) 32bit(low) = 32bit(High) 32bit(low). > > Best Regards,
Does your processor have a carry bit that you can access? (High-level languages don't provide direct access to the processor flags. This will have to be done in assembly language.) If it does, search for information on performing double-precision arithmetic. (My old Z-80 manual has it.) Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Gie78 wrote:
> Hi all, > > My DSP does not support a 64bit + 64bit = 64bit addition, it only supports > a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition.
I have a vague idea what DSP you're talking about.. It came with a C-compiler that can't do 64 bit math, right? And it does not has a carry-flag either.. In this case you can do the addition using two 32 bit adds, one 40 bit add and a shift. In this pseudo-code I assume int is 32 bit and long is 40 bit: typedef struct { unsigned int low; unsigned int high; } int64; int64 add (int64 a, int64 b) { int64 result; // do the low 32 bit addition with 40 bits, // so we preserve the overflow (carry) unsigned long temp = a.low; temp += b.low; // store lower 32 bit (truncates the upper 8 bits) result.low = temp; // do the high 32 bit addition: result.high = a.high + b.high; // add carry result.high += (temp>>32); return result; } In practice you don't want to pass structures around like this. Cheers, Nils
>Hi all, > >My DSP does not support a 64bit + 64bit = 64bit addition, it only
supports
>a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition. > >Does anybody know a fast and smart algorithm to compute a 64bit + 64bit
=
>64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + >32bit(High) 32bit(low) = 32bit(High) 32bit(low).
Are you really trying to tell us that you are doing DSP work, and don't understand the basic addition process a 6 year old learns in primary school? :-\ Surely anyone with the most basic education should be able to look at the instruction set of a processor, and understand why they have those "add with carry" instructions. Steve
steveu wrote:

   ...

> Are you really trying to tell us that you are doing DSP work, and don't > understand the basic addition process a 6 year old learns in primary > school? :-\
I thought that most curricula don't get to addition with carry until age seven. ... Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Thu, 27 Nov 2008 17:18:30 -0600, Vladimir Vassilevsky wrote:

> Gie78 wrote: > >> Hi all, >> >> My DSP does not support a 64bit + 64bit = 64bit addition, it only >> supports a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition. > > It is not your DSP. It is the DSP of Analog Devices. > >> Does anybody know a fast and smart algorithm to compute a 64bit + 64bit >> = 64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + >> 32bit(High) 32bit(low) = 32bit(High) 32bit(low). > > Everybody knows. This algorithm is taught in the 2nd grade of the > elementary school. > > > VLV
It's just that it's in the context of base ten, and they don't tell you that you'll be able to apply it to DSP problems. -- Tim Wescott Control systems and communications consulting http://www.wescottdesign.com Need to learn how to apply control theory in your embedded system? "Applied Control Theory for Embedded Systems" by Tim Wescott Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html
>On Thu, 27 Nov 2008 17:18:30 -0600, Vladimir Vassilevsky wrote: > >> Gie78 wrote: >> >>> Hi all, >>> >>> My DSP does not support a 64bit + 64bit = 64bit addition, it only >>> supports a 32bit + 32bit = 32bit or a 32bit + 40bit = 40bit addition. >> >> It is not your DSP. It is the DSP of Analog Devices. >> >>> Does anybody know a fast and smart algorithm to compute a 64bit +
64bit
>>> = 64bit addition using 32bit values. e.g. 32bit(High) 32bit(low) + >>> 32bit(High) 32bit(low) = 32bit(High) 32bit(low). >> >> Everybody knows. This algorithm is taught in the 2nd grade of the >> elementary school. >> >> >> VLV > > >-- >Tim Wescott >Control systems and communications consulting >http://www.wescottdesign.com > >Need to learn how to apply control theory in your embedded system? >"Applied Control Theory for Embedded Systems" by Tim Wescott >Elsevier/Newnes, http://www.wescottdesign.com/actfes/actfes.html >
First of all thanks for the quick responds. And for those who were talking about the primary school age. I have just started in the kindergarten. - Gie