在VC ++中,#Oragma等效于/ O2编译器选项(针对速度进行优化) [英] In VC++ what is the #pragma equivalent of /O2 compiler option (optimize for speed)

查看:190
本文介绍了在VC ++中,#Oragma等效于/ O2编译器选项(针对速度进行优化)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 msdn


/ O2(最大速度)

/O2 (Maximize Speed)

等于


/ Og / Oi / Ot / Oy / Ob2 / Gs / GF / Gy

/Og/Oi/Ot/Oy/Ob2/Gs/GF/Gy

并根据 msdn 再次,以下杂注


#pragmaoptimize( [optimization-list],{on | off})

#pragma optimize( "[optimization-list]", {on | off} )

在其优化列表中使用的字母与/ O编译器选项相同。可以使用的实用字母为:

uses the same letters in its "optimization-list" than the /O compiler option. Available letters for the pragma are:


  • g -启用全局优化。

  • p -改善浮点一致性。

  • s或t -指定机器码的短序列或快速序列。

  • y -在程序堆栈上生成帧指针

  • g - Enable global optimizations.
  • p - Improve floating-point consistency.
  • s or t - Specify short or fast sequences of machine code.
  • y - Generate frame pointers on the program stack.

我应该使用哪个含义与/ O2相同?

Which ones should I use to have the same meaning as /O2 ?

推荐答案

Microsoft文档文章 / O1,/ O2(最小化尺寸,最大化速度) 对于Visual Studio 2017说:

The Microsoft Docs article /O1, /O2 (Minimize Size, Maximize Speed) says for Visual Studio 2017:


/ O1和/ O2编译器选项是一次设置多个
特定优化选项的快速方法。 / O1选项设置
个单独的优化选项,这些选项在
多数情况下创建最小的代码。 / O2选项设置大多数情况下创建
最快代码的选项。 / O2选项是发行版本的默认
。下表显示了由/ O1和/ O2设置的
的特定选项:

The /O1 and /O2 compiler options are a quick way to set several specific optimization options at once. The /O1 option sets the individual optimization options that create the smallest code in the majority of cases. The /O2 option sets the options that create the fastest code in the majority of cases. The /O2 option is the default for release builds. This table shows the specific options that are set by /O1 and /O2:

Option                   Equivalent to
/O1 (Minimize Size)     /Og /Os /Oy /Ob2 /GF /Gy
/O2 (Maximize Speed)    /Og /Oi /Ot /Oy /Ob2 /GF /Gy


来自Microsoft文档文章 / O选项(优化代码)


  1. / Og 启用全局优化

  2. / Oi 会为相应的函数调用生成内在函数。

  3. / Ot (默认设置)告诉编译器优先于速度优化而不是大小优化。

  4. / Oy 禁止创建帧指针

  5. / Ob2 扩展标记为 inline __ inline 以及编译器选择的任何其他函数

  1. /Og enables global optimizations
  2. /Oi generates intrinsic functions for appropriate function calls.
  3. /Ot (a default setting) tells the compiler to favor optimizations for speed over optimizations for size.
  4. /Oy suppresses the creation of frame pointers on the call stack for quicker function calls.
  5. /Ob2 expands functions marked as inline or __inline and any other function that the compiler chooses

G选项为:


  1. / GF (消除重复的字符串)

  2. / Gy (启用功能级链接)

  1. /GF (Eliminate Duplicate Strings)
  2. /Gy (Enable Function-Level Linking)

/ G 选项不是严格的优化,因此我们只剩下 / Og / Ot ,加上 #pragma内在(用于列表中的项目2), #pragma auto_inline (对于列表中的第5项),可能还有 #pragma inline_depth 。请参阅 Microsoft Docs文章优化语法和关键字

The /G options aren't strictly optimizations, so that leaves us with /Og and /Ot, plus #pragma intrinsic (for item 2 in the list), #pragma auto_inline (for item 5 in the list) and possibly #pragma inline_depth. See Microsoft Docs article Optimization Pragmas and Keywords

另请参见 Microsoft文档文章/ Ox(启用最高速度优化),其中指出了 / Ox 选项类似于 / O2 选项,不同之处在于它不会打开 / GF / Gy 。另请参见 /之间的区别是什么Ox和/ O2编译器选项?

See also Microsoft Docs article /Ox (Enable Most Speed Optimizations) which indicates the /Ox option is similar to the /O2 option except that it does not turn on /GF nor /Gy. See as well What is the difference between the /Ox and /O2 compiler options?

Microsoft文档文章按类别列出的编译器选项 列出了一系列编译器选项并附有含义的链接。

The Microsoft Docs article Compiler options listed by category has a list of compiler options with links as to what they mean.

这篇关于在VC ++中,#Oragma等效于/ O2编译器选项(针对速度进行优化)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