ArticleslgStudy

science

X86 Bit manipulation instruction set

X86 Bit manipulation instruction set is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand X86 Bit manipulation instruction set rather than just read about it. In short: Bit manipulation instructions sets (BMI sets) are extensions to the x86 instruction set architecture for microprocessors from Intel and AMD. The purpose of these instruction sets is to improve the speed of bit manipulation.

Key takeaways

  • X86 Bit manipulation instruction set belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect X86 Bit manipulation instruction set to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of X86 Bit manipulation instruction set from memory before moving on to harder problems.

Reference excerpt

Bit manipulation instructions sets (BMI sets) are extensions to the x86 instruction set architecture for microprocessors from Intel and AMD. The purpose of these instruction sets is to improve the speed of bit manipulation. All the instructions in these sets are non-SIMD and operate only on general-purpose registers. There are two sets published by Intel: BMI (now referred to as BMI1) and BMI2; they were both introduced with the Haswell microarchitecture with BMI1 matching features offered by AMD's ABM instruction set and BMI2 extending them. Another two sets were published by AMD: ABM (Advanced Bit Manipulation, which is also a subset of SSE4a implemented by Intel as part of SSE4.2 and BMI1), and TBM (Trailing Bit Manipulation, an extension introduced with Piledriver-based processors as an extension to BMI1, but dropped again in Zen-based processors).

ABM (Advanced Bit Manipulation) AMD was the first to introduce the instructions that now form Intel's BMI1 as part of its ABM (Advanced Bit Manipulation) instruction set, then later added support for Intel's new BMI2 instructions. AMD today advertises the availability of these features via Intel's BMI1 and BMI2 cpuflags and instructs programmers to target them accordingly. While Intel considers POPCNT as part of SSE4.2 and LZCNT as part of BMI1, both Intel and AMD advertise the presence of these two instructions individually. POPCNT has a separate CPUID flag of the same name, and Intel and AMD use AMD's ABM flag to indicate LZCNT support (since LZCNT combined with BMI1 and BMI2 completes the expanded ABM instruction set).

LZCNT is related to the Bit Scan Reverse (BSR) instruction, but sets the ZF (if the result is zero) and CF (if the source is zero) flags rather than setting the ZF (if the source is zero). Also, it produces a defined result (the source operand size in bits) if the source operand is zero. For a non-zero argument, sum of LZCNT and BSR results is argument bit width minus 1 (for example, if 32-bit argument is 0x000f0000, LZCNT gives 12, and BSR gives 19). The encoding of LZCNT is such that if ABM is not supported, then the BSR instruction is executed instead.

BMI1 (Bit Manipulation Instruction Set 1) The instructions below are those enabled by the BMI bit in CPUID. Intel officially considers LZCNT as part of BMI, but advertises LZCNT support using the ABM CPUID feature flag. BMI1 is available in AMD's Jaguar, Piledriver and newer processors, and in Intel's Haswell and newer processors.

TZCNT is almost identical to the Bit Scan Forward (BSF) instruction, but sets the ZF (if the result is zero) and CF (if the source is zero) flags rather than setting the ZF (if the source is zero). For a non-zero argument, the result of TZCNT and BSF is equal. As with LZCNT, the encoding of TZCNT is such that if BMI1 is not supported, then the BSF instruction is executed instead.

BMI2 (Bit Manipulation Instruction Set 2) Intel introduced BMI2 together with BMI1 in its line of Haswell processors. Only AMD has produced processors supporting BMI1 without BMI2; BMI2 is supported by AMDs Excavator architecture and newer.

