Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esp32: Use newlib-esp32 #10626

Merged
merged 1 commit into from Sep 14, 2023
Merged

Conversation

royfengsss
Copy link
Contributor

Summary

When we are using newlib as libm, we can consider newlib-esp32 for esp32 hardware. An it contains some optimizations for esp32 hardware. Besides this change, two small issues has been fixed.

  1. add the tar ball to .gitignore
  2. Fix the some build warnings

Impact

Using a seperated config option to switch and default is n. So no impact to normal case.
For enable newlib-esp32 case, it has a little performance improvement for float calculation.

Testing

Write a piece of simple test code and update example/hello app as below:

int main(int argc, FAR char *argv[])
{
  struct timespec ts0;
  struct timespec ts1;
  uint64_t elapsed;
  char *endp;
  long n = 10000;
  double number = 0.0;
  double sum = 0.0;
  double result;

  printf("Hello, World!!\n");
  if (argc == 2)
  {
    n = (int)strtol(argv[1], &endp, 10);
    if (argv[1] == endp)
    {
      printf("invalid parameter!\n");
      exit(-1);
    }
  }
  srand(time(0));
  clock_gettime(CLOCK_REALTIME, &ts0);
  for (int i = 1; i <= n; i++) 
  {
    number = (double)(rand() % 9000001 + 1000000) + (double)(rand() % 10001) / 10000.0;
    sum += 1.0 / sqrt(number); 
  }
  result = sum / (double)n;
  clock_gettime(CLOCK_REALTIME, &ts1);

  elapsed  = (((uint64_t)ts1.tv_sec * NSEC_PER_SEC) + ts1.tv_nsec);
  elapsed -= (((uint64_t)ts0.tv_sec * NSEC_PER_SEC) + ts0.tv_nsec);
  elapsed /= NSEC_PER_MSEC; /* msec */

  printf("The %ld round result is %.7f\n", n, result); 
  printf("it took %" PRIu64 " msec\n", elapsed);
  return 0;
}

Use esp32-devkitc:nsh config and enable below options

CONFIG_LIBM_NEWLIB=y
CONFIG_LIBM_USE_NEWLIB_ESP32=y

Here is the test result:
For the case of using default newlib (sourceware.org)

nsh> hello
Hello, World!!
The 10000 round result is 0.0004855
it took 180 msec
nsh> hello 100000
Hello, World!!
The 100000 round result is 0.0004858
it took 1820 msec
nsh> hello 1000000
Hello, World!!
The 1000000 round result is 0.0005035
it took 18190 msec
nsh> hello
Hello, World!!
The 10000 round result is 0.0004856
it took 180 msec
nsh> hello 100000
Hello, World!!
The 100000 round result is 0.0004858
it took 1820 msec
nsh> hello 1000000
Hello, World!!
The 1000000 round result is 0.0004858
it took 18190 msec
nsh> 

For the case of using newlib-esp32:

nsh> hello
Hello, World!!
The 10000 round result is 0.0004854
it took 170 msec
nsh> hello 100000
Hello, World!!
The 100000 round result is 0.0004858
it took 1750 msec
nsh> hello 1000000
Hello, World!!
The 1000000 round result is 0.0004858
it took 17470 msec
nsh> hello 
Hello, World!!
The 10000 round result is 0.0004848
it took 180 msec
nsh> hello 100000
Hello, World!!
The 100000 round result is 0.0005035
it took 1750 msec
nsh> hello 1000000
Hello, World!!
The 1000000 round result is 0.0004858
it took 17470 msec
nsh> 

We can see the newlib-esp32 case is a little better in performance than the default.

When we are using newlib as libm, we can consider newlib-esp32 for esp32
hardware. An it contains some optimization for esp32 hardware.
Besides, two small issues has been fixed.
1. add the tar ball to .gitignore
2. Fix the some build warnings
@xiaoxiang781216 xiaoxiang781216 merged commit e90d58c into apache:master Sep 14, 2023
25 of 26 checks passed
@royfengsss royfengsss deleted the use-newlib-esp32 branch September 15, 2023 00:57
@jerpelea jerpelea added this to To-Add in Release Notes - 12.3.0 Sep 26, 2023
@jerpelea jerpelea moved this from To-Add to done in Release Notes - 12.3.0 Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants