How to inline (sorry, earlier message was in mangled HTML)

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to inline (sorry, earlier message was in mangled HTML)

Clive McCarthy


I'm using gcc with C. After profiling I've discovered that several of my functions have failed to inline. The -Winline warning confirms this.
 Two questions:
 [1] When the warning indicates: "function body not available"
     -- how do I make it available?
     I've tried in my header file both:
     "inline extern foo()" and "extern inline foo()" to no effect.
     Does the entire function body have to be included from a header?
     Is the convention to use something like:
     #include "my_inline_functions.c"
     and segregate all inline functions from other code?

 [2] Is there a gcc option to force inlining?
     I could use a macro or simply instantiate the code in the caller
     I guess...
I have a function that is called 25 million times by one caller and it's nothing more than a VERY simple switch statement. The warning=2C somewhat amusingly says "call is unlikely and code size would grow". It ain't necessarily so.
Clive.    
_________________________________________________________________
Bing™  brings you maps, menus, and reviews organized in one place.   Try it now.
http://www.bing.com/search?q=restaurants&form=MLOGEN&publ=WLHMTAG&crea=TEXT_MLOGEN_Core_tagline_local_1x1
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: How to inline (sorry, earlier message was in mangled HTML)

Roger Pack
>  Two questions:
>  [1] When the warning indicates: "function body not available"
>     -- how do I make it available?

Is it contained in the same file? Is it static? [1]
If it seems impossible you could use preprocessor macros :)

Also different optimization settings might allow it [?]

-r
[1] http://gcc.gnu.org/onlinedocs/gcc/Inline.html

------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: How to inline (sorry, earlier message was in mangled HTML)

Clive McCarthy

 <[hidden email]>
Content-Type: text/plain; charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0



> Date: Sat=2C 3 Oct 2009 06:01:28 -0600
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [Mingw-users] How to inline (sorry=2C earlier message was in=
 mangled HTML)

>=20
>>  Two questions:
>>  [1] When the warning indicates: "function body not available"
>>     -- how do I make it available?
>=20
> Is it contained in the same file? Is it static? [1]
> If it seems impossible you could use preprocessor macros :)
>=20
> Also different optimization settings might allow it [?]
>=20
> -r
> [1] http://gcc.gnu.org/onlinedocs/gcc/Inline.html
>=20
> -------------------------------------------------------------------------=
-

Roger=2C I found this on a very helpful IBM website:
--quote:=20
In C=2C any function with internal linkage can be inlined=2C but a function=
 with external linkage is subject to restriction. The restrictions are as f=
ollows:=20

If the inline keyword is used in the function declaration=2C then the funct=
ion definition must appear in the same translation unit.

An inline definition of a function is one in which all of the file-scope de=
clarations for it in the same translation unit include the inline specifier=
 without extern.

An inline definition does not provide an external definition for the functi=
on: an external definition may appear in another translation unit. The inli=
ne definition serves as an alternative to the external definition when call=
ed from within the same translation unit.=20
=20
The C99 Standard does not prescribe whether the inline or external definiti=
on is used.=20
unquote--
=20
It seems that if one is to use inline in C=2C you have to work pretty hard =
-- the compiler needs to be given the function on a platter. I guess I was =
shocked at finding=2C from my profiling=2C that all the calls=2C to what I =
thought were inline functions=2C only to discover with -Winline that they w=
ere not. I will now always compile with -Winline by default.I need to read =
my Harbison and Steele more carefully.I have -O3 turned on.=20
=20
I think a macro is perhaps the only way to force things. Microsoft has a no=
n-standard __forceinline facility this suggests no standard means.
=20
I gather that it is necessary to create a function prototype of the form:
=20
extern inline void foo(void)
{
   // the function's _complete_ code here !
}=3B
=20
One then has the manual task of keeping the body of the function's prototyp=
e _identical_ to the body of the function itself. I have not investigated i=
f gcc complains if they differ. The mechanism doesn't seem to be very whole=
some.
=20
Clive.
=20
     =0A=
_________________________________________________________________=0A=
Hotmail: Trusted email with Microsoft=92s powerful SPAM protection.=0A=
http://clk.atdmt.com/GBL/go/177141664/direct/01/=

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: How to inline (sorry, earlier message was in mangled HTML)

Tuomo Latto
Clive McCarthy wrote:
>> Subject: Re: [Mingw-users] How to inline (sorry=2C earlier message was in=
>  mangled HTML)

So is this one. Please fix your mailer.
(And thank you for not hijacking any more threads.)

>> =20
>>>  Two questions:
>>>  [1] When the warning indicates: "function body not available"
>>>     -- how do I make it available?
>> =20
>> Is it contained in the same file? Is it static? [1]
[...]
> It seems that if one is to use inline in C=2C you have to work pretty hard =
> -- the compiler needs to be given the function on a platter. I guess I was =
> shocked at finding=2C from my profiling=2C that all the calls=2C to what I =
> thought were inline functions=2C only to discover with -Winline that they w=
> ere not. I will now always compile with -Winline by default.I need to read =
> my Harbison and Steele more carefully.I have -O3 turned on.=20

