Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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

Status
Not open for further replies.

tempos

Member level 2
Joined
Aug 23, 2010
Messages
42
Helped
7
Reputation
14
Reaction score
7
Trophy points
1,288
Activity points
1,657
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: View topic - AVR Studio compiler generates slow assembler code :: AVR Freaks )

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:
#include <Si8250.H>                                   
#include <stdio.h>               
#include <math.h> 

typedef unsigned char uint8_t;
typedef char int8_t;
typedef short int int16_t;
typedef long int int32_t;

uint8_t i;
volatile uint8_t q;

volatile int8_t ae8, be8;
volatile int8_t se8;

volatile int16_t am16, bm16;
volatile int32_t pm32;

volatile float af, bf;
volatile long pf;

int main(void)
{
   ae8=-34;
   be8=21;
   am16=15343;
   bm16=-23474;
   af=15343E-34;
   bf=-23474E21;
   
   for (i=1;i<5;i++)
   {
    pm32 = am16 * bm16; // Clock Cycles (CC) -> 567
    se8 = ae8 + be8; // CC -> 624
    pf = af * bf; // CC -> 630
    q = 1; // CC -> 901
   }
return 1;

}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top