Subject: Re: compiler/optimizer question...
To: None <tech-kern@netbsd.org>
From: Matthew Mondor <mm_lists@pulsar-zone.net>
List: tech-kern
Date: 03/18/2006 11:13:26
On Fri, 17 Mar 2006 23:37:47 -0800
"Garrett D'Amore" <garrett_damore@tadpole.com> wrote:

[...]

> #define TCP_FIELDS_TO_HOST(th)                                          \
> do {                                                                    \
>         NTOHL((th)->th_seq);                                            \
>         NTOHL((th)->th_ack);                                            \
>         NTOHS((th)->th_win);                                            \
>         NTOHS((th)->th_urp);                                            \
> } while (/*CONSTCOND*/ 0)

[...]

> static void
> tcp_fields_to_host(struct tcphdr *th)
> {
> ....
> }
> 
> The question I have is, will the compiler do The Right Thing in this
> case, and inline this in such a way that it doesn't have to use a
> function call.  (I.e. there is theoretically enough info here that the
[...]

At least with GCC, unless it changed recently, you would need to use -O3
or -finline-functions for the compiler to automatically inline small
simpe functions without explicit use of inline (or __inline) keyword.  I
think that the default builds do not use -O3 to minimize cache thrashing
on some systems (-O2 generally performs better on those), but it would
be worth to check again to make sure.

> I guess "inline" or "__inline" could be added too to force the compiler
> to inline, and maybe it could do a better job then of deciding how to
> inline and reuse code if possible than the macro expansion would allow
> for.  (I have a sneaking suspicion that using macros to inline
> functionality always loses over declaring an inline function, because
> the compiler doesn't get to see that the code is common in all places.

I also think that an inline function would work as efficiently, if not
better.  I'm not sure if this conflicts with the general style of the
stack's code, and/or if we need to maintain some of those macros for
compatibility with other BSDs, however, or if we already diverged enough
that it doesn't matter...

Matt

-- 
Note: Please only reply on the list, other mail is blocked by default.
Private messages from your address can be allowed by first asking.