unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Óscar Fuentes" <ofv@wanadoo.es>
To: emacs-devel@gnu.org
Subject: Re: Emacs' C: static inline considered useless nowadays?
Date: Mon, 17 Oct 2022 05:33:18 +0200	[thread overview]
Message-ID: <87h703f7k1.fsf@telefonica.net> (raw)
In-Reply-To: 87a65vcfbp.fsf@rfc20.org

Matt Armstrong <matt@rfc20.org> writes:

> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
>> Matt Armstrong [2022-10-16 15:08:51] wrote:
>>> I've spent the last few decades coding with an undersanding that
>>> "inline" is about linkage and allows one to place code in header files
>>> so that it *may* be inlined, but that compilers long ago stopped using
>>> it as a meaningful inlining hint.  But this is mostly colored by how gcc
>>> and clang behave with C++, and not much else.
>>
>> I believe what you say does hold true for "optimized builds".
>> I'd be interested to know if it's true for lower levels of optimization
>> as well.
>>
>>         Stefan "compiling with -Og"
>
> Seems the answer, thanks to godbolt, is "it depends", but "static
> inline" does enable inlining in gcc's -Og, so it has its use.
>
> For this program:
>
>     static inline int static_inline_add(int x, int y) { return x + y; }
>     static int static_add(int x, int y) { return x + y; }
>     int add_three(int x, int y, int z) {
>         return static_add(x, static_inline_add(y, z));
>     }
>
> gcc and clang has the same behavior:
>
>     -O0: nither static functions are inlined into 'add_three'
>     -Og: only 'static_inline_add' is inlined
>     -O1: 'static_add' is also inlined

See https://gcc.gnu.org/onlinedocs/gcc/Inline.html for some enlightening
comments on this topic.

Please note that modern compilers implement complex heuristics for
deciding when a function is inlined (and the presence of the `inline'
keyword is just another factor.) An "static inline" function may not be
inlined even at -O2 if your compiler decides that it is better left
un-inlined.




  reply	other threads:[~2022-10-17  3:33 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-16 22:08 Emacs' C: static inline considered useless nowadays? Matt Armstrong
2022-10-17  0:43 ` Stefan Monnier
2022-10-17  3:13   ` Matt Armstrong
2022-10-17  3:33     ` Óscar Fuentes [this message]
2022-10-17  6:10 ` Eli Zaretskii
2022-10-17 19:08   ` Matt Armstrong
2022-10-17 19:12     ` Eli Zaretskii
2022-10-17 20:33       ` Matt Armstrong
2022-10-18  2:30         ` Eli Zaretskii
2022-10-18 13:32           ` Stefan Monnier
2022-10-18 15:09             ` Eli Zaretskii
2022-10-18 17:01               ` tomas
2022-10-18 19:22               ` Stefan Monnier
2022-10-18 19:31                 ` Eli Zaretskii
2022-10-18 11:58 ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87h703f7k1.fsf@telefonica.net \
    --to=ofv@wanadoo.es \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).