Hi,

If I want to build a VDSP project that all the arithmetic operations inside will be saturated (-1 – 0.99) and not overflowed (two’s complement). Can and How it be done?

Please note that I don’t mean by putting (s) near each arithmetic operation. What I looking for is something in the project options that will do it automatically for all arithmetic operations.

Thanks,

Daniel

Hi Daniel,

There is no need for such an option since any built-in operators for the type fract16, fract2x16 and fract32 use saturating arithmetic by default:

#include <fract_math.h>

fract16 sum_16 (fract16 x, fract16 y)

{

return add_fr1x16 (x, y); // the compiler will generate an instruction of the form R0.H = R1.L + R0.L (S);

}

The same applies to any of the fractional DSP library functions as well as the embedded C type – they too use saturating arithmetic.

Thus the only time you will need to explicitly specify saturation is when writing your own assembly code.

Please note that if you re-write the above example using integer arithmetic, no saturation will be used (the standard behavior for integral C types):

short sum_16 (short x, short y)

{

return (x+ y); // R0.H = R1.L + R0.L (NS); will be generated

}

Best Regards,

Andreas