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: Matt Armstrong
Subject: Re: Emacs' C: static inline considered useless nowadays?
Date: Sun, 16 Oct 2022 20:13:46 -0700

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

Microsoft Visual Studio has more optimization knobs.

    /Od: neither are inlined
    /Ot: neither are inlined
    /Ox: both are inlined
    /Odb1: only static_inline_add is inlined
    /Odb2: only static_inline_add is inlined
    /O1: both are inlined
    /O2: both are inlined

I couldn't find a way to trigger Visual Studio into behaving like gcc.



reply via email to

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