gpt4 book ai didi

c - MSVC#pragma 优化参数示例

转载 作者:行者123 更新时间:2023-11-30 14:41:34 25 4
gpt4 key购买 nike

任何人都可以给我链接一个示例,说明如何使用 #pragma optimize("some_values_for_02", on) 来模拟选定的几个函数的全局 02 优化。

我查看了 msdn 文档以及 SO,这是迄今为止我见过的最好的: In VC++ what is the #pragma equivalent of /O2 compiler option (optimize for speed)

该答案的链接已不再有效。

语法是什么样的?我需要使用多个#pragmas 来模仿 02 优化吗?链接的答案提到尝试添加 #pragma inside#pragma auto_inline

如果你能指出我在野外的来源,我可以将其作为一个也可以工作的示例。

谢谢

最佳答案

/O2 == /Og/Oi/Ot/Oy/Ob2/GF/Gy。一步一步:

  • /Og:Global Optimizations :

    /Og is deprecated. These optimizations are now generally enabled by default

    ~>不在乎。无论如何:

    You can enable or disable global optimization on a function-by-function basis using the optimize pragma together with the g option.

    #pragma optimize("g", on)


  • /Oi:intrinsic

    #pragma intrinsic(_disable, _outp, fabs, strcmp, _enable, _outpw, labs, strcpy,
    _inp, _rotl, memcmp, strlen, _inpw, _rotr, memcpy, _lrotl,
    _strset, memset, _lrotr, abs, strcat)


  • /Ot:optimize

    #pragma optimize("t", on)


  • /Oy:optimize

    #pragma optimize("y", on)


  • /Ob2 Inline Function Expansion :

    The compiler treats the inline expansion options and keywords as suggestions. There is no guarantee that any function will be expanded inline. You can disable inline expansions, but you cannot force the compiler to inline a particular function, even when using the __forceinline keyword.

    ~> 不在乎。


  • /GF 不知道。

  • /Gy 不知道。


最终结果:

#pragma intrinsic(_disable, _outp, fabs, strcmp, _enable, _outpw, labs, strcpy,
_inp, _rotl, memcmp, strlen, _inpw, _rotr, memcpy, _lrotl,
_strset, memset, _lrotr, abs, strcat)
#pragma optimize("gty", on)

最后一件事:为什么?

关于c - MSVC#pragma 优化参数示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54879483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com