AFAICT, the compiler clearly tells you that it can not find the function
body (i.e. the definition) within the translation unit, preventing
it from inlining it. You seem to have a poor grasp of what an inline
function is.

> I gather that it is necessary to create a function prototype of the form:
> =20
> extern inline void foo(void)
> {
>    // the function's _complete_ code here !
> }=3B
> =20
> One then has the manual task of keeping the body of the function's prototyp=
> e _identical_ to the body of the function itself. I have not investigated i=
> f gcc complains if they differ. The mechanism doesn't seem to be very whole=
> some.

The function's prototype (i.e. the declaration) is the first line,
the rest *is* the function body for the inline version.
Without the "extern" keyword that blurb would be enough to define
the function. Nothing more would be needed. Having the extern keyword
there, however, requires you to define two* separate instances of
the body - one for inline version and the other for non-inline
("extern") version.

*) Technically you could have more than two versions of a function by having
several inline declaration/definitions of the single function, but I would
question the sanity of anyone who came up with such a solution.

This might be easier reading than the complex text you quoted earlier,
which didn't really explain what "extern inline" means:
http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/vac-7.0/html/language/ref/clrc07cplr243.htm

Also possibly useful:
http://www.efnetcpp.org/wiki/Translation_unit
http://en.wikipedia.org/wiki/Inline_function
http://www.glenmccl.com/ansi_015.htm


--
Tuomo

... Something is rotten in the state of confusion


------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Reply | Threaded
Open this post in threaded view
|

Re: How to inline (sorry, earlier message was in mangled HTML)

Clive McCarthy



----------------------------------------

> Date: Sun, 4 Oct 2009 00:12:00 +0300
> From: [hidden email]
> To: [hidden email]
> Subject: Re: [Mingw-users] How to inline (sorry, earlier message was in mangled HTML)
>
> Clive McCarthy wrote:
>>> Subject: Re: [Mingw-users] How to inline (sorry=2C earlier message was in=
>> mangled HTML)
>
> So is this one. Please fix your mailer.
> (And thank you for not hijacking any more threads.)
>
>>> =20
>>>> Two questions:
>>>> [1] When the warning indicates: "function body not available"
>>>> -- how do I make it available?
>>> =20
>>> Is it contained in the same file? Is it static? [1]
> [...]
>> It seems that if one is to use inline in C=2C you have to work pretty hard =
>> -- the compiler needs to be given the function on a platter. I guess I was =
>> shocked at finding=2C from my profiling=2C that all the calls=2C to what I =
>> thought were inline functions=2C only to discover with -Winline that they w=
>> ere not. I will now always compile with -Winline by default.I need to read =
>> my Harbison and Steele more carefully.I have -O3 turned on.=20
>
> AFAICT, the compiler clearly tells you that it can not find the function
> body (i.e. the definition) within the translation unit, preventing
> it from inlining it. You seem to have a poor grasp of what an inline
> function is.
>
>> I gather that it is necessary to create a function prototype of the form:
>> =20
>> extern inline void foo(void)
>> {
>> // the function's _complete_ code here !
>> }=3B
>> =20
>> One then has the manual task of keeping the body of the function's prototyp=
>> e _identical_ to the body of the function itself. I have not investigated i=
>> f gcc complains if they differ. The mechanism doesn't seem to be very whole=
>> some.
>
> The function's prototype (i.e. the declaration) is the first line,
> the rest *is* the function body for the inline version.
> Without the "extern" keyword that blurb would be enough to define
> the function. Nothing more would be needed. Having the extern keyword
> there, however, requires you to define two* separate instances of
> the body - one for inline version and the other for non-inline
> ("extern") version.
>
> *) Technically you could have more than two versions of a function by having
> several inline declaration/definitions of the single function, but I would
> question the sanity of anyone who came up with such a solution.
>
> This might be easier reading than the complex text you quoted earlier,
> which didn't really explain what "extern inline" means:
> http://www.serc.iisc.ernet.in/ComputingFacilities/systems/cluster/vac-7.0/html/language/ref/clrc07cplr243.htm
>
> Also possibly useful:
> http://www.efnetcpp.org/wiki/Translation_unit
> http://en.wikipedia.org/wiki/Inline_function
> http://www.glenmccl.com/ansi_015.htm
>
>
> --
> Tuomo
>
> ... Something is rotten in the state of confusion
>
>
Thanks.    
_________________________________________________________________
Hotmail: Free, trusted and rich email service.
http://clk.atdmt.com/GBL/go/171222984/direct/01/
------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.

Most annoying abuses are:
1) Top posting
2) Thread hijacking
3) HTML/MIME encoded mail
4) Improper quoting
5) Improper trimming
_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users