Question asked by bookevg on May 16, 2013
Latest reply on May 20, 2013 by bookevg

So I use VDSP++ C++ and must to use fixed point.

I use the builtin function: set_saturate_mode().

I try why do I need to use set_saturate_mode().

I'm using

int a1,a2,b;

b = 0x80000000;

a1 = __builtin_abs(b);     // a1 = 0x80000000 - invalid result

set_saturate_mode();

a2 = __builtin_abs(b);     // a2 = 0x7FFFFFFF - correct result

------------------------------------------------------

// Correct using set_saturate_mode():

set_saturate_mode();

int a, b, c;

a     = 0x3fff;

b     = 0x4fff;

c     = a+ b;     // c = 0x7FFFFFFF;

------------------------------------------------------

// Invalid using set_saturate_mode() and __builtin_sat_add

set_saturate_mode();

int a, b, c;

a     = 0x3fff;

b     = 0x4fff;

c     = __builtin_sat_add(a, b);     // c = 0x80000000;

It's because the code c = __builtin_sat_add(a, b) is

r8     = r15 + r0;                              // r8     = 0x7FFFFFFF and AV     = 1

if av r8     = ashift r8 by 0xFFFFFFE1;         // r8     = 0x00000000

if av r8     = btgl   r8 by 0x1F;               // r8     = 0x80000000

------------------------------------------------------

If we want using the same time set_saturate_mode() and __builtin_sat_add VDSP++ must generate the next code:

set_saturate_mode();

int a, b, c;

a     = 0x3fff;

b     = 0x4fff;

c     = __builtin_sat_add(a, b);     // c = 0x80000000;

It's because the code c = __builtin_sat_add(a, b) is

r8     = r15 + r0;                              // r8     = 0x7FFFFFFF and AV     = 1

if av r8     = ashift r8 by 0xFFFFFFE1;         // r8     = 0x00000000

if av r8     = btgl   r8 by 0x1F;               // r8     = 0x80000000

------------------------------------------------------

So it's danger to use set_saturate_mode(). Especialy if you want to use the native support of fixed point in C.

I think we must migrate to CCES when the native support of fixed point in C++ exist and all of VDSP++'s interrupt handlers are support in CCES. At this moment CCES don't support all types of VDSP++'s interrupt handlers. The support is from this forum? but it's not official release.

Or ADI must add the native support of fixed point in C++ to VDSP++