Keil uVision4 for 8051 slow in doiing float * float products. Why?

Discussion in 'Embedded Systems and Microcontrollers' started by beamrider, Dec 14, 2011.

  1. beamrider

    Thread Starter New Member

    Dec 14, 2011
    3
    0
    Keil uVision4 for 8051 slow in doing float * float products. Why?
    Maybe I miss a setting, an optimization. I do not know what to do to accelerate the calculations.

    I wanted to multiply two float numbers af=15343E-34 and bf=-23474E21. I noticed that Keil compiler generates assembly code that needs 271 Clock Cycles (on a Silab C8051F121, accelerated 8051) to generate the product.
    Now, if a do a trick and calculate separately the mantissa and exponent of af * bf, I need only 63 Clock Cycles (see the code), i.e. same result is obtained 4.3 times faster.
    (Multiplying two float numbers reduces to multiplying two signed integer mantissas and adding two signed integer exponents).

    I mention that I had the same problem with AVR Studio 4.18 for Atmel AVR 8 bit uControllers, floating point operation were incredible slow. Fortunately there was a fix for AVR. A library (libm.a) had to be added somewhere. With that libm.a the speed for float * float grew 14 times (see: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=114878 )

    I the case of Keil I do not know what to do, what settings to make to speed up calculations. Maybe you know and can help me.

    One thing is sure, 8051 is capable of multiplying float quantities at least 4 times faster than it does with the default configuration of Keil.

    Code ( (Unknown Language)):
    1.  
    2. #include <Si8250.H>                                  
    3. #include <stdio.h>              
    4. #include <math.h>
    5.  
    6. typedef unsigned char uint8_t;
    7. typedef char int8_t;
    8. typedef short int int16_t;
    9. typedef long int int32_t;
    10.  
    11. uint8_t i;
    12. volatile uint8_t q;
    13.  
    14. volatile int8_t ae8, be8;
    15. volatile int8_t se8;
    16.  
    17. volatile int16_t am16, bm16;
    18. volatile int32_t pm32;
    19.  
    20. volatile float af, bf;
    21. volatile long pf;
    22.  
    23. int main(void)
    24. {
    25.    ae8=-34;
    26.    be8=21;
    27.    am16=15343;
    28.    bm16=-23474;
    29.    af=15343E-34;
    30.    bf=-23474E21;
    31.    
    32.    for (i=1;i<5;i++)
    33.    {
    34.     pm32 = am16 * bm16; // Clock Cycles (CC) -> 567
    35.     se8 = ae8 + be8; // CC -> 624
    36.     pf = af * bf; // CC -> 630
    37.     q = 1; // CC -> 901
    38.    }
    39. return 1;
    40.  
    41. }
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    What speed do you get when using gcc porting to 8051? Or a different free/limited use compiler?

    If the other compilers also make faster code, submit a bug report to the vendor.
     
  3. beamrider

    Thread Starter New Member

    Dec 14, 2011
    3
    0
    Only somebody having direct experience with Keil and 8051 can answer my question.
    I do not believe Keil has such bugs because everybody talks about it with respect, in general.
    Likely it is a setting I miss, a library I do not have or something like this.
     
  4. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Thought I'd toss out that for an idea and to bump the thread for you so others with experience using Keil can help.
     
  5. MrChips

    Moderator

    Oct 2, 2009
    12,449
    3,365
    If you desire speed, don't use floating point.
     
  6. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,607
    Multiplying two float numbers is far more complicated then just multiplying two signed integer mantissas and adding two signed integer exponents
     
  7. beamrider

    Thread Starter New Member

    Dec 14, 2011
    3
    0
    Why far more!?

    af=15343E-34;
    bf=-23474E21;
    af*bf= -360161582E-13

    ae=-34; (exp of a)
    be=21;
    am=15343; (mantissa of a)
    bm=-23474;

    am*bm=-360161582
    ae+be=-13

     
  8. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    IF that is how your compiler breaks it down to asm.

    Otherwise it loads the floating point library and does everything the hard way to cover all possibilities.

    That's why I suggested a different compiler, maybe its library could be more efficient, or you could break it into integer math on your own as you are doing.
     
Loading...