Overall I must optimize my code for size, due to targeting IoT devices which have small amounts of SRAM with which to code for execution, and which have small program flash sizes, but there are some situations where I need trivial functions to be aggressively inlined.
Unfortunately, when optimizing for size, GCC basically seems to take over deciding when something should be inlined entirely, causing me some major performance problems in certain codepaths.
In order to get around this, rather than declaring an inline function, I use preprocessor macros with the function's implementation inside of them, and use those instead of a function call when I need to do something.
That leads to methods that look like this:
virtual void address_window(
uint16_t x1,
uint16_t y1,
uint16_t x2,
uint16_t y2) {
HTCW_RS_C; HTCW_WRITE8(ca_set);
HTCW_RS_D; HTCW_WRITE16(x1); HTCW_WRITE16(x2);
HTCW_RS_C; HTCW_WRITE8(ra_set);
HTCW_RS_C; HTCW_WRITE16(y1); HTCW_WRITE16(y2);
HTCW_RS_C; HTCW_WRITE8(ram_wr);
HTCW_RS_C;
}
all the HTCW_XXXX things are preprocessor macros.
I'm one of those weirdos that thinks that in an ideal world, in C++ the preprocessor should be totally unnecessary. You should be able to anything you can do with the preprocessor using const/constexpr/inline/template. In theory, you can, but because "inline" is a suggestion at best, in practice I'm still stuck with the preprocessor ugliness.
Does anyone know of a better way?
What I have tried:
I've tried declaring my functions inline and even only putting them in the header, and GCC nevertheless will sometimes create a call for it.