avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: AW: [avr-gcc-list] SIGNAL and INTERRUPT overhead


From: Bernard Fouché
Subject: Re: AW: [avr-gcc-list] SIGNAL and INTERRUPT overhead
Date: Sun, 28 Aug 2005 19:24:09 +0200

On 14:26:38 28/08/2005 "E. Weddington" <address@hidden> wrote:
> Haase Bjoern (PT-BEU/EMT) * wrote:
>
> > Citing from the gcc documentation:
> >
> > "Compiling multiple files at once to a single output file in
> > _unit-at-a-time_ mode allows the compiler to use information gained
> > from all of the files when compiling each of them."
> > -O2 and -Os switch on -funit-at-a-time.
> >
> >
> >
> [Sorry to get in on this later. I'm just now catching up on mail.]
>
> How very interesting! I wasn't aware of this method. Has anyone done
> research on this to see if it will reduce the size of the final code
> even more?

I tried this approach, however the result I got was bigger than my previous
try with the 'big C file' system. (see later)


The problem is that even when compiling many C files with -funit-at-a-time,
the compiler can not take the decision to inline everything it could since
functions are not declared 'static inline'. And if you define some of them
this way manually (and thus already losing the interest of the
'-funit-at-a-time' approach) the compiler will complain because you'll
refer to functions declared 'static' but yet not in the same file!


For instance, let's say we have:

-- file f1.h ---
PREFIX void f1(void);
----------------

-- file f1.c ---
#include "f1.h"
PREFIX void f1(void){ ... something ... }
----------------

--- file f2.h ---
PREFIX void f2(void);
-----------------

--- file f2.c ---
#include "f1.h"
#include "f2.h"
PREFIX void f2(void) { f1(); ... something ... }
------------------

Let's say that the final result is built only with these files.

So here are the different solutions:

1) Compiling with -funit-at-a-time and -DPREFIX="" because compiling with
-DPREFIX="static inline" will fail: one can't compile f2.c since this will
lead to have the declaration of f1() in f1.h saying that the function is
'static inline'. And f1() itself can't be found.


2) Compiling f1.c and f2.c separatly with -DPREFIX="" (the 'usual' way)

3) Building a big C file with f1.c and f2.c and -DPREFIX="static inline"

The big C file needs to be:

PREFIX void f1(void);
PREFIX void f2(void);

PREFIX void f1(void){ ... something ... }
PREFIX void f2(void){ f1(); ... something... }

My point of view is that the latest approach gives the smallest result
since this is the only solution for the compiler to have everything it
needs to know about inlining. And if your project uses functions that needs
32 bits parameters, or many parameters, being able to inline some of them
will shrink the result in an important way. Doing the big C file approach,
I spared nearly 20% of the final size of a particular network bootloader.


(Also the 'PREFIX' system allows the project to use the 'usual' way (one
function or set of related functions in a single C file) for functions
needed by the application and the bootloader, when generating the
application)


Now beside inlining, -funit-at-a-time will surely optimizes other things
but IMHO to be very effective, this option should (or by adding others) :


- compile all C files in a single run.
- consider that all defined functions in the processed C files are not
called by external functions and so..:

- inline everything that can be.

  Bernard





reply via email to

[Prev in Thread] Current Thread [Next in Thread]