SPRUJG0B December   2024  – November 2025 F29H850TU , F29H859TU-Q1

 

  1.   1
  2.   Abstract
  3.   Trademarks
  4. 1Introduction
  5. 2Performance Optimization
    1. 2.1 Compiler Settings
      1. 2.1.1 Enabling Debug and Source Inter-Listing
      2. 2.1.2 Optimization Control
      3. 2.1.3 Floating-Point Math
      4. 2.1.4 Fixed-Point Division
      5. 2.1.5 Single vs Double Precision Floating-Point
      6. 2.1.6 Link-Time Optimization (LTO)
    2. 2.2 Memory Settings
      1. 2.2.1 Executing Code From RAM
      2. 2.2.2 Executing Code From Flash
      3. 2.2.3 Data Placement
    3. 2.3 Code Construction and Configuration
      1. 2.3.1 Inlining
      2. 2.3.2 Intrinsics
      3. 2.3.3 Volatile Variables
      4. 2.3.4 Function Arguments
      5. 2.3.5 Enabling Wider Data Accesses
      6. 2.3.6 Auto Code-Generation Tools
      7. 2.3.7 Accurately Profiling Code
    4. 2.4 Application Code Optimization
      1. 2.4.1 Optimized SDK Libraries
      2. 2.4.2 Optimizing Code-Size With Libraries
      3. 2.4.3 C29 Special Instructions
      4. 2.4.4 C29 Parallelism
      5. 2.4.5 32-Bit Variables and Writes Preferred
      6. 2.4.6 Coding Style and Impact on Performance
  6. 3References
  7. 4Revision History

C29 Special Instructions

C29 supports a number of instructions that find use in optimizing specific types of functions. Key examples are listed below:

  • SVGEN - space vector generation can be optimized with the QUADF instruction, leveraged using the intrinsic 'float __builtin_c29_quadf32(unsigned int * tdm_w_uip0, float * rw_fp1, float * rw_fp2)'.
    Note: Optimized implementations of the SVGEN (including those that can be applied to a 3-level inverter) are planned in the F29x Motor Control SDK.
  • CRC - Cyclic Redundancy Check implementations can be optimized with the CRC instruction. Examples are provided in the F29x SDK. An intrinsic is also available 'unsigned int __builtin_c29_i32_crc(unsigned int ui0, unsigned int ui1, unsigned int ui2, unsigned int ui3)'.
  • Limiting (Saturation) operations - can be optimized using the MINMAXF instruction.
    • The compiler generates the MINMAXF instruction and an optimal implementation if the C code is written using the ternary operator, if min and max are constants, and the code is compiled with -O3 and -ffast-math options. This implementation is the fastest as it involves 2 MV instructions in parallel, followed by the MINMAXF instruction. If min and max are constants, but only -O3 is used, MINMAXF is not generated, instead CMPF and SELECT instruction pairs are generated. If min and max are not constant, with -O3 and -ffast-math options, the compiler generates LDs to read from memory, CMPF, SELECT, and MAXF.
      float saturation(float in)
      { 
         float out; 
         out = (in > max)? max:((in < min)? min:in); 
         return out;
      }
    • With if.else conditionals and either of the implementations below, the behavior is exactly the same as above.
      float saturation(float in)
      {
         float out;
         if(in > max) 
         { 
            out = max; 
         } else if(in < min) 
         { 
            out = min; 
         } else { 
            out = in; 
         }
         return out;
      }
      float saturation(float in)
      {
         float out = in;
         if(in > max) 
         { 
            out = max; 
         } else if(in < min) 
         { 
            out = min; 
         }
         return out;
      }
      float saturation(float in)
      {
         float out = in;
         if(in > max) 
         { 
            out = max; 
         } 
         if(in < min) 
         { 
            out = min; 
         }
         return out;
      }
  • Deadzone operations - the compiler generates the most efficient code when min and max are constants, with the -O3 option, and with the C code written using either the ternary operator or if..else as shown in the code blocks below.
    float deadzone(float in)
    {
       float out; 
       out = (in>1.0f)?(in-1.0f):((in>-1.0f)?0.0f:(in+1.0f));
       return out;
    }
    float deadzone(float in)
    {
        float out;
        if(in >1.0f)
        { 
            out = in-1.0f; 
        } else if(in >-1.0f){ 
            out =0.0f; 
        } else { 
            out = in+1.0f; 
        }
        return out;
    }