简体   繁体   English

在带有std = c99的gcc中强制内联函数

[英]forcing inline functions in gcc with std=c99

I am writing a pure c code (for fast performance) and I am hoping that gcc can at least expand all the functions that I declared as "static inline" (because I am using std=c99, the semantics of inline has changed and static inline is what preferred), some of those functions include matrix manipulation, heap up/down sift, etc. usually fairly small operations that occurs many time. 我正在编写一个纯C代码(以提高性能),并且希望gcc至少可以扩展我声明为“静态内联”的所有功能(因为我使用的是std = c99,所以内联的语义已更改并且是静态的最好使用inline),其中一些功能包括矩阵操作,堆向上/向下筛选等。通常情况下,发生的操作非常小,通常会发生很多次。 Is there a way to achieve this by specifying any options of GCC? 有没有一种方法可以通过指定GCC的任何选项来实现? I have already enabled -o3, and somewhere I came across saying that by -o3 and "static inline" function declaring, all function calls will be expanded. 我已经启用了-o3,在某个地方我碰巧说过-o3和“静态内联”函数声明,所有函数调用都将被扩展。 Is that true? 真的吗? How can I verify that? 我该如何验证? Thanks! 谢谢!

You might try __attribute__((always_inline)) , but in general, normal inline should be enough, unless you go for -Os . 您可以尝试__attribute__((always_inline)) ,但通常来说,正常的inline就足够了,除非您使用-Os If a function is not inlined, gcc might have good reasons not to. 如果未内联函数,则gcc可能有充分的理由不这样做。

A better way would be to use profiling and link time optimization (LTO). 更好的方法是使用性能分析和链接时间优化(LTO)。 In general, hand-optimizing code should be the last ressort. 通常,手动优化代码应该是最后的解决方法。

Of course you can verify if a function has been inlined: just look at the generated code. 当然,您可以验证函数是否已内联:只需查看生成的代码即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM