CPU_FLAGS_*

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page CPU FLAGS * and the translation is 65% complete.
Outdated translations are marked like this.
Other languages:
不要混淆 CFLAGS.

Warning: Display title "CPU_FLAGS_*" overrides earlier display title "CPU FLAGS *".

CPU_FLAGS_* 是 包含指令集和其他 CPU 特定功能的 USE_EXPAND 变量。 目前,Gentoo 支持 CPU_FLAGS_X86 (针对 amd64x86 架构),CPU_FLAGS_ARM (针对 armarm64 架构)和 CPU_FLAGS_PPC (针对 ppcppc64 架构)。

另请参阅
For more information see the CPU_FLAGS_* section in the Gentoo Handbook.

CFLAGS 和 CPU_FLAGS_* 之间的不同

A common question is "what's the difference between CFLAGS and e.g. CPU_FLAGS_X86?"

CPU_FLAGS_* is an example of a USE_EXPAND. It enables specific options in ebuilds which are passed onto the build system. For example, CPU_FLAGS_X86_SSE2, if defined for a package, will enable handwritten ASM. These options enable specific code which already exists within the package.

CFLAGS, on the other hand, are simply used to tell the compiler it is allowed to try to generate code using such instructions if it is able. It does not mean it will be successful in doing so. e.g. -msse2 in CFLAGS does not mean the compiler will be clever enough to generate SSE2 for a certain function. These options just permit the compiler to generate certain code with certain instructions.

It is therefore important to configure CPU_FLAGS_* appropriately to get the best performance out of packages.

配置

这些标志需要复制到新创建的 CPU_FLAGS_X86 变量中:

文件 /etc/portage/make.conf设置 CPU_FLAGS_X86
CPU_FLAGS_X86="mmx mmxext sse sse2 sse3"

When in doubt, consult the flag descriptions using one of the commonly available tools, e.g. equery uses from app-portage/gentoolkit:

user $equery uses media-video/ffmpeg

大多数标志名称与 /proc/cpuinfo 名称匹配,例外是 sse3,它在 /proc/ 中称为 pni cpuinfo(也请不要将它与不同的 ssse3 混淆)。

使用 cpuid2cpuflags

app-portage/cpuid2cpuflags helps users determine the correct CPU_FLAGS_ USE_EXPAND variables for their CPU architecture.

Emerge

root #emerge --ask app-portage/cpuid2cpuflags

调用

user $cpuid2cpuflags
CPU_FLAGS_X86: mmx mmxext sse sse2 sse3

全局应用示例:

root #echo "*/* $(cpuid2cpuflags)" > /etc/portage/package.use/00cpu-flags

外部资源