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

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

CPU_FLAGS_* is a USE_EXPAND variable containing instruction set and other CPU-specific features. Currently Gentoo supports CPU_FLAGS_X86 (for amd64 and x86 architectures), CPU_FLAGS_ARM (for arm and arm64 architectures), and CPU_FLAGS_PPC (for ppc and ppc64 architectures).


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.


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

Migration from deprecated USE flags

为了不丢失 CPU 特点优化,用户将需要更新 make.conf(可能还有 package.use)文件。例如,如果存在以下 USE 标志:

文件 /etc/portage/make.conf
USE="mmx mmxext sse sse2 sse3"

They should be moved to the relevant CPU_FLAGS_* variable.

保存不推荐使用的 USE 标记

Previous USE flags corresponding to the instruction sets and other features specific to the x86/amd64, ppc/ppc64 and arm/arm64 architectures are being moved into separate USE_EXPAND variables.

In order to ensure safe migration and maintain compatibility with external repositories, it is recommended to preserve the old USE settings for a period of one year or until no package of interest is still using them.