Topic : About C816 compilation efficiency

Forum : Other families

Original Post
Post Information Post
June 4, 2021 - 10:28am
Yoshifumi Konda

GCC C816 sometimes generates inefficient code. 

When there is such C code:

static struct { uint8_t a, b, c, d, e, f; } dat __attribute__ ((page_0));

dat.a = 0; dat.b = 1; dat.c = 2; dat.d = 3; dat.e = 4; datf = 5;

then, the compiler may generate following ASM code:

MOVE i0h,#0x0
MOVE i0l,#0xXX ; address of `dat` < 0x100
MOVE a,#0x0
MOVE (i0,0),a
MOVE a,#0x1
MOVE (i0,1),a
MOVE a,#0x2
MOVE (i0,2),a
MOVE a,#0x3
MOVE (i0,3),a
MOVE a,#0x4
MOVE (i0,4),a
MOVE a,#0x5
MOVE (i0,4),a

The compiler will generate ASM code that seems to ignore that all fields of the structure exist in the Page0 region.
Originally, this code should have been written in half the lines.

Replies
Post Information Post
+1
0
-1
June 15, 2021 - 2:45pm
vincent choplin

Hello,

Thanks for the information.

Indeed the C816 compiler could be more efficient if one day we have resources for that.

However, there might we ways to workaround the problem...

Please first confirm the version of the compiler that you are using and the optimization options.

Note also that there might be ways to write the same thing differently and get a better result. Which CPU are you using? Do you have NVM data in your CPU?

Best Regards,

Vincent