This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C Library Stack Usage: AC6 vs AC5

Noticed particularly the stack usage difference of a function _printf_f between ARM Compiler 6 (tested with 6.11) and ARMCC 5.06 (update 6) is a whopping 6x more on the AC6 (1968 bytes on AC6 vs 320 bytes on AC5), as reported by the linker static analysis.

Any reason why AC6 uses more stack in this case?

Appreciate any thoughts on this.

ST

Parents
  • Hi Milorad,

    Just had the time to go back to this subject.

    I got rid of all my floating point string formatting in sprintf and snprintf while replacing it with function below:

     static void printf_float (const char * s, uint8_t decimal, float value)
    {
     char *tmpSign = (value < 0) ? "-" : " ";
     float tmpVal = (value < 0) ? -value : value;
    
     int tmpInt1 = tmpVal;                  // typecast
     float tmpFrac = tmpVal - tmpInt1;      // Get fraction
    
    //determine number of digits used by tmpInt1
     uint8_t sigDigits = fminf(6,trunc(log10f(fmaxf(1,fabsf(tmpInt1))))+1);
    
     int tempGain = powf(10,decimal);             //
    
     //limit decimal
     decimal = fminf(decimal,fmaxf(0,5-sigDigits));
    
    
     int tmpInt2 = trunc(tmpFrac * tempGain);  // Turn into integer.
    
    //Print to string
    if (decimal>0)
            snprintf(lcd_str_large,STRBUFFSIZE,"%s%s%-*d.%-*d",s,tmpSign,sigDigits,tmpInt1,decimal,tmpInt2);
    else //rpint significant numbers only
            snprintf(lcd_str_large,STRBUFFSIZE,"%s%s%-5d",s,tmpSign,tmpInt1);
    }
    

    _printf_f wasn't linked in the the final output and stack usage was reduced significantly by slashing almost 2000 bytes to the AC5 level!

    Though I am still not sure whats really the difference but definitely something in the library.

    Regards,
    Seng Tak

Reply
  • Hi Milorad,

    Just had the time to go back to this subject.

    I got rid of all my floating point string formatting in sprintf and snprintf while replacing it with function below:

     static void printf_float (const char * s, uint8_t decimal, float value)
    {
     char *tmpSign = (value < 0) ? "-" : " ";
     float tmpVal = (value < 0) ? -value : value;
    
     int tmpInt1 = tmpVal;                  // typecast
     float tmpFrac = tmpVal - tmpInt1;      // Get fraction
    
    //determine number of digits used by tmpInt1
     uint8_t sigDigits = fminf(6,trunc(log10f(fmaxf(1,fabsf(tmpInt1))))+1);
    
     int tempGain = powf(10,decimal);             //
    
     //limit decimal
     decimal = fminf(decimal,fmaxf(0,5-sigDigits));
    
    
     int tmpInt2 = trunc(tmpFrac * tempGain);  // Turn into integer.
    
    //Print to string
    if (decimal>0)
            snprintf(lcd_str_large,STRBUFFSIZE,"%s%s%-*d.%-*d",s,tmpSign,sigDigits,tmpInt1,decimal,tmpInt2);
    else //rpint significant numbers only
            snprintf(lcd_str_large,STRBUFFSIZE,"%s%s%-5d",s,tmpSign,tmpInt1);
    }
    

    _printf_f wasn't linked in the the final output and stack usage was reduced significantly by slashing almost 2000 bytes to the AC5 level!

    Though I am still not sure whats really the difference but definitely something in the library.

    Regards,
    Seng Tak

Children