emacs-devel
[Top][All Lists]
Advanced

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

Re: Emacs' C: static inline considered useless nowadays?


From: Óscar Fuentes
Subject: Re: Emacs' C: static inline considered useless nowadays?
Date: Mon, 17 Oct 2022 05:33:18 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

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 via email to

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