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.

c2000: question about __sat()



I have a question about the __sat() intrinsic as mentioned in SPRU514C.

The document just says it translates into "SAT ACC". Is this really all it does, to add a "SAT ACC" instruction at the end of whatever it encloses?

It seems like in order for the __sat() instruction to perform correctly, there needs to be a "ZAP  OVC" inserted by the compiler at the beginning of the outermost calculation, e.g.

  int16_t a = ...;
  int16_t b = ...;

  int32_t c = ...;
  int16_t d = ...;
  int16_t e = ...;

  c = __sat(c + (int32_t)a*b + (int32_t)d*f(e));

which a good compiler would turn into

  // assemble tmp = f(e);
  ZAP OVC
  // load c into accumulator
  // multiply a*b, add to accumulator
  // multiply d*tmp, add to accumulator
  SAT ACC
  // load accumulator into c

Does it do this? Or are there conditions under which __sat() will not reset the overflow counter properly and therefore yield an incorrect result?

  • The __sat intrinsic will only generate a SAT ACC instruction.  One issue is that the TI compiler can optimize the expression used as the argument to the intrinsic.  Thus, if the intrinsic were to reset the overflow counter the compiler could not guarantee that it would occur prior to any execution of the argument expression.

  • ThomasS said:

    The __sat intrinsic will only generate a SAT ACC instruction.  One issue is that the TI compiler can optimize the expression used as the argument to the intrinsic.  Thus, if the intrinsic were to reset the overflow counter the compiler could not guarantee that it would occur prior to any execution of the argument expression.

    then what's the point of the __sat() intrinsic? As a programmer, I cannot guarantee that the compiler does / does not do anything that is inconsistent with the use of the SAT ACC instruction.

  • The _sat intrinsic simply does not work the way you want.  Moreover, I don't see any way to achieve your goal from C.  I'm sorry.

    Thanks and regards,

    -George