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/TMS320F280049: Min Max instructions from C

Part Number: TMS320F280049
Other Parts Discussed in Thread: C2000WARE

Tool/software: TI C/C++ Compiler

So, i do know we used to advise customers to do the following 

But i have noticed that this is no longer true, I am unable to generate this optimized code. 

I am using compiler version 18.1.3.LTS , I tested this with the example in C2000Ware, by just adding the following in the code...

volatile float val1=0.2;
volatile float val2=0.5;
volatile float val3=0.5;

 val1=(val1>val2)?val2:val1;

but i cannot get the assembler to generate the min and the max instructions for me, i have optimizations turned on at level 2 and level 3, 

Can you advise, if the above still is true? and second what is the necessary and sufficient condition to make use of this. 

 

  • I would not expect to see any difference between if or ?: .  If I remove volatile from your example, I get MINF32.

    All that said, I do suspect something has gone wrong.  I presume there is some source code either from C2000Ware, or a customer, that got MINF32 or MAXF32 with an older compiler, and does not get those instructions with version 18.1.x.LTS.  For the file which contains that source code, please submit a test case as described in the article How to Submit a Compiler Test Case.  Indicate which function(s) have the problem.

    Thanks and regards,

    -George

  • George,

    Is there a reason the voltaile should not generate MIN MAX instructions?

    I went back on some of my code, with compiler v5.1 but i still saw volatile not generating MIN MAX, So I am not sure if this is a enhancement request then ?
  • The keyword volatile means the memory location may change at any time, not just when code generated by the compiler changes it.  Consider interrupts, peripherals, and the like.  Thus volatile means a variable cannot be allocated to a register.  So it inhibits lots of optimization.  Generally speaking, do not expect much in the way of optimization in the presence of volatile.

    Thanks and regards,

    -George

  • George, so for volatile variables, the compiler will never use instructions that operate on registers? and only direct memory?
  • If a variable is volatile, the compiler always allocates that variable to memory, and never a register.  If, for the desired operation, the only instruction available does not support memory operands, then the volatile variable is loaded into a register.  But only for as long as needed for the operation, and no longer.

    Thanks and regards,

    -George