Skip to content

Very bad FPU performance #2538

@portasynthinca3

Description

@portasynthinca3

Hardware:

Board: ESP-WROVER-32 board
Core Installation/update date: 03/mar/2019 (version 1.0.1)
IDE name: Arduino IDE
Flash Frequency: 80 MHz
PSRAM enabled: yes
Upload Speed: 921600
Computer OS: Windows 10

Description:

I've noticed a very bad performance of the FPU unit. The datasheet says it's only able to work with 32-bit floating point numbers. So, the "float" data type. I prepared a sketch below to see which will work faster: the FPU (using the "float" data type) or the CPU (using the "double" data type). I expect that the "float" data type operations will complete faster than the ones using "double". In reality, the complete opposite of this can be seen ("double" data type operations execute almost 2 times faster!). After searching for this problem on the Internet, I saw that this may be caused by the FPU startup procedure. So, I repeated the same code twice, but the difference has got even bigger!

Sketch

void setup() {
  Serial.begin(115200);
  
  float f = 2;
  uint32_t st_f = micros();
  for(uint64_t i = 0; i < 10000000; i++)
    f *= f * (double)f;
  Serial.println(f);
  Serial.println(String(micros() - st_f));
  
  double d = 2;
  uint32_t st_d = micros();
  for(uint64_t i = 0; i < 10000000; i++)
    d *= d * (double)d;
  Serial.println(d);
  Serial.println(String(micros() - st_d));

  Serial.println("---RETRY---");

  f = 2;
  st_f = micros();
  for(uint64_t i = 0; i < 10000000; i++)
    f *= f * (double)f;
  Serial.println(f);
  Serial.println(String(micros() - st_f));
  
  d = 2;
  st_d = micros();
  for(uint64_t i = 0; i < 10000000; i++)
    d *= d * (double)d;
  Serial.println(d);
  Serial.println(String(micros() - st_d));
}

void loop() {
}

Debug Messages:

inf
6925317
inf
4322672
---RETRY---
inf
7134875
inf
3987262

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions