简体   繁体   English

对于 gcc 编译器,gcc 在不使用任何标志与 -O2 进行编译时针对哪个 x86-64 指令集?

[英]For gcc compiler, what x86-64 instruction set does gcc target when you compile without any flags versus -O2?

For x86-64 there are lots of instruction sets that speed up code execution.对于 x86-64,有很多指令集可以加速代码执行。 Here is a list from gcc wiki https://gcc.gnu.org/wiki/FunctionMultiVersioning :这是来自 gcc wiki https://gcc.gnu.org/wiki/FunctionMultiVersioning的列表:

  • MMX MMX
  • SSE上交所
  • SSE2 SSE2
  • SSE3上证3
  • SSSE3 SSSE3
  • SSE4.1 SSE4.1
  • SSE4.2 SSE4.2
  • POPCNT流行音乐网络
  • AVX AVX
  • AVX2 AVX2

For gcc compiler, what x86-64 instruction set does gcc target when you compile without any flags versus -O2 ?对于 gcc 编译器,gcc 在编译时不带任何标志与-O2对应的 x86-64 指令集是什么?

To keep things simple lets just say the question is about gcc version 12 (most recent major).为了简单起见,我们只说问题是关于 gcc 版本 12(最近的主要版本)。 But I would like to know what gcc command switches/options i need to do to so that i can see what my version of gcc version does.但我想知道我需要做什么 gcc 命令开关/选项,以便我可以看到我的 gcc 版本的功能。

I assume that gcc chooses something that is "portable" so that would mean probably something slow.我假设 gcc 选择了“便携”的东西,所以这可能意味着速度很慢。 But this is just my assumption... I would like to know does that mean like SSE4.2 or none?但这只是我的假设……我想知道这意味着像 SSE4.2 还是没有?

If you don't pass a command-line -march option, then you get whatever was selected when gcc was compiled.如果您不传递命令行-march选项,那么您将获得编译 gcc 时选择的任何内容。 The default is -march=x86-64 but it could have been overridden by whoever compiled your gcc (eg your binary package distributor).默认值为-march=x86-64但它可能已被编译您的 gcc 的人覆盖(例如您的二进制 package 分发者)。 See https://gcc.gnu.org/install/configure.html and note the --with-arch option.请参阅https://gcc.gnu.org/install/configure.html并注意--with-arch选项。

You can compile with -v -Q to see what option is in use.您可以使用-v -Q进行编译以查看正在使用的选项。 Look for the options passed line.查找options passed行。

With -march=x86-64 you get "least common denominator" code that will run on every known x86-64 CPU, all the way back to the AMD K8.使用-march=x86-64可以获得“最小公分母”代码,该代码将在每个已知的 x86-64 CPU 上运行,一直追溯到 AMD K8。 This includes SSE2, which was part of the original AMD64 spec, but not SSE3 or anything later.这包括 SSE2,它是原始 AMD64 规范的一部分,但不包括 SSE3 或任何更高版本。 popcnt would not be included either. popcnt也不会包括在内。

The -march option is orthogonal to optimization options like -O2 and the -f... flags (eg -funroll-loops ). -march选项与-O2-f...标志(例如-funroll-loops )等优化选项正交。 You always get code compatible with whatever is selected by -march , no matter what optimization options are in use.无论使用什么优化选项,您始终会获得与-march选择的任何内容兼容的代码。 However -m flags (like -mavx ) can permit the use of other CPU features beyond what -march implies, in which case your code is only guaranteed to run on CPUs with those features.但是-m标志(如-mavx )可以允许使用超出-march暗示的其他 CPU 功能,在这种情况下,您的代码只能保证在具有这些功能的 CPU 上运行。

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

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