Parallel bit deposit and extract The PDEP and PEXT instructions are new generalized bit-level compress and expand instructions. They take two inputs; one is a source, and the other is a selector. The selector is a bitmap selecting the bits that are to be packed or unpacked. PEXT copies selected bits from the source to contiguous low-order bits of the destination; higher-order destination bits are cleared. PDEP does the opposite for the selected bits: contiguous low-order bits are copied to selected bits of the destination; other destination bits are cleared. This can be used to extract any bitfield of the input, and even do a lot of bit-level shuffling that previously would have been expensive. While what these instructions do is similar to bit level gather-scatter SIMD instructions, PDEP and PEXT instructions (like the rest of the BMI instruction sets) operate on general-purpose registers. The instructions are available in 32-bit and 64-bit versions. An example using arbitrary source and selector in 32-bit mode is:

AMD processors before Zen 3 that implement PDEP and PEXT do so in microcode, with a latency of 18 cycles rather than (Zen 3) 3 cycles. As a result it is often faster to use other instructions on these processors.

TBM (Trailing Bit Manipulation) TBM consists of instructions complementary to the instruction set started by BMI1; their complementary nature means they do not necessarily need to be used directly but can be generated by an optimizing compiler when supported. AMD introduced TBM together with BMI1 in its Piledriver line of processors; later AMD Jaguar and Zen-based processors do not support TBM. No Intel processors (through Nova Lake) support TBM.

Supporting CPUs Intel Intel Nehalem processors and newer (like Sandy Bridge, Ivy Bridge) (POPCNT supported) Intel Silvermont processors (POPCNT supported) Intel Haswell processors and newer (like Skylake, Broadwell) (ABM, BMI1 and BMI2 supported) AMD K10-based processors (ABM supported) "Cat" low-power processors Bobcat-based processors (ABM supported) Jaguar-based processors and newer (ABM and BMI1 supported) Puma-based processors and newer (ABM and BMI1 supported) "Heavy Equipment" processors Bulldozer-based processors (ABM supported) Piledriver-based processors (ABM, BMI1 and TBM supported) Steamroller-based processors (ABM, BMI1 and TBM supported) Excavator-based processors and newer (ABM, BMI1, BMI2 and TBM supported; microcoded PEXT and PDEP) Zen-based, Zen+-based, and Zen 2-based processors (ABM, BMI1 and BMI2 supported; microcoded PEXT and PDEP) Zen 3 processors and newer (ABM, BMI1 and BMI2 supported; full hardware implementation) Note that instruction extension support means the processor is capable of executing the supported instructions for software compatibility purposes. The processor might not perform well doing so. For example, Excavator through Zen 2 processors implement PEXT and PDEP instructions using microcode resulting in the instructions executing significantly slower than the same behaviour recreated using other instructions. (A software method called "zp7" is, in fact, faster on these machines.) For optimum performance it is recommended that compiler developers choose to use individual instructions in the extensions based on architecture specific performance profiles rather than on extension availability.

See also

References

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with X86 Bit manipulation instruction set

Start with the simplest possible case. Write down what X86 Bit manipulation instruction set claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to X86 Bit manipulation instruction set before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about X86 Bit manipulation instruction set ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of X86 Bit manipulation instruction set

In research
X86 Bit manipulation instruction set appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses X86 Bit manipulation instruction set in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
X86 Bit manipulation instruction set is common in secondary-school and first-year university syllabi. It links to neighbouring topics AMD technologies, Instruction set extensions, X86 instructions, so understanding it makes those chapters shorter.
In everyday life
Look for X86 Bit manipulation instruction set outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “X86 Bit manipulation instruction set” →

How to study X86 Bit manipulation instruction set in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what X86 Bit manipulation instruction set means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain X86 Bit manipulation instruction set out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is X86 Bit manipulation instruction set in simple terms?

Bit manipulation instructions sets (BMI sets) are extensions to the x86 instruction set architecture for microprocessors from Intel and AMD. The purpose of these instruction sets is to improve the speed of bit manipulation.

Why does X86 Bit manipulation instruction set matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study X86 Bit manipulation instruction set?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on X86 Bit manipulation instruction set.

Tags

  • AMD technologies
  • Instruction set extensions
  • X86 instructions

Keep exploring