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.

Compiler/TMS320F28379D: Saturated addition on C level

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software: TI C/C++ Compiler

Hello,
I have a question regarding the saturation function of the TMS320F28379. The saturation feature can be used by setting the OVM bit in the ST0 register. In an assembler source code this feature is easy to use.

But I want to use the saturated addition feature on a C source code level.

Does the controller have an intrinsic function to accomplish the saturated addition (or subtraction) on C level programming language.

Many thanks
Ralf

  • Hello Ralf,

    There isn't an intrinsic which do this.  In fixed point, I think most C2000 programmers would use the IQmath library, and handle the potential for overflow using the IQsat intrinsic.  If there is a potential for overflow, you would move the operands to a lower IQ format, perform the addition, saturate, then shift the result back to the format you need.  Attached is a page from the IQmath library user's guide which illustrates the technique.  IQmath is included in C2000Ware, under \libraries\math\IQmath.

    Regards,

    Richard

    IQsat.pdf

  • Dear Richard,
    many thanks for your response. I will check the possibilities of the IQmath lib.

    I have one additional question. Is it allowed to change the status of the OVM, SXM and PM-bits in the ST0 register (with an asm inline assembler instruction) or would this destroy the C runtime environment?

    Best regards
    Ralf

  • Dear Ralf,

    I would avoid manipulating these bits from the C environment. There is a cautionary note in the compiler user's guide about using inline assembly with C optimization (section 3.9.1). In my view it would be safer to write an external assembly routine, and to save and restore ST0 if you need to modify these flags.

    There are a couple of related posts on this topic:
    e2e.ti.com/.../245988
    e2e.ti.com/.../149342

    Regards,

    Richard