:> 
:>     More then judicious use -- inlines are an incredible advantage.  Most
:>     people don't realize that GCC will optimize constant arguments through
:>     an inline call.  Try this:
:> 
:> static __inline

    Yah, and if it's static it will not even output code for fubar.

    I've never trusted -O3, though, and you can't put static procedures
    in header files ( because then you can't fall back to -O2 ).  Thus,
    for this sort of optimization to work the procedure must be in the same
    source file, which kills the modularity.  Also, on top of all of that,
    GCC may not make a good decision on whether to actually inline the
    static or whether to call it - it might wind up inlining a large
    routine that you call many times in your module and both bloat the code
    and destroy the L1 cache.

    I think it's better to make things explicitly __inline and to put them in
    the proper subsystem's header files.  It isn't worth depending on -O3
    for things to compile:

       -O3    Optimize  yet  more.  This  turns on everything -O2
              does, along with  also  turning  on  -finline-func-
              tions.

                                                -Matt

:Matt,
:
:int
:fubar(int c)
:{
:    if (c & 1)
:        ++c;
:     if (c & 2)
:         ++c;
:     return(c);
:}
:
:void
:fubar2(void)
:{
:    volatile int x;
:
:     x = fubar(0);
:     x = fubar(1);
:     x = fubar(2);
:     x = fubar(3);
:}
: 
:% cc -S -O3 x.c
:% cat x.s
:
:fubar2:
:        pushl %ebp
:        movl %esp,%ebp
:        subl $4,%esp
:        xorl %eax,%eax         <----- fubar (0)
:        movl %eax,-4(%ebp)
:        movl $3,-4(%ebp)       <----- fubar (1)
:        movl $3,-4(%ebp)       <----- fubar (2)
:        movl $4,-4(%ebp)       <----- fubar (3)
:        leave
:        ret
:
:-- 
:Steve
:
:finger ka...@troutmask.apl.washington.edu
:http://troutmask.apl.washington.edu/~clesceri/kargl.html
:

                                        Matthew Dillon 
                                        <dil...@backplane.com>

To Unsubscribe: send mail to majord...@freebsd.org
with "unsubscribe freebsd-current" in the body of the message

Reply via email to