1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-21 21:22:31 +03:00

Move .C to .CPP in the code (#5696)

Use g++ to compile core files to get additional C++ checks on the code.

Also move libb64 constants to PROGMEM, saving ~128 bytes of heap when used.
This commit is contained in:
Earle F. Philhower, III
2019-02-07 02:06:17 +00:00
committed by Develo
parent 24fa59df4b
commit f706c83b66
37 changed files with 390 additions and 190 deletions

60
cores/esp8266/sqrt32.cpp Normal file
View File

@ -0,0 +1,60 @@
#include <coredecls.h>
#include <stdint.h>
extern "C" {
uint32_t sqrt32 (uint32_t n)
{
// http://www.codecodex.com/wiki/Calculate_an_integer_square_root#C
// Another very fast algorithm donated by Tristan.Muntsinger@gmail.com
// (note: tested across the full 32 bits range, see comment below)
// 15 iterations (c=1<<15)
unsigned int c = 0x8000;
unsigned int g = 0x8000;
for(;;)
{
if (g*g > n)
g ^= c;
c >>= 1;
if (!c)
return g;
g |= c;
}
}
/*
* tested with:
*
#include <stdio.h>
#include <stdint.h>
#include <math.h>
int main (void)
{
for (uint32_t i = 0; ++i; )
{
uint32_t sr = sqrt32(i);
uint32_t ifsr = sqrt(i);
if (ifsr != sr)
printf("%d: i%d f%d\n", i, sr, ifsr);
if (!(i & 0xffffff))
{
printf("%i%% (0x%08x)\r", ((i >> 16) * 100) >> 16, i);
fflush(stdout);
}
}
printf("\n");
}
*
*/
};