是否可以编译自动使用不同处理器的东西?
是否可以编译一些自动利用其在指令集上运行的不同处理器的东西?
理想情况下,在 gcc 和 c 上,无需在代码中显式执行。
-mtune(单独)可以吗?
Is it possible to compile something which automatically utilises the different processors' it runs on instruction sets?
Ideally on gcc and c, without doing it explicitly in code.
Will -mtune (alone) do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最新版本的 gcc 有
-march=native
,它将生成代码以使用运行编译器的计算机上可用的所有指令集扩展,但它不会生成在运行时检测哪些指令集扩展的二进制文件。可以使用扩展。可以编写代码来检测哪些扩展可用,并基于此使用不同的代码路径(这是游戏引擎等性能敏感代码的常用技术),但我不知道有任何工具可以自动生成此扩展代码和代码的不同版本。如果您想创建一个可以在多种不同架构(如 x86 和 ARM)上运行的二进制文件,您需要创建一个称为“胖二进制文件”的东西,或者用 Apple 的营销术语来说,就是“通用二进制文件” :这需要为每个架构编译一次代码,并将不同架构的二进制文件链接到同一个文件中。这仅适用于支持胖二进制文件的操作系统,因为操作系统需要知道它必须仅加载正确架构的段。
Recent versions of gcc have
-march=native
, which will generate code to use all the instruction set extensions available on the machine that is running the compiler, but it does not generate a binary that detects at runtime which extensions are available. It is possible to write code that will detect which extensions are available and use different code paths based on that (this is a common technique for performance-sensitive code like game engines), but I don't know of any tools that automatically generate this code and the different versions of your code.If you want to create a binary that can run on multiple different architectures (like x86 and ARM), you need to create something called a fat binary, or in Apple's marketing lingo, a universal binary: this requires compiling your code once for each architecture, and linking the binaries for the different architectures into the same file. This only works on operating systems that support fat binaries, because the operating system needs to know that it has to load only the segments for the right architecture.