royfengsss opened a new pull request, #10626:
URL: https://github.com/apache/nuttx/pull/10626

   ## 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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to