more explicit
Thanks. That does help a lot.
There are two reasons that your results are inconsistent with mine:
1) You didn't inline the RCC functions as well. This is pretty minor; it's a nice trivial function and the call setup is about the same as the inline sequence produced. No big deal.
2) the big problem is that you missed that for the optimization I'm trying to invoke, the arguments to the inline functions should be CONSTANTS. Instead of
USART_TypeDef *uart;
uart=USART2;
:
myUSART_DeInit(uart);
You should have
myUSART_DeInit(USART2);
I'm a little surprised (and disappointed) that gcc doesn't manage to do this optimization even for your original code. Clearly uart has a constant value and is not volatile or anything; your code and the code with an explicitly constant argument REALLY ought to compile the same :-(
Here's the whole set of possible outcomes. "MANY" means three calls to DeInit rather than one.
( plain )
text data bss dec hex filename
1244 1080 32 2356 934 a.out
-DCONSTANT
1236 1080 28 2344 928 a.out
-DMANY
1256 1080 32 2368 940 a.out
-DMANY -DCONSTANT
1248 1080 28 2356 934 a.out
-DINLINES
1060 1080 32 2172 87c a.out
-DINLINES -DCONSTANT
1044 1080 28 2152 868 a.out
-DINLINES -DMANY
1384 1080 32 2496 9c0 a.out
-DINLINES -DMANY -DCONSTANT
1084 1080 28 2192 890 a.out
I discovered something else interesting, accidentally. Want to save 528 bytes of code and 1k of data space (initialized data, so it takes up flash space) in most of your programs? Define your own exit() function.
void exit(int r) {while(1);}
Apparently the standard runtime defaults to a fancy version of exit that calls registered exit procedures. And that pulls in code to register those procs. And support functions. 528 bytes worth of code plus over 1000 bytes of "data" to support something that shouldn't happen in an embedded system (calling exit() or allowing main() to return.) Sigh.
(Edited to include the substantial .data contribution of the default exit()) (Hmm. It may be that since I'm using a different compile procedure and maybe different STP libs (from the Nucleo downloads, rather than the STP downloads) that my results are different than others...)