Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By cal
#19457
pvvx wrote:
cal wrote:BTW: Any reason you disabled -Os and use -O2 on your code?
-Os = Big size :)
gcc curve compiler. GCC ESP8266 does not use a offset by reference to variable and creates a lot of downloadable constants in 'text' section. + No optimization (associations) of these constants... gcc curve compiler...

I don't know what you mean by "curve compiler" but just saying "-Os" results in big size
is wrong. Applying it to the nodemcu code base gained 15k.
I can can imagine that it depends on the type of c code you have.
Small functions may actually loose and bigger ones win.
User avatar
By pvvx
#19502
Code: Select allvoid test(void)
{
   unsigned int *ptr = (unsigned int *)0x60001100;
   ptr[0] = 0;
   ptr[1] = 1;
   ptr[2] = 2;
   ptr[3] = 3;
   ptr[4] = 4;
   ptr[5] = 5;
   ptr[6] = 6;
   ptr[7] = 7;
   ptr[8] = 8;
}

gcc:
Code: Select alldword_40100030  .int 0x60001100
dword_40100034  .int 0x60001104
dword_40100038  .int 0x60001108
dword_4010003C  .int 0x6000110C
dword_40100040  .int 0x60001110
dword_40100044  .int 0x60001114
dword_40100048  .int 0x60001118
dword_4010004C  .int 0x6000111C
dword_40100050  .int 0x60001120
test:                         
                l32r            a2, dword_40100030
                movi.n          a3, 0
                s32i.n          a3, a2, 0
                l32r            a2, dword_40100034
                movi.n          a3, 1
                s32i.n          a3, a2, 0
                l32r            a2, dword_40100038
                movi.n          a3, 2
                s32i.n          a3, a2, 0
                l32r            a2, dword_4010003C
                movi.n          a3, 3
                s32i.n          a3, a2, 0
                l32r            a2, dword_40100040
                movi.n          a3, 4
                s32i.n          a3, a2, 0
                l32r            a2, dword_40100044
                movi.n          a3, 5
                s32i.n          a3, a2, 0
                l32r            a2, dword_40100048
                movi.n          a3, 6
                s32i.n          a3, a2, 0
                l32r            a2, dword_4010004C
                movi.n          a3, 7
                s32i.n          a3, a2, 0
                l32r            a2, dword_40100050
                movi.n          a3, 8
                s32i.n          a3, a2, 0
                ret.n

Low speed, big code. Is especially relevant in the drivers.

xtensa:
Code: Select alldword_40100070  .int 0x60001100         
test:                                   
                movi.n          a2, 8
                movi.n          a4, 7
                movi.n          a5, 6
                movi.n          a6, 5
                movi.n          a7, 4
                movi.n          a8, 3
                movi.n          a9, 2
                movi.n          a10, 1
                l32r            a3, dword_40100070
                movi.n          a11, 0
                s32i.n          a11, a3, 0
                s32i.n          a10, a3, 4
                s32i.n          a9, a3, 8
                s32i.n          a8, a3, 0xC
                s32i.n          a7, a3, 0x10
                s32i.n          a6, a3, 0x14
                s32i.n          a5, a3, 0x18
                s32i.n          a4, a3, 0x1C
                s32i.n          a2, a3, 0x20
                ret.n


In the GCC and this happens:

l32r a4, xxxx
addi a4, a4, offset
l32i a3, a4, 0

instead :o :

l32r a4, xxxx
l32i a3, a4, offset

and this happens:

xxxx0 .int 12345
xxxx1 .int 12345
l32r a2, xxxx0
...
l32r a3, xxxx1
User avatar
By jcmvbkbc
#19517
pvvx wrote:
Code: Select allvoid test(void)
{
   unsigned int *ptr = (unsigned int *)0x60001100;
   ptr[0] = 0;
   ptr[1] = 1;
   ptr[2] = 2;
   ptr[3] = 3;
   ptr[4] = 4;
   ptr[5] = 5;
   ptr[6] = 6;
   ptr[7] = 7;
   ptr[8] = 8;
}


Funny, this exact example is compiled perfectly by gcc with -fno-tree-ccp -Os, but looks like somebody here is either too arrogant to notice or is actively misleading.