使用一个+95%的C++ 11代码(其余的代码是C),这是通常使用的编译w/优化级别3,我们分析了它,发现了一种非常耗时的方法。
玩具代码:
myClass::mainMethod()
{
// do stuff here
/ ...
// do more stuff here
/ ...
}
我们把它的内部部分分割成其他方法,以便精确地测量出问题所在。
myClass::mainMethod()
{
this->auxiliaryMethod1();
this->auxiliaryMethod2();
}
myClass::auxiliaryMethod1()
{
// do stuff here
// ...
}
myClass::auxiliaryMethod2()
{
// do more stuff here
// ...
}
但是(英特尔)编译器足够聪明,能够注意到这仅仅是一种用法,并将它组装回一个方法中。
除了这两个明显的其他可能的解决方案,即编译而没有优化(不切实际)和添加其他虚假用法(一个浪费的过程),是否有一个英特尔编译器标志,以表明“请明确编码到类”?
谢谢!
发布于 2022-05-10 14:53:49
正如注释所建议的那样,使用属性noinline进行拆分是很有用的。
void __attribute__((noinline)) myClass::mainMethod()
{
this->auxiliaryMethod1();
this->auxiliaryMethod2();
}
void __attribute__((noinline)) myClass::auxiliaryMethod1()
{
// do stuff here
// ...
}
void __attribute__((noinline)) myClass::auxiliaryMethod2()
{
// do more stuff here
// ...
}
https://stackoverflow.com/questions/72174397
复制相似问题