From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?utf-8?Q?=C3=93scar_Fuentes?= Newsgroups: gmane.emacs.devel Subject: Re: Emacs' C: static inline considered useless nowadays? Date: Mon, 17 Oct 2022 05:33:18 +0200 Message-ID: <87h703f7k1.fsf@telefonica.net> References: <874jw37764.fsf@rfc20.org> <87a65vcfbp.fsf@rfc20.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29095"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: emacs-devel@gnu.org Cancel-Lock: sha1:nuF3j3GGOvKW7IOUJsBn3Tx9EFk= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 17 07:24:36 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1okIc7-0007LA-Mn for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 07:24:35 +0200 Original-Received: from localhost ([::1]:52260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1okIc6-0007up-0k for ged-emacs-devel@m.gmane-mx.org; Mon, 17 Oct 2022 01:24:34 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okGsc-00064s-Mu for emacs-devel@gnu.org; Sun, 16 Oct 2022 23:33:30 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]:44378) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1okGsa-0000Kw-Pc for emacs-devel@gnu.org; Sun, 16 Oct 2022 23:33:30 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1okGsX-0000gP-Oq for emacs-devel@gnu.org; Mon, 17 Oct 2022 05:33:25 +0200 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=ged-emacs-devel@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 17 Oct 2022 01:19:49 -0400 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297908 Archived-At: Matt Armstrong writes: > Stefan Monnier 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.