This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

_sadd2 saturation result

Other Parts Discussed in Thread: OMAP-L138

Hi

I wan to use intrinsic function _sadd2,  see the addition result and saturation result. I tried to see the SSR register. but no change even saturated. sample code is below

int i, a, b, c;
a = 0x7fff7fff;
b = 0x6fff6fff;
for(i =0; i < 0xffff; i++)
{
       c = _sadd2(a, b);
       a = a + 0x10001000;

}

Pls let me know how to use _sadd2 function,

I am using OMAP-L138 Development Kit (LCDK) and code is for dsp core

Regards

vinod

  • Vinod,

    The _sadd2 intrinsic instructs the compiler to use the SADD2 instruction on the two source arguments that you have supplied (a & b) and returns the destination register's value as the output value of the intrinsic, in your case to the variable c.

    The full description of the operation of the SADD2 assembly instruction is described in the CPU & Instruction Set Reference Guide for the C674x. I will not copy it here since you can download and read that description along with all the other instructions that you may come across in the future.

    Your code does not make any sense to me. What do you expect to happen with it? You could delete the 'c=' assignment line and the code would not be affected; if you used the optimizer it would surely delete that line since the assignment is not used.

    What DSP function are you trying to accomplish? Or are you trying to learn how to write C code for the DSP?

    The two most helpful things I can think to offer are:

    1. Add printf("a,b,c = %d,%d,%d\n", c); inside your for-loop and see what happens.

    2. Better yet, use CCS to step through the loop and observe the variables.

    Regards,
    RandyP
  • Hi

    Thanks for reply.

    How to see the saturation in _sadd. I am executing step wise.

    I want to optimizing code,it involves addition ,multiplication, subtraction etc. For     a = 0x436771F2;      b = 0x5A2E51A3; _sadd should generate saturation condition, how to read staturation condition in c code (SSR register). Is SSR having address?. how to clear it?.

    thanks

    vinod

  • Vinod,

    I will not be able to fully explain the concepts and methods of the implementation of saturation for the math operations in the C674x core. You will need to study the sections in the DSP & CPU Instruction Set Reference Guide that describe it, how to clear it, how to set it in instructions, and so on. And you can look in the C/C++ Compiler User Guide to see how to access SSR in C code (search the pdf for SSR).

    Each math instruction's description in the CPU Instruction Set guide says whether it does saturation or not. It seems like most do, but some do not, mainly to make it easier for implementation of the C/C++ languages which do not natively comprehend saturation.

    Can you see the SAT bit and SSR register values being set and/or cleared in your CCS debugger window?

    For optimizing your code, you will probably come out faster by increasing the size of your math operations and variables so you can see final overflow at the end and handle it simply in C code. But there will be ways to do it using saturation after a lot of digging into it. I am sorry that I cannot give you code to do what you want - I do not have it.

    There may be some other users who have excellent advice in a simpler way than reading the manuals. Maybe one or two of them will join your thread.

    Regards,
    RandyP