Intel 64 and IA-32 Architectures. Software Developer’s Manual (Collection, 2023) - page 82

 

  Index      Manuals     Intel 64 and IA-32 Architectures. Software Developer’s Manual (Collection, 2023)

 

Search            copyright infringement  

 

   

 

   

 

Content      ..     80      81      82      83     ..

 

 

 

Intel 64 and IA-32 Architectures. Software Developer’s Manual (Collection, 2023) - page 82

 

 

INSTRUCTION SET REFERENCE, M-U
VPCMPGTB (VEX.256 encoded version)
DEST[127:0] := COMPARE_BYTES_GREATER(SRC1[127:0],SRC2[127:0])
DEST[255:128] := COMPARE_BYTES_GREATER(SRC1[255:128],SRC2[255:128])
DEST[MAXVL-1:256] := 0
VPCMPGTB (EVEX encoded versions)
(KL, VL) = (16, 128), (32, 256), (64, 512)
FOR j := 0 TO KL-1
i := j * 8
IF k2[j] OR *no writemask*
THEN
/* signed comparison */
CMP := SRC1[i+7:i] > SRC2[i+7:i];
IF CMP = TRUE
THEN DEST[j] := 1;
ELSE DEST[j] := 0; FI;
ELSE
DEST[j] := 0
; zeroing-masking onlyFI;
FI;
ENDFOR
DEST[MAX_KL-1:KL] := 0
PCMPGTW (with 64-bit operands)
IF DEST[15:0] > SRC[15:0]
THEN DEST[15:0] := FFFFH;
ELSE DEST[15:0] := 0; FI;
(* Continue comparison of 2nd and 3rd words in DEST and SRC *)
IF DEST[63:48] > SRC[63:48]
THEN DEST[63:48] := FFFFH;
ELSE DEST[63:48] := 0; FI;
PCMPGTW (with 128-bit operands)
DEST[127:0] := COMPARE_WORDS_GREATER(DEST[127:0],SRC[127:0])
DEST[MAXVL-1:128] (Unmodified)
VPCMPGTW (VEX.128 encoded version)
DEST[127:0] := COMPARE_WORDS_GREATER(SRC1,SRC2)
DEST[MAXVL-1:128] := 0
VPCMPGTW (VEX.256 encoded version)
DEST[127:0] := COMPARE_WORDS_GREATER(SRC1[127:0],SRC2[127:0])
DEST[255:128] := COMPARE_WORDS_GREATER(SRC1[255:128],SRC2[255:128])
DEST[MAXVL-1:256] := 0
VPCMPGTW (EVEX encoded versions)
(KL, VL) = (8, 128), (16, 256), (32, 512)
FOR j := 0 TO KL-1
i := j * 16
IF k2[j] OR *no writemask*
THEN
/* signed comparison */
CMP := SRC1[i+15:i] > SRC2[i+15:i];
IF CMP = TRUE
THEN DEST[j] := 1;
ELSE DEST[j] := 0; FI;
PCMPGTB/PCMPGTW/PCMPGTD—Compare Packed Signed Integers for Greater Than
Vol. 2B
4-267
INSTRUCTION SET REFERENCE, M-U
ELSE
DEST[j] := 0
; zeroing-masking onlyFI;
FI;
ENDFOR
DEST[MAX_KL-1:KL] := 0
PCMPGTD (with 64-bit operands)
IF DEST[31:0] > SRC[31:0]
THEN DEST[31:0] := FFFFFFFFH;
ELSE DEST[31:0] := 0; FI;
IF DEST[63:32] > SRC[63:32]
THEN DEST[63:32] := FFFFFFFFH;
ELSE DEST[63:32] := 0; FI;
PCMPGTD (with 128-bit operands)
DEST[127:0] := COMPARE_DWORDS_GREATER(DEST[127:0],SRC[127:0])
DEST[MAXVL-1:128] (Unmodified)
VPCMPGTD (VEX.128 encoded version)
DEST[127:0] := COMPARE_DWORDS_GREATER(SRC1,SRC2)
DEST[MAXVL-1:128] := 0
VPCMPGTD (VEX.256 encoded version)
DEST[127:0] := COMPARE_DWORDS_GREATER(SRC1[127:0],SRC2[127:0])
DEST[255:128] := COMPARE_DWORDS_GREATER(SRC1[255:128],SRC2[255:128])
DEST[MAXVL-1:256] := 0
VPCMPGTD (EVEX encoded versions)
(KL, VL) = (4, 128), (8, 256), (8, 512)
FOR j := 0 TO KL-1
i := j * 32
IF k2[j] OR *no writemask*
THEN
/* signed comparison */
IF (EVEX.b = 1) AND (SRC2 *is memory*)
THEN CMP := SRC1[i+31:i] > SRC2[31:0];
ELSE CMP := SRC1[i+31:i] > SRC2[i+31:i];
FI;
IF CMP = TRUE
THEN DEST[j] := 1;
ELSE DEST[j] := 0; FI;
ELSE
DEST[j] := 0
; zeroing-masking only
FI;
ENDFOR
DEST[MAX_KL-1:KL] := 0
4-268
Vol. 2B
PCMPGTB/PCMPGTW/PCMPGTD—Compare Packed Signed Integers for Greater Than
INSTRUCTION SET REFERENCE, M-U
Intel C/C++ Compiler Intrinsic Equivalents
VPCMPGTB __mmask64 _mm512_cmpgt_epi8_mask(__m512i a, __m512i b);
VPCMPGTB __mmask64 _mm512_mask_cmpgt_epi8_mask(__mmask64 k, __m512i a, __m512i b);
VPCMPGTB __mmask32 _mm256_cmpgt_epi8_mask(__m256i a, __m256i b);
VPCMPGTB __mmask32 _mm256_mask_cmpgt_epi8_mask(__mmask32 k, __m256i a, __m256i b);
VPCMPGTB __mmask16 _mm_cmpgt_epi8_mask(__m128i a, __m128i b);
VPCMPGTB __mmask16 _mm_mask_cmpgt_epi8_mask(__mmask16 k, __m128i a, __m128i b);
VPCMPGTD __mmask16 _mm512_cmpgt_epi32_mask(__m512i a, __m512i b);
VPCMPGTD __mmask16 _mm512_mask_cmpgt_epi32_mask(__mmask16 k, __m512i a, __m512i b);
VPCMPGTD __mmask8 _mm256_cmpgt_epi32_mask(__m256i a, __m256i b);
VPCMPGTD __mmask8 _mm256_mask_cmpgt_epi32_mask(__mmask8 k, __m256i a, __m256i b);
VPCMPGTD __mmask8 _mm_cmpgt_epi32_mask(__m128i a, __m128i b);
VPCMPGTD __mmask8 _mm_mask_cmpgt_epi32_mask(__mmask8 k, __m128i a, __m128i b);
VPCMPGTW __mmask32 _mm512_cmpgt_epi16_mask(__m512i a, __m512i b);
VPCMPGTW __mmask32 _mm512_mask_cmpgt_epi16_mask(__mmask32 k, __m512i a, __m512i b);
VPCMPGTW __mmask16 _mm256_cmpgt_epi16_mask(__m256i a, __m256i b);
VPCMPGTW __mmask16 _mm256_mask_cmpgt_epi16_mask(__mmask16 k, __m256i a, __m256i b);
VPCMPGTW __mmask8 _mm_cmpgt_epi16_mask(__m128i a, __m128i b);
VPCMPGTW __mmask8 _mm_mask_cmpgt_epi16_mask(__mmask8 k, __m128i a, __m128i b);
PCMPGTB:__m64 _mm_cmpgt_pi8 (__m64 m1, __m64 m2)
PCMPGTW:__m64 _mm_cmpgt_pi16 (__m64 m1, __m64 m2)
PCMPGTD:__m64 _mm_cmpgt_pi32 (__m64 m1, __m64 m2)
(V)PCMPGTB:__m128i _mm_cmpgt_epi8 ( __m128i a, __m128i b)
(V)PCMPGTW:__m128i _mm_cmpgt_epi16 ( __m128i a, __m128i b)
(V)DCMPGTD:__m128i _mm_cmpgt_epi32 ( __m128i a, __m128i b)
VPCMPGTB:
__m256i _mm256_cmpgt_epi8 ( __m256i a, __m256i b)
VPCMPGTW:
__m256i _mm256_cmpgt_epi16 ( __m256i a, __m256i b)
VPCMPGTD:
__m256i _mm256_cmpgt_epi32 ( __m256i a, __m256i b)
Flags Affected
None.
Numeric Exceptions
None.
Other Exceptions
Non-EVEX-encoded instruction, see Table 2-21, “Type 4 Class Exception Conditions”.
EVEX-encoded VPCMPGTD, see Table 2-49, “Type E4 Class Exception Conditions”.
EVEX-encoded VPCMPGTB/W, see Exceptions Type E4.nb in Table 2-49, “Type E4 Class Exception Conditions”.
PCMPGTB/PCMPGTW/PCMPGTD—Compare Packed Signed Integers for Greater Than
Vol. 2B
4-269
INSTRUCTION SET REFERENCE, M-U
PCMPGTQ—Compare Packed Data for Greater Than
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
66 0F 38 37 /r
A
V/V
SSE4_2
Compare packed signed qwords in xmm2/m128
PCMPGTQ xmm1,xmm2/m128
and xmm1 for greater than.
VEX.128.66.0F38.WIG 37 /r
B
V/V
AVX
Compare packed signed qwords in xmm2 and
VPCMPGTQ xmm1, xmm2, xmm3/m128
xmm3/m128 for greater than.
VEX.256.66.0F38.WIG 37 /r
B
V/V
AVX2
Compare packed signed qwords in ymm2 and
VPCMPGTQ ymm1, ymm2, ymm3/m256
ymm3/m256 for greater than.
EVEX.128.66.0F38.W1 37 /r
C
V/V
AVX512VL
Compare Greater between int64 vector xmm2 and
VPCMPGTQ k1 {k2}, xmm2,
AVX512F
int64 vector xmm3/m128/m64bcst, and set
xmm3/m128/m64bcst
vector mask k1 to reflect the zero/nonzero status
of each element of the result, under writemask.
EVEX.256.66.0F38.W1 37 /r
C
V/V
AVX512VL
Compare Greater between int64 vector ymm2 and
VPCMPGTQ k1 {k2}, ymm2,
AVX512F
int64 vector ymm3/m256/m64bcst, and set
ymm3/m256/m64bcst
vector mask k1 to reflect the zero/nonzero status
of each element of the result, under writemask.
EVEX.512.66.0F38.W1 37 /r
C
V/V
AVX512F
Compare Greater between int64 vector zmm2 and
VPCMPGTQ k1 {k2}, zmm2, zmm3/m512/m64bcst
int64 vector zmm3/m512/m64bcst, and set
vector mask k1 to reflect the zero/nonzero status
of each element of the result, under writemask.
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
B
N/A
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
C
Full
ModRM:reg (w)
EVEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
Performs an SIMD signed compare for the packed quadwords in the destination operand (first operand) and the
source operand (second operand). If the data element in the first (destination) operand is greater than the
corresponding element in the second (source) operand, the corresponding data element in the destination is set
to all 1s; otherwise, it is set to 0s.
128-bit Legacy SSE version: The second source operand can be an XMM register or a 128-bit memory location. The
first source operand and destination operand are XMM registers. Bits (MAXVL-1:128) of the corresponding YMM
destination register remain unchanged.
VEX.128 encoded version: The second source operand can be an XMM register or a 128-bit memory location. The
first source operand and destination operand are XMM registers. Bits (MAXVL-1:128) of the corresponding YMM
register are zeroed.
VEX.256 encoded version: The first source operand is a YMM register. The second source operand is a YMM register
or a 256-bit memory location. The destination operand is a YMM register.
EVEX encoded VPCMPGTD/Q: The first source operand (second operand) is a ZMM/YMM/XMM register. The second
source operand can be a ZMM/YMM/XMM register, a 512/256/128-bit memory location or a 512/256/128-bit vector
broadcasted from a 64-bit memory location. The destination operand (first operand) is a mask register updated
according to the writemask k2.
4-270
Vol. 2B
PCMPGTQ—Compare Packed Data for Greater Than
INSTRUCTION SET REFERENCE, M-U
Operation
COMPARE_QWORDS_GREATER (SRC1, SRC2)
IF SRC1[63:0] > SRC2[63:0]
THEN DEST[63:0] := FFFFFFFFFFFFFFFFH;
ELSE DEST[63:0] := 0; FI;
IF SRC1[127:64] > SRC2[127:64]
THEN DEST[127:64] := FFFFFFFFFFFFFFFFH;
ELSE DEST[127:64] := 0; FI;
VPCMPGTQ (VEX.128 encoded version)
DEST[127:0] := COMPARE_QWORDS_GREATER(SRC1,SRC2)
DEST[MAXVL-1:128] := 0
VPCMPGTQ (VEX.256 encoded version)
DEST[127:0] := COMPARE_QWORDS_GREATER(SRC1[127:0],SRC2[127:0])
DEST[255:128] := COMPARE_QWORDS_GREATER(SRC1[255:128],SRC2[255:128])
DEST[MAXVL-1:256] := 0
VPCMPGTQ (EVEX encoded versions)
(KL, VL) = (2, 128), (4, 256), (8, 512)
FOR j := 0 TO KL-1
i := j * 64
IF k2[j] OR *no writemask*
THEN
/* signed comparison */
IF (EVEX.b = 1) AND (SRC2 *is memory*)
THEN CMP := SRC1[i+63:i] > SRC2[63:0];
ELSE CMP := SRC1[i+63:i] > SRC2[i+63:i];
FI;
IF CMP = TRUE
THEN DEST[j] := 1;
ELSE DEST[j] := 0; FI;
ELSE
DEST[j] := 0
; zeroing-masking only
FI;
ENDFOR
DEST[MAX_KL-1:KL] := 0
Intel C/C++ Compiler Intrinsic Equivalent
VPCMPGTQ __mmask8 _mm512_cmpgt_epi64_mask( __m512i a, __m512i b);
VPCMPGTQ __mmask8 _mm512_mask_cmpgt_epi64_mask(__mmask8 k, __m512i a, __m512i b);
VPCMPGTQ __mmask8 _mm256_cmpgt_epi64_mask( __m256i a, __m256i b);
VPCMPGTQ __mmask8 _mm256_mask_cmpgt_epi64_mask(__mmask8 k, __m256i a, __m256i b);
VPCMPGTQ __mmask8 _mm_cmpgt_epi64_mask( __m128i a, __m128i b);
VPCMPGTQ __mmask8 _mm_mask_cmpgt_epi64_mask(__mmask8 k, __m128i a, __m128i b);
(V)PCMPGTQ:
__m128i _mm_cmpgt_epi64(__m128i a, __m128i b)
VPCMPGTQ:
__m256i _mm256_cmpgt_epi64( __m256i a, __m256i b);
Flags Affected
None.
SIMD Floating-Point Exceptions
None.
PCMPGTQ—Compare Packed Data for Greater Than
Vol. 2B
4-271
INSTRUCTION SET REFERENCE, M-U
Other Exceptions
Non-EVEX-encoded instruction, see Table 2-21, “Type 4 Class Exception Conditions”.
EVEX-encoded VPCMPGTQ, see Table 2-49, “Type E4 Class Exception Conditions”.
4-272
Vol. 2B
PCMPGTQ—Compare Packed Data for Greater Than
INSTRUCTION SET REFERENCE, M-U
PCMPISTRI—Packed Compare Implicit Length Strings, Return Index
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
66 0F 3A 63 /r imm8
RM
V/V
SSE4_2
Perform a packed comparison of string data
PCMPISTRI xmm1, xmm2/m128, imm8
with implicit lengths, generating an index, and
storing the result in ECX.
VEX.128.66.0F3A.WIG 63 /r ib
RM
V/V
AVX
Perform a packed comparison of string data
VPCMPISTRI xmm1, xmm2/m128, imm8
with implicit lengths, generating an index, and
storing the result in ECX.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (r)
ModRM:r/m (r)
imm8
N/A
Description
The instruction compares data from two strings based on the encoded value in the imm8 control byte (see Section
4.1, “Imm8 Control Byte Operation for PCMPESTRI / PCMPESTRM / PCMPISTRI / PCMPISTRM”), and generates an
index stored to ECX.
Each string is represented by a single value. The value is an xmm (or possibly m128 for the second operand) which
contains the data elements of the string (byte or word data). Each input byte/word is augmented with a
valid/invalid tag. A byte/word is considered valid only if it has a lower index than the least significant null
byte/word. (The least significant null byte/word is also considered invalid.)
The comparison and aggregation operations are performed according to the encoded value of imm8 bit fields (see
Section 4.1). The index of the first (or last, according to imm8[6]) set bit of IntRes2 is returned in ECX. If no bits
are set in IntRes2, ECX is set to 16 (8).
Note that the Arithmetic Flags are written in a non-standard manner in order to supply the most relevant informa-
tion:
CFlag - Reset if IntRes2 is equal to zero, set otherwise
ZFlag - Set if any byte/word of xmm2/mem128 is null, reset otherwise
SFlag - Set if any byte/word of xmm1 is null, reset otherwise
OFlag -IntRes2[0]
AFlag - Reset
PFlag - Reset
Note: In VEX.128 encoded version, VEX.vvvv is reserved and must be 1111b, VEX.L must be 0, otherwise the
instruction will #UD.
Effective Operand Size
Operating mode/size
Operand 1
Operand 2
Result
16 bit
xmm
xmm/m128
ECX
32 bit
xmm
xmm/m128
ECX
64 bit
xmm
xmm/m128
ECX
Intel C/C++ Compiler Intrinsic Equivalent For Returning Index
int
_mm_cmpistri (__m128i a, __m128i b, const int mode);
PCMPISTRI—Packed Compare Implicit Length Strings, Return Index
Vol. 2B
4-273
INSTRUCTION SET REFERENCE, M-U
Intel C/C++ Compiler Intrinsics For Reading EFlag Results
int
_mm_cmpistra (__m128i a, __m128i b, const int mode);
int
_mm_cmpistrc (__m128i a, __m128i b, const int mode);
int
_mm_cmpistro (__m128i a, __m128i b, const int mode);
int
_mm_cmpistrs (__m128i a, __m128i b, const int mode);
int
_mm_cmpistrz (__m128i a, __m128i b, const int mode);
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally, this instruction does not cause #GP if the
memory operand is not aligned to 16 Byte boundary, and:
#UD
If VEX.L = 1.
If VEX.vvvv ≠ 1111B.
4-274
Vol. 2B
PCMPISTRI—Packed Compare Implicit Length Strings, Return Index
INSTRUCTION SET REFERENCE, M-U
PCMPISTRM—Packed Compare Implicit Length Strings, Return Mask
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
66 0F 3A 62 /r imm8
RM
V/V
SSE4_2
Perform a packed comparison of string data
PCMPISTRM xmm1, xmm2/m128, imm8
with implicit lengths, generating a mask, and
storing the result in XMM0.
VEX.128.66.0F3A.WIG 62 /r ib
RM
V/V
AVX
Perform a packed comparison of string data
VPCMPISTRM xmm1, xmm2/m128, imm8
with implicit lengths, generating a Mask, and
storing the result in XMM0.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (r)
ModRM:r/m (r)
imm8
N/A
Description
The instruction compares data from two strings based on the encoded value in the imm8 byte (see Section 4.1,
“Imm8 Control Byte Operation for PCMPESTRI / PCMPESTRM / PCMPISTRI / PCMPISTRM”) generating a mask
stored to XMM0.
Each string is represented by a single value. The value is an xmm (or possibly m128 for the second operand) which
contains the data elements of the string (byte or word data). Each input byte/word is augmented with a
valid/invalid tag. A byte/word is considered valid only if it has a lower index than the least significant null
byte/word. (The least significant null byte/word is also considered invalid.)
The comparison and aggregation operation are performed according to the encoded value of imm8 bit fields (see
Section 4.1). As defined by imm8[6], IntRes2 is then either stored to the least significant bits of XMM0 (zero
extended to 128 bits) or expanded into a byte/word-mask and then stored to XMM0.
Note that the Arithmetic Flags are written in a non-standard manner in order to supply the most relevant informa-
tion:
CFlag - Reset if IntRes2 is equal to zero, set otherwise
ZFlag - Set if any byte/word of xmm2/mem128 is null, reset otherwise
SFlag - Set if any byte/word of xmm1 is null, reset otherwise
OFlag - IntRes2[0]
AFlag - Reset
PFlag - Reset
Note: In VEX.128 encoded versions, bits (MAXVL-1:128) of XMM0 are zeroed. VEX.vvvv is reserved and must be
1111b, VEX.L must be 0, otherwise the instruction will #UD.
Effective Operand Size
Operating mode/size
Operand 1
Operand 2
Result
16 bit
xmm
xmm/m128
XMM0
32 bit
xmm
xmm/m128
XMM0
64 bit
xmm
xmm/m128
XMM0
Intel C/C++ Compiler Intrinsic Equivalent For Returning Mask
__m128i _mm_cmpistrm (__m128i a, __m128i b, const int mode);
PCMPISTRM—Packed Compare Implicit Length Strings, Return Mask
Vol. 2B
4-275
INSTRUCTION SET REFERENCE, M-U
Intel C/C++ Compiler Intrinsics For Reading EFlag Results
int
_mm_cmpistra (__m128i a, __m128i b, const int mode);
int
_mm_cmpistrc (__m128i a, __m128i b, const int mode);
int
_mm_cmpistro (__m128i a, __m128i b, const int mode);
int
_mm_cmpistrs (__m128i a, __m128i b, const int mode);
int
_mm_cmpistrz (__m128i a, __m128i b, const int mode);
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally, this instruction does not cause #GP if the
memory operand is not aligned to 16 Byte boundary, and:
#UD
If VEX.L = 1.
If VEX.vvvv ≠ 1111B.
4-276
Vol. 2B
PCMPISTRM—Packed Compare Implicit Length Strings, Return Mask
INSTRUCTION SET REFERENCE, M-U
PCONFIG—Platform Configuration
Opcode/
Op/
64/32
CPUID Feature
Description
Instruction
En
bit Mode
Flag
Support
NP 0F 01 C5
A
V/V
PCONFIG
This instruction is used to execute functions for
PCONFIG
configuring platform features.
Instruction Operand Encoding
Op/En
Tuple
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
N/A
N/A
N/A
N/A
Description
PCONFIG allows software to configure certain platform features. PCONFIG supports multiple leaf functions, with a
leaf function identified by the value in EAX. The registers RBX, RCX, and RDX may provide input or output informa-
tion for certain leaves. All leaves write status information to EAX but do not modify RBX, RCX, or RDX unless they
are being used as leaf-specific output.
Each PCONFIG leaf function applies to a specific hardware block called a PCONFIG target, and each PCONFIG target
is associated with a numerical target identifier. Supported target identifiers are enumerated, along with other
PCONFIG capabilities, in the sub-leaves of the PCONFIG-information leaf of CPUID (EAX = 1BH). An attempt to
execute an undefined leaf function, or a leaf function that applies to an unsupported target identifier, results in a
general-protection exception (#GP). (In the future, the PCONFIG-information leaf of CPUID may enumerate
PCONFIG capabilities in addition to the supported target identifiers.)
Addresses and operands are 32 bits outside 64-bit mode and are 64 bits in 64-bit mode. The value of CS.D does
not affect operand size or address size.
Table 4-15 shows the leaf encodings for PCONFIG, and Table 4-16 shows the leaf register usage for PCONFIG.
Table 4-15. PCONFIG Leaf Encodings
Leaf
Encoding
Description
MKTME_KEY_PROGRAM
00000000H
This leaf is used to program the key and encryption mode associated
with a KeyID.
RESERVED
00000001H - FFFFFFFFH
Reserved for future use (#GP(0) if used).
Table 4-16. PCONFIG Leaf Register Usage
Leaf
RBX
RCX
RDX
MKTME_KEY_PROGRAM
Input only.
Input only.
Input only.
RESERVED
Reserved for future use.
Reserved for future use.
Reserved for future use.
The MKTME_KEY_PROGRAM leaf of PCONFIG pertains to the MKTME1 target, which has target identifier 1. It is used
by software to manage the key associated with a KeyID. The leaf function is invoked by setting the leaf value of 0
in EAX and the address of MKTME_KEY_PROGRAM_STRUCT in RBX. Successful execution of the leaf clears RAX (set
to zero) and ZF, CF, PF, AF, OF, and SF are cleared. In case of failure, the failure reason is indicated in RAX with ZF
set to 1 and CF, PF, AF, OF, and SF are cleared. The MKTME_KEY_PROGRAM leaf uses the
MKTME_KEY_PROGRAM_STRUCT in memory shown in Table 4-17.
1. Further details on MKTME usage can be found here:
PCONFIG—Platform Configuration
Vol. 2B
4-277
INSTRUCTION SET REFERENCE, M-U
Table 4-17. MKTME_KEY_PROGRAM_STRUCT Format
Field
Offset (bytes)
Size (bytes)
Comments
KEYID
0
2
Key Identifier.
KEYID_CTRL
2
4
KeyID control:
• Bits [7:0]: COMMAND.
• Bits [23:8]: ENC_ALG.
• Bits [31:24]: Reserved, must be zero.
RESERVED
6
58
Reserved, must be zero.
KEY_FIELD_1
64
64
Software supplied KeyID data key or entropy for KeyID data key.
KEY_FIELD_2
128
64
Software supplied KeyID tweak key or entropy for KeyID tweak key.
A description of each of the fields in MKTME_KEY_PROGRAM_STRUCT is provided below:
KEYID: Key Identifier being programmed to the MKTME engine.
KEYID_CTRL: The KEYID_CTRL field carries two sub-fields used by software to control the behavior of a
KeyID: Command and KeyID encryption algorithm.
The command used controls the encryption mode for a KeyID. Table 4-18 provides a summary of the
commands supported.
Table 4-18. Supported Key Programming Commands
Command
Encoding
Description
KEYID_SET_KEY_DIRECT
0
Software uses this mode to directly program a key for use with KeyID.
KEYID_SET_KEY_RANDOM
1
CPU generates and assigns an ephemeral key for use with a KeyID. Each time the
instruction is executed, the CPU generates a new key using a hardware random
number generator and the keys are discarded on reset.
KEYID_CLEAR_KEY
2
Clear the (software programmed) key associated with the KeyID. On execution of this
command, the KeyID gets TME behavior (encrypt with platform TME key or bypass
TME encryption).
KEYID_NO_ENCRYPT
3
Do not encrypt memory when this KeyID is in use.
The encryption algorithm field (ENC_ALG) allows software to select one of the activated encryption algorithms
for the KeyID. The BIOS can activate a set of algorithms to allow for use when programming keys using the
IA32_TME_ACTIVATE MSR (does not apply to KeyID 0 which uses the TME policy when TME encryption is not
bypassed). The processor checks to ensure that the algorithm selected by software is one of the algorithms
that has been activated by the BIOS.
KEY_FIELD_1: This field carries the software supplied data key to be used for the KeyID if the direct key
programming option is used (KEYID_SET_KEY_DIRECT). When the random key programming option is used
(KEYID_SET_KEY_RANDOM), this field carries the software supplied entropy to be mixed in the CPU generated
random data key. It is software's responsibility to ensure that the key supplied for the direct programming
option or the entropy supplied for the random programming option does not result in weak keys. There are no
explicit checks in the instruction to detect or prevent weak keys. When AES XTS-128 is used, the upper 48B are
treated as reserved and must be zeroed out by software before executing the instruction.
KEY_FIELD_2: This field carries the software supplied tweak key to be used for the KeyID if the direct key
programming option is used (KEYID_SET_KEY_DIRECT). When the random key programming option is used
(KEYID_SET_KEY_RANDOM), this field carries the software supplied entropy to be mixed in the CPU generated
random tweak key. It is software's responsibility to ensure that the key supplied for the direct programming
option or the entropy supplied for the random programming option does not result in weak keys. There are no
explicit checks in the instruction to detect or prevent weak keys. When AES XTS-128 is used, the upper 48B are
treated as reserved and must be zeroed out by software before executing the instruction.
All KeyIDs default to TME behavior (encrypt with TME key or bypass encryption) on MKTME activation.
Software can at any point decide to change the key for a KeyID using the PCONFIG instruction. Change of
4-278
Vol. 2B
PCONFIG—Platform Configuration
INSTRUCTION SET REFERENCE, M-U
keys for a KeyID does NOT change the state of the TLB caches or memory pipeline. It is software's responsi-
bility to take appropriate actions to ensure correct behavior.
Table 4-19 shows the return values associated with the MKTME_KEY_PROGRAM leaf of PCONFIG. On
instruction execution, RAX is populated with the return value.
Table 4-19. Supported Key Error Codes
Return Value
Encoding
Description
PROG_SUCCESS
0
KeyID was successfully programmed.
INVALID_PROG_CMD
1
Invalid KeyID programming command.
ENTROPY_ERROR
2
Insufficient entropy.
INVALID_KEYID
3
KeyID not valid.
INVALID_ENC_ALG
4
Invalid encryption algorithm chosen (not supported).
DEVICE_BUSY
5
Failure to access key table.
PCONFIG Concurrency
In a scenario where the MKTME_KEY_PROGRAM leaf of PCONFIG is executed concurrently on multiple logical
processors, only one logical processor will succeed in updating the key table. PCONFIG execution will return with
an error code (DEVICE_BUSY) on other logical processors and software must retry. In cases where the instruction
execution fails with a DEVICE_BUSY error code, the key table is not updated, thereby ensuring that either the key
table is updated in its entirety with the information for a KeyID, or it is not updated at all. In order to accomplish
this, the MKTME_KEY_PROGRAM leaf of PCONFIG maintains a writer lock for updating the key table. This lock is
referred to as the Key table lock and denoted in the instruction flows as KEY_TABLE_LOCK. The lock can either be
unlocked, when no logical processor is holding the lock (also the initial state of the lock) or be in an exclusive state
where a logical processor is trying to update the key table. There can be only one logical processor holding the lock
in exclusive state. The lock, being exclusive, can only be acquired when the lock is in unlocked state.
PCONFIG uses the following syntax to acquire KEY_TABLE_LOCK in exclusive mode and release the lock:
KEY_TABLE_LOCK.ACQUIRE(WRITE)
KEY_TABLE_LOCK.RELEASE()
Operation
Table 4-20. PCONFIG Operation Variables
Variable Name
Type
Size
Description
(Bytes)
TMP_KEY_PROGRAM_STRUCT
MKTME_KEY_PROGRAM_STRUCT
192
Structure holding the key programming structure.
TMP_RND_DATA_KEY
UINT128
16
Random data key generated for random key
programming option.
TMP_RND_TWEAK_KEY
UINT128
16
Random tweak key generated for random key
programming option.
PCONFIG—Platform Configuration
Vol. 2B
4-279
INSTRUCTION SET REFERENCE, M-U
(* #UD if PCONFIG is not enumerated or CPL>0 *)
IF (CPUID.7.0:EDX[18] == 0 OR CPL > 0) #UD;
(* #GP(0) for an unsupported leaf *)
IF (EAX != 0) #GP(0)
(* KEY_PROGRAM leaf flow *)
IF (EAX == 0)
{
(* #GP(0) if TME_ACTIVATE MSR is not locked or does not enable hardware encryption or multiple keys are not enabled *)
IF (IA32_TME_ACTIVATE.LOCK != 1 OR IA32_TME_ACTIVATE.ENABLE != 1 OR IA32_TME_ACTIVATE.MK_TME_KEYID_BITS == 0)
#GP(0)
(* Check MKTME_KEY_PROGRAM_STRUCT is 256B aligned *)
IF (DS:RBX is not 256B aligned) #GP(0);
(* Check that MKTME_KEY_PROGRAM_STRUCT is read accessible *)
<<DS: RBX should be read accessible>>
(* Copy MKTME_KEY_PROGRAM_STRUCT to a temporary variable *)
TMP_KEY_PROGRAM_STRUCT = DS:RBX.*;
(* RSVD field check *)
IF (TMP_KEY_PROGRAM_STRUCT.RSVD != 0) #GP(0);
IF (TMP_KEY_PROGRAM_STRUCT.KEYID_CTRL.RSVD !=0) #GP(0);
IF (TMP_KEY_PROGRAM_STRUCT.KEY_FIELD_1.BYTES[63:16] != 0) #GP(0);
IF (TMP_KEY_PROGRAM_STRUCT.KEY_FIELD_2.BYTES[63:16] != 0) #GP(0);
(* Check for a valid command *)
IF (TMP_KEY_PROGRAM_STRUCT. KEYID_CTRL.COMMAND is not a valid command)
{
RFLAGS.ZF = 1;
RAX = INVALID_PROG_CMD;
goto EXIT;
}
(* Check that the KEYID being operated upon is a valid KEYID *)
IF (TMP_KEY_PROGRAM_STRUCT.KEYID >
2^IA32_TME_ACTIVATE.MK_TME_KEYID_BITS - 1
OR TMP_KEY_PROGRAM_STRUCT.KEYID >
IA32_TME_CAPABILITY.MK_TME_MAX_KEYS
OR TMP_KEY_PROGRAM_STRUCT.KEYID == 0)
{
RFLAGS.ZF = 1;
RAX = INVALID_KEYID;
goto EXIT;
}
(* Check that only one algorithm is requested for the KeyID and it is one of the activated algorithms *)
IF (NUM_BITS(TMP_KEY_PROGRAM_STRUCT.KEYID_CTRL.ENC_ALG) != 1 ||
(TMP_KEY_PROGRAM_STRUCT.KEYID_CTRL.ENC_ALG &
IA32_TME_ACTIVATE. MK_TME_CRYPTO_ALGS == 0))
4-280
Vol. 2B
PCONFIG—Platform Configuration
INSTRUCTION SET REFERENCE, M-U
{
RFLAGS.ZF = 1;
RAX = INVALID_ENC_ALG;
goto EXIT;
}
(* Try to acquire exclusive lock *)
IF (NOT KEY_TABLE_LOCK.ACQUIRE(WRITE))
{
//PCONFIG failure
RFLAGS.ZF = 1;
RAX = DEVICE_BUSY;
goto EXIT;
}
(* Lock is acquired and key table will be updated as per the command
Before this point no changes to the key table are made *)
switch(TMP_KEY_PROGRAM_STRUCT.KEYID_CTRL.COMMAND)
{
case KEYID_SET_KEY_DIRECT:
<<Write
DATA_KEY=TMP_KEY_PROGRAM_STRUCT.KEY_FIELD_1,
TWEAK_KEY=TMP_KEY_PROGRAM_STRUCT.KEY_FIELD_2,
ENCRYPTION_MODE=ENCRYPT_WITH_KEYID_KEY,
to MKTME Key table at index TMP_KEY_PROGRAM_STRUCT.KEYID
>>
break;
case KEYID_SET_KEY_RANDOM:
TMP_RND_DATA_KEY = <<Generate a random key using hardware RNG>>
IF (NOT ENOUGH ENTROPY)
{
RFLAGS.ZF = 1;
RAX = ENTROPY_ERROR;
goto EXIT;
}
TMP_RND_TWEAK_KEY = <<Generate a random key using hardware RNG>>
IF (NOT ENOUGH ENTROPY)
{
RFLAGS.ZF = 1;
RAX = ENTROPY_ERROR;
goto EXIT;
}
(* Mix user supplied entropy to the data key and tweak key *)
TMP_RND_DATA_KEY = TMP_RND_KEY XOR
TMP_KEY_PROGRAM_STRUCT.KEY_FIELD_1.BYTES[15:0];
TMP_RND_TWEAK_KEY = TMP_RND_TWEAK_KEY XOR
TMP_KEY_PROGRAM_STRUCT.KEY_FIELD_2.BYTES[15:0];
<<Write
DATA_KEY=TMP_RND_DATA_KEY,
TWEAK_KEY=TMP_RND_TWEAK_KEY,
ENCRYPTION_MODE=ENCRYPT_WITH_KEYID_KEY,
to MKTME_KEY_TABLE at index TMP_KEY_PROGRAM_STRUCT.KEYID
PCONFIG—Platform Configuration
Vol. 2B
4-281
INSTRUCTION SET REFERENCE, M-U
>>
break;
case KEYID_CLEAR_KEY:
<<Write
DATA_KEY='0,
TWEAK_KEY='0,
ENCRYPTION_MODE = ENCRYPT_WITH_TME_KEY_OR_BYPASS,
to MKTME_KEY_TABLE at index TMP_KEY_PROGRAM_STRUCT.KEYID
>>
break;
case KD_NO_ENCRYPT:
<<Write
ENCRYPTION_MODE=NO_ENCRYPTION,
to MKTME_KEY_TABLE at index TMP_KEY_PROGRAM_STRUCT.KEYID
>>
break;
}
RAX = 0;
RFLAGS.ZF = 0;
//Release Lock
KEY_TABLE_LOCK(RELEASE);
EXIT:
RFLAGS.CF=0;
RFLAGS.PF=0;
RFLAGS.AF=0;
RFLAGS.OF=0;
RFLAGS.SF=0;
}
end_of_flow
Protected Mode Exceptions
#GP(0)
If input value in EAX encodes an unsupported leaf.
If IA32_TME_ACTIVATE MSR is not locked.
If hardware encryption and MKTME capability are not enabled in IA32_TME_ACTIVATE MSR.
If the memory operand is not 256B aligned.
If any of the reserved bits in MKTME_KEY_PROGRAM_STRUCT are set.
If a memory operand effective address is outside the DS segment limit.
#PF(fault-code)
If a page fault occurs in accessing memory operands.
#UD
If any of the LOCK/REP/OSIZE/VEX prefixes are used.
If current privilege level is not 0.
If CPUID.7.0:EDX[bit 18] = 0
4-282
Vol. 2B
PCONFIG—Platform Configuration
INSTRUCTION SET REFERENCE, M-U
Real-Address Mode Exceptions
#GP
If input value in EAX encodes an unsupported leaf.
If IA32_TME_ACTIVATE MSR is not locked.
If hardware encryption and MKTME capability are not enabled in IA32_TME_ACTIVATE MSR.
If a memory operand is not 256B aligned.
If any of the reserved bits in MKTME_KEY_PROGRAM_STRUCT are set.
#UD
If any of the LOCK/REP/OSIZE/VEX prefixes are used.
If current privilege level is not 0.
If CPUID.7.0:EDX.PCONFIG[bit 18] = 0
Virtual-8086 Mode Exceptions
#UD
PCONFIG instruction is not recognized in virtual-8086 mode.
Compatibility Mode Exceptions
Same exceptions as in protected mode.
64-Bit Mode Exceptions
#GP(0)
If input value in EAX encodes an unsupported leaf.
If IA32_TME_ACTIVATE MSR is not locked.
If hardware encryption and MKTME capability are not enabled in IA32_TME_ACTIVATE MSR.
If a memory operand is not 256B aligned.
If any of the reserved bits in MKTME_KEY_PROGRAM_STRUCT are set.
If a memory operand is non-canonical form.
#PF(fault-code)
If a page fault occurs in accessing memory operands.
#UD
If any of the LOCK/REP/OSIZE/VEX prefixes are used.
If the current privilege level is not 0.
If CPUID.7.0:EDX.PCONFIG[bit 18] = 0.
PCONFIG—Platform Configuration
Vol. 2B
4-283
INSTRUCTION SET REFERENCE, M-U
PDEP—Parallel Bits Deposit
Opcode/
Op/
64/32
CPUID
Description
Instruction
En
-bit
Feature
Mode
Flag
VEX.LZ.F2.0F38.W0 F5 /r
RVM
V/V
BMI2
Parallel deposit of bits from r32b using mask in r/m32, result is writ-
PDEP r32a, r32b, r/m32
ten to r32a.
VEX.LZ.F2.0F38.W1 F5 /r
RVM
V/N.E.
BMI2
Parallel deposit of bits from r64b using mask in r/m64, result is writ-
PDEP r64a, r64b, r/m64
ten to r64a.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RVM
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
PDEP uses a mask in the second source operand (the third operand) to transfer/scatter contiguous low order bits in
the first source operand (the second operand) into the destination (the first operand). PDEP takes the low bits from
the first source operand and deposit them in the destination operand at the corresponding bit locations that are set
in the second source operand (mask). All other bits (bits not set in mask) in destination are set to zero.
SRC1
S31
S30
S29 S28
S27
S7
S6
S5
S4
S3
S2
S1
S
0
SRC2
0
0
0
1
0
1
0
1
0
0
1
0
0
(mask)
DEST
0
0
0
S3
0
S2
0
S1
0
0
S0
0
0
bit 0
bit 31
Figure 4-8. PDEP Example
This instruction is not supported in real mode and virtual-8086 mode. The operand size is always 32 bits if not in
64-bit mode. In 64-bit mode operand size 64 requires VEX.W1. VEX.W1 is ignored in non-64-bit modes. An attempt
to execute this instruction with VEX.L not equal to 0 will cause #UD.
Operation
TEMP := SRC1;
MASK := SRC2;
DEST := 0 ;
m := 0, k := 0;
DO WHILE m < OperandSize
IF MASK[ m] = 1 THEN
DEST[ m] := TEMP[ k];
k := k+ 1;
FI
m := m+ 1;
OD
4-284
Vol. 2B
PDEP—Parallel Bits Deposit
INSTRUCTION SET REFERENCE, M-U
Flags Affected
None.
Intel C/C++ Compiler Intrinsic Equivalent
PDEP:
unsigned __int32 _pdep_u32(unsigned __int32 src, unsigned __int32 mask);
PDEP:
unsigned __int64 _pdep_u64(unsigned __int64 src, unsigned __int32 mask);
SIMD Floating-Point Exceptions
None
Other Exceptions
See Table 2-29, “Type 13 Class Exception Conditions”.
PDEP—Parallel Bits Deposit
Vol. 2B
4-285
INSTRUCTION SET REFERENCE, M-U
PEXT—Parallel Bits Extract
Opcode/
Op/
64/32
CPUID
Description
Instruction
En
-bit
Feature
Mode
Flag
VEX.LZ.F3.0F38.W0 F5 /r
RVM
V/V
BMI2
Parallel extract of bits from r32b using mask in r/m32, result is writ-
PEXT r32a, r32b, r/m32
ten to r32a.
VEX.LZ.F3.0F38.W1 F5 /r
RVM
V/N.E.
BMI2
Parallel extract of bits from r64b using mask in r/m64, result is writ-
PEXT r64a, r64b, r/m64
ten to r64a.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RVM
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
PEXT uses a mask in the second source operand (the third operand) to transfer either contiguous or non-contig-
uous bits in the first source operand (the second operand) to contiguous low order bit positions in the destination
(the first operand). For each bit set in the MASK, PEXT extracts the corresponding bits from the first source operand
and writes them into contiguous lower bits of destination operand. The remaining upper bits of destination are
zeroed.
SRC1
S31
S30
S29 S28
S27
S7
S6
S5
S4
S3
S2
S1
S0
SRC2
0
0
0
1
0
1
0
1
0
0
1
0
0
(mask)
DEST
0
0
0
0
0
0
0
0
0
S28
S7
S5
S2
bit 0
bit 31
Figure 4-9. PEXT Example
This instruction is not supported in real mode and virtual-8086 mode. The operand size is always 32 bits if not in
64-bit mode. In 64-bit mode operand size 64 requires VEX.W1. VEX.W1 is ignored in non-64-bit modes. An attempt
to execute this instruction with VEX.L not equal to 0 will cause #UD.
4-286
Vol. 2B
PEXT—Parallel Bits Extract
INSTRUCTION SET REFERENCE, M-U
Operation
TEMP := SRC1;
MASK := SRC2;
DEST := 0 ;
m := 0, k := 0;
DO WHILE m < OperandSize
IF MASK[ m] = 1 THEN
DEST[ k] := TEMP[ m];
k := k+ 1;
FI
m := m+ 1;
OD
Flags Affected
None.
Intel C/C++ Compiler Intrinsic Equivalent
PEXT:
unsigned __int32 _pext_u32(unsigned __int32 src, unsigned __int32 mask);
PEXT:
unsigned __int64 _pext_u64(unsigned __int64 src, unsigned __int32 mask);
SIMD Floating-Point Exceptions
None
Other Exceptions
See Table 2-29, “Type 13 Class Exception Conditions”.
PEXT—Parallel Bits Extract
Vol. 2B
4-287
INSTRUCTION SET REFERENCE, M-U
PEXTRB/PEXTRD/PEXTRQ—Extract Byte/Dword/Qword
Opcode/
Op/ En
64/32 bit
CPUID
Description
Instruction
Mode
Feature
Support
Flag
66 0F 3A 14 /r ib
A
V/V
SSE4_1
Extract a byte integer value from xmm2 at the
PEXTRB reg/m8, xmm2, imm8
source byte offset specified by imm8 into reg or
m8. The upper bits of r32 or r64 are zeroed.
66 0F 3A 16 /r ib
A
V/V
SSE4_1
Extract a dword integer value from xmm2 at the
PEXTRD r/m32, xmm2, imm8
source dword offset specified by imm8 into r/m32.
66 REX.W 0F 3A 16 /r ib
A
V/N.E.
SSE4_1
Extract a qword integer value from xmm2 at the
PEXTRQ r/m64, xmm2, imm8
source qword offset specified by imm8 into r/m64.
VEX.128.66.0F3A.W0 14 /r ib
A
V1/V
AVX
Extract a byte integer value from xmm2 at the
VPEXTRB reg/m8, xmm2, imm8
source byte offset specified by imm8 into reg or
m8. The upper bits of r64/r32 is filled with zeros.
VEX.128.66.0F3A.W0 16 /r ib
A
V/V
AVX
Extract a dword integer value from xmm2 at the
VPEXTRD r32/m32, xmm2, imm8
source dword offset specified by imm8 into
r32/m32.
VEX.128.66.0F3A.W1 16 /r ib
A
V/I2
AVX
Extract a qword integer value from xmm2 at the
VPEXTRQ r64/m64, xmm2, imm8
source dword offset specified by imm8 into
r64/m64.
EVEX.128.66.0F3A.WIG 14 /r ib
B
V/V
AVX512BW
Extract a byte integer value from xmm2 at the
VPEXTRB reg/m8, xmm2, imm8
source byte offset specified by imm8 into reg or
m8. The upper bits of r64/r32 is filled with zeros.
EVEX.128.66.0F3A.W0 16 /r ib
B
V/V
AVX512DQ
Extract a dword integer value from xmm2 at the
VPEXTRD r32/m32, xmm2, imm8
source dword offset specified by imm8 into
r32/m32.
EVEX.128.66.0F3A.W1 16 /r ib
B
V/N.E.2
AVX512DQ
Extract a qword integer value from xmm2 at the
VPEXTRQ r64/m64, xmm2, imm8
source dword offset specified by imm8 into
r64/m64.
NOTES:
1. In 64-bit mode, VEX.W1 is ignored for VPEXTRB (similar to legacy REX.W=1 prefix in PEXTRB).
2. VEX.W/EVEX.W in non-64 bit is ignored; the instructions behaves as if the W0 version is used.
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:r/m (w)
ModRM:reg (r)
imm8
N/A
B
Tuple1 Scalar
ModRM:r/m (w)
ModRM:reg (r)
imm8
N/A
Description
Extract a byte/dword/qword integer value from the source XMM register at a byte/dword/qword offset determined
from imm8[3:0]. The destination can be a register or byte/dword/qword memory location. If the destination is a
register, the upper bits of the register are zero extended.
In legacy non-VEX encoded version and if the destination operand is a register, the default operand size in 64-bit
mode for PEXTRB/PEXTRD is 64 bits, the bits above the least significant byte/dword data are filled with zeros.
PEXTRQ is not encodable in non-64-bit modes and requires REX.W in 64-bit mode.
Note: In VEX.128 encoded versions, VEX.vvvv is reserved and must be 1111b, VEX.L must be 0, otherwise the
instruction will #UD. In EVEX.128 encoded versions, EVEX.vvvv is reserved and must be 1111b, EVEX.L”L must be
0, otherwise the instruction will #UD. If the destination operand is a register, the default operand size in 64-bit
mode for VPEXTRB/VPEXTRD is 64 bits, the bits above the least significant byte/word/dword data are filled with
zeros.
4-288
Vol. 2B
PEXTRB/PEXTRD/PEXTRQ—Extract Byte/Dword/Qword
INSTRUCTION SET REFERENCE, M-U
Operation
CASE of
PEXTRB: SEL := COUNT[3:0];
TEMP := (Src >> SEL*8) AND FFH;
IF (DEST = Mem8)
THEN
Mem8 := TEMP[7:0];
ELSE IF (64-Bit Mode and 64-bit register selected)
THEN
R64[7:0] := TEMP[7:0];
r64[63:8] := ZERO_FILL; };
ELSE
R32[7:0] := TEMP[7:0];
r32[31:8] := ZERO_FILL; };
FI;
PEXTRD:SEL := COUNT[1:0];
TEMP := (Src >> SEL*32) AND FFFF_FFFFH;
DEST := TEMP;
PEXTRQ: SEL := COUNT[0];
TEMP := (Src >> SEL*64);
DEST := TEMP;
EASC:
VPEXTRTD/VPEXTRQ
IF (64-Bit Mode and 64-bit dest operand)
THEN
Src_Offset := imm8[0]
r64/m64 := (Src >> Src_Offset * 64)
ELSE
Src_Offset := imm8[1:0]
r32/m32 := ((Src >> Src_Offset *32) AND 0FFFFFFFFh);
FI
VPEXTRB ( dest=m8)
SRC_Offset := imm8[3:0]
Mem8 := (Src >> Src_Offset*8)
VPEXTRB ( dest=reg)
IF (64-Bit Mode )
THEN
SRC_Offset := imm8[3:0]
DEST[7:0] := ((Src >> Src_Offset*8) AND 0FFh)
DEST[63:8] := ZERO_FILL;
ELSE
SRC_Offset := imm8[3:0];
DEST[7:0] := ((Src >> Src_Offset*8) AND 0FFh);
DEST[31:8] := ZERO_FILL;
FI
PEXTRB/PEXTRD/PEXTRQ—Extract Byte/Dword/Qword
Vol. 2B
4-289
INSTRUCTION SET REFERENCE, M-U
Intel C/C++ Compiler Intrinsic Equivalent
PEXTRB:
int _mm_extract_epi8 (__m128i src, const int ndx);
PEXTRD:
int _mm_extract_epi32 (__m128i src, const int ndx);
PEXTRQ:
__int64 _mm_extract_epi64 (__m128i src, const int ndx);
Flags Affected
None.
SIMD Floating-Point Exceptions
None.
Other Exceptions
Non-EVEX-encoded instruction, see Table 2-22, “Type 5 Class Exception Conditions”.
EVEX-encoded instruction, see Table 2-57, “Type E9NF Class Exception Conditions”.
Additionally:
#UD
If VEX.L = 1 or EVEX.L’L > 0.
If VEX.vvvv != 1111B or EVEX.vvvv != 1111B.
4-290
Vol. 2B
PEXTRB/PEXTRD/PEXTRQ—Extract Byte/Dword/Qword
INSTRUCTION SET REFERENCE, M-U
PEXTRW—Extract Word
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature Flag
Support
NP 0F C5 /r ib1
A
V/V
SSE
Extract the word specified by imm8 from mm and
move it to reg, bits 15-0. The upper bits of r32 or
PEXTRW reg, mm, imm8
r64 is zeroed.
66 0F C5 /r ib
A
V/V
SSE2
Extract the word specified by imm8 from xmm
and move it to reg, bits 15-0. The upper bits of
PEXTRW reg, xmm, imm8
r32 or r64 is zeroed.
66 0F 3A 15 /r ib
B
V/V
SSE4_1
Extract the word specified by imm8 from xmm
PEXTRW reg/m16, xmm, imm8
and copy it to lowest 16 bits of reg or m16. Zero-
extend the result in the destination, r32 or r64.
VEX.128.66.0F.W0 C5 /r ib
A
V2/V
AVX
Extract the word specified by imm8 from xmm1
VPEXTRW reg, xmm1, imm8
and move it to reg, bits 15:0. Zero-extend the
result. The upper bits of r64/r32 is filled with
zeros.
VEX.128.66.0F3A.W0 15 /r ib
B
V/V
AVX
Extract a word integer value from xmm2 at the
VPEXTRW reg/m16, xmm2, imm8
source word offset specified by imm8 into reg or
m16. The upper bits of r64/r32 is filled with zeros.
EVEX.128.66.0F.WIG C5 /r ib
A
V/V
AVX512BW
Extract the word specified by imm8 from xmm1
VPEXTRW reg, xmm1, imm8
and move it to reg, bits 15:0. Zero-extend the
result. The upper bits of r64/r32 is filled with
zeros.
EVEX.128.66.0F3A.WIG 15 /r ib
C
V/V
AVX512BW
Extract a word integer value from xmm2 at the
VPEXTRW reg/m16, xmm2, imm8
source word offset specified by imm8 into reg or
m16. The upper bits of r64/r32 is filled with zeros.
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX
Registers” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
2. In 64-bit mode, VEX.W1 is ignored for VPEXTRW (similar to legacy REX.W=1 prefix in PEXTRW).
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:reg (w)
ModRM:r/m (r)
imm8
N/A
B
N/A
ModRM:r/m (w)
ModRM:reg (r)
imm8
N/A
C
Tuple1 Scalar
ModRM:r/m (w)
ModRM:reg (r)
imm8
N/A
Description
Copies the word in the source operand (second operand) specified by the count operand (third operand) to the
destination operand (first operand). The source operand can be an MMX technology register or an XMM register.
The destination operand can be the low word of a general-purpose register or a 16-bit memory address. The count
operand is an 8-bit immediate. When specifying a word location in an MMX technology register, the 2 least-signifi-
cant bits of the count operand specify the location; for an XMM register, the 3 least-significant bits specify the loca-
tion. The content of the destination register above bit 16 is cleared (set to all 0s).
In 64-bit mode, using a REX prefix in the form of REX.R permits this instruction to access additional registers
(XMM8-XMM15, R8-15). If the destination operand is a general-purpose register, the default operand size is 64-bits
in 64-bit mode.
PEXTRW—Extract Word
Vol. 2B
4-291
INSTRUCTION SET REFERENCE, M-U
Note: In VEX.128 encoded versions, VEX.vvvv is reserved and must be 1111b, VEX.L must be 0, otherwise the
instruction will #UD. In EVEX.128 encoded versions, EVEX.vvvv is reserved and must be 1111b, EVEX.L must be 0,
otherwise the instruction will #UD. If the destination operand is a register, the default operand size in 64-bit mode
for VPEXTRW is 64 bits, the bits above the least significant byte/word/dword data are filled with zeros.
Operation
IF (DEST = Mem16)
THEN
SEL := COUNT[2:0];
TEMP := (Src >> SEL*16) AND FFFFH;
Mem16 := TEMP[15:0];
ELSE IF (64-Bit Mode and destination is a general-purpose register)
THEN
FOR (PEXTRW instruction with 64-bit source operand)
{ SEL := COUNT[1:0];
TEMP := (SRC >> (SEL 16)) AND FFFFH;
r64[15:0] := TEMP[15:0];
r64[63:16] := ZERO_FILL; };
FOR (PEXTRW instruction with 128-bit source operand)
{ SEL := COUNT[2:0];
TEMP := (SRC >> (SEL 16)) AND FFFFH;
r64[15:0] := TEMP[15:0];
r64[63:16] := ZERO_FILL; }
ELSE
FOR (PEXTRW instruction with 64-bit source operand)
{ SEL := COUNT[1:0];
TEMP := (SRC >> (SEL 16)) AND FFFFH;
r32[15:0] := TEMP[15:0];
r32[31:16] := ZERO_FILL; };
FOR (PEXTRW instruction with 128-bit source operand)
{ SEL := COUNT[2:0];
TEMP := (SRC >> (SEL 16)) AND FFFFH;
r32[15:0] := TEMP[15:0];
r32[31:16] := ZERO_FILL; };
FI;
FI;
VPEXTRW ( dest=m16)
SRC_Offset := imm8[2:0]
Mem16 := (Src >> Src_Offset*16)
4-292
Vol. 2B
PEXTRW—Extract Word
INSTRUCTION SET REFERENCE, M-U
VPEXTRW ( dest=reg)
IF (64-Bit Mode )
THEN
SRC_Offset := imm8[2:0]
DEST[15:0] := ((Src >> Src_Offset*16) AND 0FFFFh)
DEST[63:16] := ZERO_FILL;
ELSE
SRC_Offset := imm8[2:0]
DEST[15:0] := ((Src >> Src_Offset*16) AND 0FFFFh)
DEST[31:16] := ZERO_FILL;
FI
Intel C/C++ Compiler Intrinsic Equivalent
PEXTRW:
int _mm_extract_pi16 (__m64 a, int n)
PEXTRW:
int _mm_extract_epi16 ( __m128i a, int imm)
Flags Affected
None.
Numeric Exceptions
None.
Other Exceptions
Non-EVEX-encoded instruction, see Table 2-22, “Type 5 Class Exception Conditions”.
EVEX-encoded instruction, see Table 2-57, “Type E9NF Class Exception Conditions”.
Additionally:
#UD
If VEX.L = 1 or EVEX.L’L > 0.
If VEX.vvvv != 1111B or EVEX.vvvv != 1111B.
PEXTRW—Extract Word
Vol. 2B
4-293
INSTRUCTION SET REFERENCE, M-U
PHADDW/PHADDD—Packed Horizontal Add
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
NP 0F 38 01 /r1
RM
V/V
SSSE3
Add 16-bit integers horizontally, pack to mm1.
PHADDW mm1, mm2/m64
66 0F 38 01 /r
RM
V/V
SSSE3
Add 16-bit integers horizontally, pack to
xmm1.
PHADDW xmm1, xmm2/m128
NP 0F 38 02 /r
RM
V/V
SSSE3
Add 32-bit integers horizontally, pack to mm1.
PHADDD mm1, mm2/m64
66 0F 38 02 /r
RM
V/V
SSSE3
Add 32-bit integers horizontally, pack to
xmm1.
PHADDD xmm1, xmm2/m128
VEX.128.66.0F38.WIG 01 /r
RVM
V/V
AVX
Add 16-bit integers horizontally, pack to
xmm1.
VPHADDW xmm1, xmm2, xmm3/m128
VEX.128.66.0F38.WIG 02 /r
RVM
V/V
AVX
Add 32-bit integers horizontally, pack to
xmm1.
VPHADDD xmm1, xmm2, xmm3/m128
VEX.256.66.0F38.WIG 01 /r
RVM
V/V
AVX2
Add 16-bit signed integers horizontally, pack
to ymm1.
VPHADDW ymm1, ymm2, ymm3/m256
VEX.256.66.0F38.WIG 02 /r
RVM
V/V
AVX2
Add 32-bit signed integers horizontally, pack
to ymm1.
VPHADDD ymm1, ymm2, ymm3/m256
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX Reg-
isters” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
RVM
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
(V)PHADDW adds two adjacent 16-bit signed integers horizontally from the source and destination operands and
packs the 16-bit signed results to the destination operand (first operand). (V)PHADDD adds two adjacent 32-bit
signed integers horizontally from the source and destination operands and packs the 32-bit signed results to the
destination operand (first operand). When the source operand is a 128-bit memory operand, the operand must be
aligned on a 16-byte boundary or a general-protection exception (#GP) will be generated.
Note that these instructions can operate on either unsigned or signed (two’s complement notation) integers;
however, it does not set bits in the EFLAGS register to indicate overflow and/or a carry. To prevent undetected over-
flow conditions, software must control the ranges of the values operated on.
Legacy SSE instructions: Both operands can be MMX registers. The second source operand can be an MMX register
or a 64-bit memory location.
128-bit Legacy SSE version: The first source and destination operands are XMM registers. The second source
operand can be an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding YMM
destination register remain unchanged.
In 64-bit mode, use the REX prefix to access additional registers.
4-294
Vol. 2B
PHADDW/PHADDD—Packed Horizontal Add
INSTRUCTION SET REFERENCE, M-U
VEX.128 encoded version: The first source and destination operands are XMM registers. The second source
operand can be an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding YMM
register are zeroed.
VEX.256 encoded version: Horizontal addition of two adjacent data elements of the low 16-bytes of the first and
second source operands are packed into the low 16-bytes of the destination operand. Horizontal addition of two
adjacent data elements of the high 16-bytes of the first and second source operands are packed into the high 16-
bytes of the destination operand. The first source and destination operands are YMM registers. The second source
operand can be an YMM register or a 256-bit memory location.
SRC2
Y7
Y6
Y5
Y4
Y3
Y2
Y1
Y0
X7
X6
X5
X4
X3
X2
X1
X0
SRC1
S7
S3
S3
S4
S3
S2
S1
S0
255
0
Dest
Figure 4-10. 256-bit VPHADDD Instruction Operation
Operation
PHADDW (with 64-bit operands)
mm1[15-0] = mm1[31-16] + mm1[15-0];
mm1[31-16] = mm1[63-48] + mm1[47-32];
mm1[47-32] = mm2/m64[31-16] + mm2/m64[15-0];
mm1[63-48] = mm2/m64[63-48] + mm2/m64[47-32];
PHADDW (with 128-bit operands)
xmm1[15-0] = xmm1[31-16] + xmm1[15-0];
xmm1[31-16] = xmm1[63-48] + xmm1[47-32];
xmm1[47-32] = xmm1[95-80] + xmm1[79-64];
xmm1[63-48] = xmm1[127-112] + xmm1[111-96];
xmm1[79-64] = xmm2/m128[31-16] + xmm2/m128[15-0];
xmm1[95-80] = xmm2/m128[63-48] + xmm2/m128[47-32];
xmm1[111-96] = xmm2/m128[95-80] + xmm2/m128[79-64];
xmm1[127-112] = xmm2/m128[127-112] + xmm2/m128[111-96];
VPHADDW (VEX.128 encoded version)
DEST[15:0] := SRC1[31:16] + SRC1[15:0]
DEST[31:16] := SRC1[63:48] + SRC1[47:32]
DEST[47:32] := SRC1[95:80] + SRC1[79:64]
DEST[63:48] := SRC1[127:112] + SRC1[111:96]
DEST[79:64] := SRC2[31:16] + SRC2[15:0]
DEST[95:80] := SRC2[63:48] + SRC2[47:32]
DEST[111:96] := SRC2[95:80] + SRC2[79:64]
DEST[127:112] := SRC2[127:112] + SRC2[111:96]
DEST[MAXVL-1:128] := 0
PHADDW/PHADDD—Packed Horizontal Add
Vol. 2B
4-295
INSTRUCTION SET REFERENCE, M-U
VPHADDW (VEX.256 encoded version)
DEST[15:0] := SRC1[31:16] + SRC1[15:0]
DEST[31:16] := SRC1[63:48] + SRC1[47:32]
DEST[47:32] := SRC1[95:80] + SRC1[79:64]
DEST[63:48] := SRC1[127:112] + SRC1[111:96]
DEST[79:64] := SRC2[31:16] + SRC2[15:0]
DEST[95:80] := SRC2[63:48] + SRC2[47:32]
DEST[111:96] := SRC2[95:80] + SRC2[79:64]
DEST[127:112] := SRC2[127:112] + SRC2[111:96]
DEST[143:128] := SRC1[159:144] + SRC1[143:128]
DEST[159:144] := SRC1[191:176] + SRC1[175:160]
DEST[175:160] := SRC1[223:208] + SRC1[207:192]
DEST[191:176] := SRC1[255:240] + SRC1[239:224]
DEST[207:192] := SRC2[127:112] + SRC2[143:128]
DEST[223:208] := SRC2[159:144] + SRC2[175:160]
DEST[239:224] := SRC2[191:176] + SRC2[207:192]
DEST[255:240] := SRC2[223:208] + SRC2[239:224]
PHADDD (with 64-bit operands)
mm1[31-0] = mm1[63-32] + mm1[31-0];
mm1[63-32] = mm2/m64[63-32] + mm2/m64[31-0];
PHADDD (with 128-bit operands)
xmm1[31-0] = xmm1[63-32] + xmm1[31-0];
xmm1[63-32] = xmm1[127-96] + xmm1[95-64];
xmm1[95-64] = xmm2/m128[63-32] + xmm2/m128[31-0];
xmm1[127-96] = xmm2/m128[127-96] + xmm2/m128[95-64];
VPHADDD (VEX.128 encoded version)
DEST[31-0] := SRC1[63-32] + SRC1[31-0]
DEST[63-32] := SRC1[127-96] + SRC1[95-64]
DEST[95-64] := SRC2[63-32] + SRC2[31-0]
DEST[127-96] := SRC2[127-96] + SRC2[95-64]
DEST[MAXVL-1:128] := 0
VPHADDD (VEX.256 encoded version)
DEST[31-0] := SRC1[63-32] + SRC1[31-0]
DEST[63-32] := SRC1[127-96] + SRC1[95-64]
DEST[95-64] := SRC2[63-32] + SRC2[31-0]
DEST[127-96] := SRC2[127-96] + SRC2[95-64]
DEST[159-128] := SRC1[191-160] + SRC1[159-128]
DEST[191-160] := SRC1[255-224] + SRC1[223-192]
DEST[223-192] := SRC2[191-160] + SRC2[159-128]
DEST[255-224] := SRC2[255-224] + SRC2[223-192]
Intel C/C++ Compiler Intrinsic Equivalents
PHADDW:
__m64 _mm_hadd_pi16 (__m64 a, __m64 b)
PHADDD:
__m64 _mm_hadd_pi32 (__m64 a, __m64 b)
(V)PHADDW:
__m128i _mm_hadd_epi16 (__m128i a, __m128i b)
(V)PHADDD:
__m128i _mm_hadd_epi32 (__m128i a, __m128i b)
VPHADDW:
__m256i _mm256_hadd_epi16 (__m256i a, __m256i b)
VPHADDD:
__m256i _mm256_hadd_epi32 (__m256i a, __m256i b)
4-296
Vol. 2B
PHADDW/PHADDD—Packed Horizontal Add
INSTRUCTION SET REFERENCE, M-U
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally:
#UD
If VEX.L = 1.
PHADDW/PHADDD—Packed Horizontal Add
Vol. 2B
4-297
INSTRUCTION SET REFERENCE, M-U
PHADDSW—Packed Horizontal Add and Saturate
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
NP 0F 38 03 /r1
RM
V/V
SSSE3
Add 16-bit signed integers horizontally, pack
saturated integers to mm1.
PHADDSW mm1, mm2/m64
66 0F 38 03 /r
RM
V/V
SSSE3
Add 16-bit signed integers horizontally, pack
saturated integers to xmm1.
PHADDSW xmm1, xmm2/m128
VEX.128.66.0F38.WIG 03 /r
RVM
V/V
AVX
Add 16-bit signed integers horizontally, pack
saturated integers to xmm1.
VPHADDSW xmm1, xmm2, xmm3/m128
VEX.256.66.0F38.WIG 03 /r
RVM
V/V
AVX2
Add 16-bit signed integers horizontally, pack
saturated integers to ymm1.
VPHADDSW ymm1, ymm2, ymm3/m256
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX
Registers” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
RVM
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
(V)PHADDSW adds two adjacent signed 16-bit integers horizontally from the source and destination operands and
saturates the signed results; packs the signed, saturated 16-bit results to the destination operand (first operand)
When the source operand is a 128-bit memory operand, the operand must be aligned on a 16-byte boundary or a
general-protection exception (#GP) will be generated.
Legacy SSE version: Both operands can be MMX registers. The second source operand can be an MMX register or a
64-bit memory location.
128-bit Legacy SSE version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding YMM destina-
tion register remain unchanged.
In 64-bit mode, use the REX prefix to access additional registers.
VEX.128 encoded version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the destination YMM register are
zeroed.
VEX.256 encoded version: The first source and destination operands are YMM registers. The second source
operand can be an YMM register or a 256-bit memory location.
Operation
PHADDSW (with 64-bit operands)
mm1[15-0] = SaturateToSignedWord((mm1[31-16] + mm1[15-0]);
mm1[31-16] = SaturateToSignedWord(mm1[63-48] + mm1[47-32]);
mm1[47-32] = SaturateToSignedWord(mm2/m64[31-16] + mm2/m64[15-0]);
mm1[63-48] = SaturateToSignedWord(mm2/m64[63-48] + mm2/m64[47-32]);
4-298
Vol. 2B
PHADDSW—Packed Horizontal Add and Saturate
INSTRUCTION SET REFERENCE, M-U
PHADDSW (with 128-bit operands)
xmm1[15-0]= SaturateToSignedWord(xmm1[31-16] + xmm1[15-0]);
xmm1[31-16] = SaturateToSignedWord(xmm1[63-48] + xmm1[47-32]);
xmm1[47-32] = SaturateToSignedWord(xmm1[95-80] + xmm1[79-64]);
xmm1[63-48] = SaturateToSignedWord(xmm1[127-112] + xmm1[111-96]);
xmm1[79-64] = SaturateToSignedWord(xmm2/m128[31-16] + xmm2/m128[15-0]);
xmm1[95-80] = SaturateToSignedWord(xmm2/m128[63-48] + xmm2/m128[47-32]);
xmm1[111-96] = SaturateToSignedWord(xmm2/m128[95-80] + xmm2/m128[79-64]);
xmm1[127-112] = SaturateToSignedWord(xmm2/m128[127-112] + xmm2/m128[111-96]);
VPHADDSW (VEX.128 encoded version)
DEST[15:0]= SaturateToSignedWord(SRC1[31:16] + SRC1[15:0])
DEST[31:16] = SaturateToSignedWord(SRC1[63:48] + SRC1[47:32])
DEST[47:32] = SaturateToSignedWord(SRC1[95:80] + SRC1[79:64])
DEST[63:48] = SaturateToSignedWord(SRC1[127:112] + SRC1[111:96])
DEST[79:64] = SaturateToSignedWord(SRC2[31:16] + SRC2[15:0])
DEST[95:80] = SaturateToSignedWord(SRC2[63:48] + SRC2[47:32])
DEST[111:96] = SaturateToSignedWord(SRC2[95:80] + SRC2[79:64])
DEST[127:112] = SaturateToSignedWord(SRC2[127:112] + SRC2[111:96])
DEST[MAXVL-1:128] := 0
VPHADDSW (VEX.256 encoded version)
DEST[15:0]= SaturateToSignedWord(SRC1[31:16] + SRC1[15:0])
DEST[31:16] = SaturateToSignedWord(SRC1[63:48] + SRC1[47:32])
DEST[47:32] = SaturateToSignedWord(SRC1[95:80] + SRC1[79:64])
DEST[63:48] = SaturateToSignedWord(SRC1[127:112] + SRC1[111:96])
DEST[79:64] = SaturateToSignedWord(SRC2[31:16] + SRC2[15:0])
DEST[95:80] = SaturateToSignedWord(SRC2[63:48] + SRC2[47:32])
DEST[111:96] = SaturateToSignedWord(SRC2[95:80] + SRC2[79:64])
DEST[127:112] = SaturateToSignedWord(SRC2[127:112] + SRC2[111:96])
DEST[143:128]= SaturateToSignedWord(SRC1[159:144] + SRC1[143:128])
DEST[159:144] = SaturateToSignedWord(SRC1[191:176] + SRC1[175:160])
DEST[175:160] = SaturateToSignedWord( SRC1[223:208] + SRC1[207:192])
DEST[191:176] = SaturateToSignedWord(SRC1[255:240] + SRC1[239:224])
DEST[207:192] = SaturateToSignedWord(SRC2[127:112] + SRC2[143:128])
DEST[223:208] = SaturateToSignedWord(SRC2[159:144] + SRC2[175:160])
DEST[239:224] = SaturateToSignedWord(SRC2[191-160] + SRC2[159-128])
DEST[255:240] = SaturateToSignedWord(SRC2[255:240] + SRC2[239:224])
Intel C/C++ Compiler Intrinsic Equivalent
PHADDSW:
__m64 _mm_hadds_pi16 (__m64 a, __m64 b)
(V)PHADDSW:
__m128i _mm_hadds_epi16 (__m128i a, __m128i b)
VPHADDSW:
__m256i _mm256_hadds_epi16 (__m256i a, __m256i b)
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally:
#UD
If VEX.L = 1.
PHADDSW—Packed Horizontal Add and Saturate
Vol. 2B
4-299
INSTRUCTION SET REFERENCE, M-U
PHMINPOSUW—Packed Horizontal Word Minimum
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
66 0F 38 41 /r
RM
V/V
SSE4_1
Find the minimum unsigned word in
PHMINPOSUW xmm1, xmm2/m128
xmm2/m128 and place its value in the low
word of xmm1 and its index in the second-
lowest word of xmm1.
VEX.128.66.0F38.WIG 41 /r
RM
V/V
AVX
Find the minimum unsigned word in
VPHMINPOSUW xmm1, xmm2/m128
xmm2/m128 and place its value in the low
word of xmm1 and its index in the second-
lowest word of xmm1.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (w)
ModRM:r/m (r)
N/A
N/A
Description
Determine the minimum unsigned word value in the source operand (second operand) and place the unsigned
word in the low word (bits 0-15) of the destination operand (first operand). The word index of the minimum value
is stored in bits 16-18 of the destination operand. The remaining upper bits of the destination are set to zero.
128-bit Legacy SSE version: Bits (MAXVL-1:128) of the corresponding XMM destination register remain
unchanged.
VEX.128 encoded version: Bits (MAXVL-1:128) of the destination XMM register are zeroed. VEX.vvvv is reserved
and must be 1111b, VEX.L must be 0, otherwise the instruction will #UD.
Operation
PHMINPOSUW (128-bit Legacy SSE version)
INDEX := 0;
MIN := SRC[15:0]
IF (SRC[31:16] < MIN)
THEN INDEX := 1; MIN := SRC[31:16]; FI;
IF (SRC[47:32] < MIN)
THEN INDEX := 2; MIN := SRC[47:32]; FI;
* Repeat operation for words 3 through 6
IF (SRC[127:112] < MIN)
THEN INDEX := 7; MIN := SRC[127:112]; FI;
DEST[15:0] := MIN;
DEST[18:16] := INDEX;
DEST[127:19] := 0000000000000000000000000000H;
4-300
Vol. 2B
PHMINPOSUW—Packed Horizontal Word Minimum
INSTRUCTION SET REFERENCE, M-U
VPHMINPOSUW (VEX.128 encoded version)
INDEX := 0
MIN := SRC[15:0]
IF (SRC[31:16] < MIN) THEN INDEX := 1; MIN := SRC[31:16]
IF (SRC[47:32] < MIN) THEN INDEX := 2; MIN := SRC[47:32]
* Repeat operation for words 3 through 6
IF (SRC[127:112] < MIN) THEN INDEX := 7; MIN := SRC[127:112]
DEST[15:0] := MIN
DEST[18:16] := INDEX
DEST[127:19] := 0000000000000000000000000000H
DEST[MAXVL-1:128] := 0
Intel C/C++ Compiler Intrinsic Equivalent
PHMINPOSUW:
__m128i _mm_minpos_epu16( __m128i packed_words);
Flags Affected
None.
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally:
#UD
If VEX.L = 1.
If VEX.vvvv ≠ 1111B.
PHMINPOSUW—Packed Horizontal Word Minimum
Vol. 2B
4-301
INSTRUCTION SET REFERENCE, M-U
PHSUBW/PHSUBD—Packed Horizontal Subtract
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
NP 0F 38 05 /r1
RM
V/V
SSSE3
Subtract 16-bit signed integers horizontally,
pack to mm1.
PHSUBW mm1, mm2/m64
66 0F 38 05 /r
RM
V/V
SSSE3
Subtract 16-bit signed integers horizontally,
pack to xmm1.
PHSUBW xmm1, xmm2/m128
NP 0F 38 06 /r
RM
V/V
SSSE3
Subtract 32-bit signed integers horizontally,
pack to mm1.
PHSUBD mm1, mm2/m64
66 0F 38 06 /r
RM
V/V
SSSE3
Subtract 32-bit signed integers horizontally,
pack to xmm1.
PHSUBD xmm1, xmm2/m128
VEX.128.66.0F38.WIG 05 /r
RVM
V/V
AVX
Subtract 16-bit signed integers horizontally,
pack to xmm1.
VPHSUBW xmm1, xmm2, xmm3/m128
VEX.128.66.0F38.WIG 06 /r
RVM
V/V
AVX
Subtract 32-bit signed integers horizontally,
pack to xmm1.
VPHSUBD xmm1, xmm2, xmm3/m128
VEX.256.66.0F38.WIG 05 /r
RVM
V/V
AVX2
Subtract 16-bit signed integers horizontally,
pack to ymm1.
VPHSUBW ymm1, ymm2, ymm3/m256
VEX.256.66.0F38.WIG 06 /r
RVM
V/V
AVX2
Subtract 32-bit signed integers horizontally,
pack to ymm1.
VPHSUBD ymm1, ymm2, ymm3/m256
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX
Registers” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
RVM
ModRM:reg (r, w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
(V)PHSUBW performs horizontal subtraction on each adjacent pair of 16-bit signed integers by subtracting the
most significant word from the least significant word of each pair in the source and destination operands, and packs
the signed 16-bit results to the destination operand (first operand). (V)PHSUBD performs horizontal subtraction on
each adjacent pair of 32-bit signed integers by subtracting the most significant doubleword from the least signifi-
cant doubleword of each pair, and packs the signed 32-bit result to the destination operand. When the source
operand is a 128-bit memory operand, the operand must be aligned on a 16-byte boundary or a general-protection
exception (#GP) will be generated.
Legacy SSE version: Both operands can be MMX registers. The second source operand can be an MMX register or a
64-bit memory location.
128-bit Legacy SSE version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding YMM destina-
tion register remain unchanged.
In 64-bit mode, use the REX prefix to access additional registers.
VEX.128 encoded version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the destination YMM register are
zeroed.
4-302
Vol. 2B
PHSUBW/PHSUBD—Packed Horizontal Subtract
INSTRUCTION SET REFERENCE, M-U
VEX.256 encoded version: The first source and destination operands are YMM registers. The second source
operand can be an YMM register or a 256-bit memory location.
Operation
PHSUBW (with 64-bit operands)
mm1[15-0] = mm1[15-0] - mm1[31-16];
mm1[31-16] = mm1[47-32] - mm1[63-48];
mm1[47-32] = mm2/m64[15-0] - mm2/m64[31-16];
mm1[63-48] = mm2/m64[47-32] - mm2/m64[63-48];
PHSUBW (with 128-bit operands)
xmm1[15-0] = xmm1[15-0] - xmm1[31-16];
xmm1[31-16] = xmm1[47-32] - xmm1[63-48];
xmm1[47-32] = xmm1[79-64] - xmm1[95-80];
xmm1[63-48] = xmm1[111-96] - xmm1[127-112];
xmm1[79-64] = xmm2/m128[15-0] - xmm2/m128[31-16];
xmm1[95-80] = xmm2/m128[47-32] - xmm2/m128[63-48];
xmm1[111-96] = xmm2/m128[79-64] - xmm2/m128[95-80];
xmm1[127-112] = xmm2/m128[111-96] - xmm2/m128[127-112];
VPHSUBW (VEX.128 encoded version)
DEST[15:0] := SRC1[15:0] - SRC1[31:16]
DEST[31:16] := SRC1[47:32] - SRC1[63:48]
DEST[47:32] := SRC1[79:64] - SRC1[95:80]
DEST[63:48] := SRC1[111:96] - SRC1[127:112]
DEST[79:64] := SRC2[15:0] - SRC2[31:16]
DEST[95:80] := SRC2[47:32] - SRC2[63:48]
DEST[111:96] := SRC2[79:64] - SRC2[95:80]
DEST[127:112] := SRC2[111:96] - SRC2[127:112]
DEST[MAXVL-1:128] := 0
VPHSUBW (VEX.256 encoded version)
DEST[15:0] := SRC1[15:0] - SRC1[31:16]
DEST[31:16] := SRC1[47:32] - SRC1[63:48]
DEST[47:32] := SRC1[79:64] - SRC1[95:80]
DEST[63:48] := SRC1[111:96] - SRC1[127:112]
DEST[79:64] := SRC2[15:0] - SRC2[31:16]
DEST[95:80] := SRC2[47:32] - SRC2[63:48]
DEST[111:96] := SRC2[79:64] - SRC2[95:80]
DEST[127:112] := SRC2[111:96] - SRC2[127:112]
DEST[143:128] := SRC1[143:128] - SRC1[159:144]
DEST[159:144] := SRC1[175:160] - SRC1[191:176]
DEST[175:160] := SRC1[207:192] - SRC1[223:208]
DEST[191:176] := SRC1[239:224] - SRC1[255:240]
DEST[207:192] := SRC2[143:128] - SRC2[159:144]
DEST[223:208] := SRC2[175:160] - SRC2[191:176]
DEST[239:224] := SRC2[207:192] - SRC2[223:208]
DEST[255:240] := SRC2[239:224] - SRC2[255:240]
PHSUBD (with 64-bit operands)
mm1[31-0] = mm1[31-0] - mm1[63-32];
mm1[63-32] = mm2/m64[31-0] - mm2/m64[63-32];
PHSUBW/PHSUBD—Packed Horizontal Subtract
Vol. 2B
4-303
INSTRUCTION SET REFERENCE, M-U
PHSUBD (with 128-bit operands)
xmm1[31-0] = xmm1[31-0] - xmm1[63-32];
xmm1[63-32] = xmm1[95-64] - xmm1[127-96];
xmm1[95-64] = xmm2/m128[31-0] - xmm2/m128[63-32];
xmm1[127-96] = xmm2/m128[95-64] - xmm2/m128[127-96];
VPHSUBD (VEX.128 encoded version)
DEST[31-0] := SRC1[31-0] - SRC1[63-32]
DEST[63-32] := SRC1[95-64] - SRC1[127-96]
DEST[95-64] := SRC2[31-0] - SRC2[63-32]
DEST[127-96] := SRC2[95-64] - SRC2[127-96]
DEST[MAXVL-1:128] := 0
VPHSUBD (VEX.256 encoded version)
DEST[31:0] := SRC1[31:0] - SRC1[63:32]
DEST[63:32] := SRC1[95:64] - SRC1[127:96]
DEST[95:64] := SRC2[31:0] - SRC2[63:32]
DEST[127:96] := SRC2[95:64] - SRC2[127:96]
DEST[159:128] := SRC1[159:128] - SRC1[191:160]
DEST[191:160] := SRC1[223:192] - SRC1[255:224]
DEST[223:192] := SRC2[159:128] - SRC2[191:160]
DEST[255:224] := SRC2[223:192] - SRC2[255:224]
Intel C/C++ Compiler Intrinsic Equivalents
PHSUBW:
__m64 _mm_hsub_pi16 (__m64 a, __m64 b)
PHSUBD:
__m64 _mm_hsub_pi32 (__m64 a, __m64 b)
(V)PHSUBW:
__m128i _mm_hsub_epi16 (__m128i a, __m128i b)
(V)PHSUBD:
__m128i _mm_hsub_epi32 (__m128i a, __m128i b)
VPHSUBW:
__m256i _mm256_hsub_epi16 (__m256i a, __m256i b)
VPHSUBD:
__m256i _mm256_hsub_epi32 (__m256i a, __m256i b)
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally:
#UD
If VEX.L = 1.
4-304
Vol. 2B
PHSUBW/PHSUBD—Packed Horizontal Subtract
INSTRUCTION SET REFERENCE, M-U
PHSUBSW—Packed Horizontal Subtract and Saturate
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
NP 0F 38 07 /r1
RM
V/V
SSSE3
Subtract 16-bit signed integer horizontally,
pack saturated integers to mm1.
PHSUBSW mm1, mm2/m64
66 0F 38 07 /r
RM
V/V
SSSE3
Subtract 16-bit signed integer horizontally,
pack saturated integers to xmm1.
PHSUBSW xmm1, xmm2/m128
VEX.128.66.0F38.WIG 07 /r
RVM
V/V
AVX
Subtract 16-bit signed integer horizontally,
pack saturated integers to xmm1.
VPHSUBSW xmm1, xmm2, xmm3/m128
VEX.256.66.0F38.WIG 07 /r
RVM
V/V
AVX2
Subtract 16-bit signed integer horizontally,
pack saturated integers to ymm1.
VPHSUBSW ymm1, ymm2, ymm3/m256
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX
Registers” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Instruction Operand Encoding
Op/En
Operand 1
Operand 2
Operand 3
Operand 4
RM
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
RVM
ModRM:reg (r, w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
(V)PHSUBSW performs horizontal subtraction on each adjacent pair of 16-bit signed integers by subtracting the
most significant word from the least significant word of each pair in the source and destination operands. The
signed, saturated 16-bit results are packed to the destination operand (first operand). When the source operand is
a 128-bit memory operand, the operand must be aligned on a 16-byte boundary or a general-protection exception
(#GP) will be generated.
Legacy SSE version: Both operands can be MMX registers. The second source operand can be an MMX register or
a 64-bit memory location.
128-bit Legacy SSE version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding YMM destina-
tion register remain unchanged.
In 64-bit mode, use the REX prefix to access additional registers.
VEX.128 encoded version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the destination YMM register are
zeroed.
VEX.256 encoded version: The first source and destination operands are YMM registers. The second source
operand can be an YMM register or a 256-bit memory location.
Operation
PHSUBSW (with 64-bit operands)
mm1[15-0] = SaturateToSignedWord(mm1[15-0] - mm1[31-16]);
mm1[31-16] = SaturateToSignedWord(mm1[47-32] - mm1[63-48]);
mm1[47-32] = SaturateToSignedWord(mm2/m64[15-0] - mm2/m64[31-16]);
mm1[63-48] = SaturateToSignedWord(mm2/m64[47-32] - mm2/m64[63-48]);
PHSUBSW—Packed Horizontal Subtract and Saturate
Vol. 2B
4-305
INSTRUCTION SET REFERENCE, M-U
PHSUBSW (with 128-bit operands)
xmm1[15-0] = SaturateToSignedWord(xmm1[15-0] - xmm1[31-16]);
xmm1[31-16] = SaturateToSignedWord(xmm1[47-32] - xmm1[63-48]);
xmm1[47-32] = SaturateToSignedWord(xmm1[79-64] - xmm1[95-80]);
xmm1[63-48] = SaturateToSignedWord(xmm1[111-96] - xmm1[127-112]);
xmm1[79-64] = SaturateToSignedWord(xmm2/m128[15-0] - xmm2/m128[31-16]);
xmm1[95-80] =SaturateToSignedWord(xmm2/m128[47-32] - xmm2/m128[63-48]);
xmm1[111-96] =SaturateToSignedWord(xmm2/m128[79-64] - xmm2/m128[95-80]);
xmm1[127-112]= SaturateToSignedWord(xmm2/m128[111-96] - xmm2/m128[127-112]);
VPHSUBSW (VEX.128 encoded version)
DEST[15:0]= SaturateToSignedWord(SRC1[15:0] - SRC1[31:16])
DEST[31:16] = SaturateToSignedWord(SRC1[47:32] - SRC1[63:48])
DEST[47:32] = SaturateToSignedWord(SRC1[79:64] - SRC1[95:80])
DEST[63:48] = SaturateToSignedWord(SRC1[111:96] - SRC1[127:112])
DEST[79:64] = SaturateToSignedWord(SRC2[15:0] - SRC2[31:16])
DEST[95:80] = SaturateToSignedWord(SRC2[47:32] - SRC2[63:48])
DEST[111:96] = SaturateToSignedWord(SRC2[79:64] - SRC2[95:80])
DEST[127:112] = SaturateToSignedWord(SRC2[111:96] - SRC2[127:112])
DEST[MAXVL-1:128] := 0
VPHSUBSW (VEX.256 encoded version)
DEST[15:0]= SaturateToSignedWord(SRC1[15:0] - SRC1[31:16])
DEST[31:16] = SaturateToSignedWord(SRC1[47:32] - SRC1[63:48])
DEST[47:32] = SaturateToSignedWord(SRC1[79:64] - SRC1[95:80])
DEST[63:48] = SaturateToSignedWord(SRC1[111:96] - SRC1[127:112])
DEST[79:64] = SaturateToSignedWord(SRC2[15:0] - SRC2[31:16])
DEST[95:80] = SaturateToSignedWord(SRC2[47:32] - SRC2[63:48])
DEST[111:96] = SaturateToSignedWord(SRC2[79:64] - SRC2[95:80])
DEST[127:112] = SaturateToSignedWord(SRC2[111:96] - SRC2[127:112])
DEST[143:128]= SaturateToSignedWord(SRC1[143:128] - SRC1[159:144])
DEST[159:144] = SaturateToSignedWord(SRC1[175:160] - SRC1[191:176])
DEST[175:160] = SaturateToSignedWord(SRC1[207:192] - SRC1[223:208])
DEST[191:176] = SaturateToSignedWord(SRC1[239:224] - SRC1[255:240])
DEST[207:192] = SaturateToSignedWord(SRC2[143:128] - SRC2[159:144])
DEST[223:208] = SaturateToSignedWord(SRC2[175:160] - SRC2[191:176])
DEST[239:224] = SaturateToSignedWord(SRC2[207:192] - SRC2[223:208])
DEST[255:240] = SaturateToSignedWord(SRC2[239:224] - SRC2[255:240])
Intel C/C++ Compiler Intrinsic Equivalent
PHSUBSW:
__m64 _mm_hsubs_pi16 (__m64 a, __m64 b)
(V)PHSUBSW:
__m128i _mm_hsubs_epi16 (__m128i a, __m128i b)
VPHSUBSW:
__m256i _mm256_hsubs_epi16 (__m256i a, __m256i b)
SIMD Floating-Point Exceptions
None.
Other Exceptions
See Table 2-21, “Type 4 Class Exception Conditions”; additionally:
#UD
If VEX.L = 1.
4-306
Vol. 2B
PHSUBSW—Packed Horizontal Subtract and Saturate
INSTRUCTION SET REFERENCE, M-U
PINSRB/PINSRD/PINSRQ—Insert Byte/Dword/Qword
Opcode/
Op/ En
64/32 bit
CPUID
Description
Instruction
Mode
Feature
Support
Flag
66 0F 3A 20 /r ib
A
V/V
SSE4_1
Insert a byte integer value from r32/m8 into
PINSRB xmm1, r32/m8, imm8
xmm1 at the destination element in xmm1
specified by imm8.
66 0F 3A 22 /r ib
A
V/V
SSE4_1
Insert a dword integer value from r/m32 into
PINSRD xmm1, r/m32, imm8
the xmm1 at the destination element
specified by imm8.
66 REX.W 0F 3A 22 /r ib
A
V/N. E.
SSE4_1
Insert a qword integer value from r/m64 into
PINSRQ xmm1, r/m64, imm8
the xmm1 at the destination element
specified by imm8.
VEX.128.66.0F3A.W0 20 /r ib
B
V1/V
AVX
Merge a byte integer value from r32/m8 and
VPINSRB xmm1, xmm2, r32/m8, imm8
rest from xmm2 into xmm1 at the byte offset
in imm8.
VEX.128.66.0F3A.W0 22 /r ib
B
V/V
AVX
Insert a dword integer value from r32/m32
VPINSRD xmm1, xmm2, r/m32, imm8
and rest from xmm2 into xmm1 at the dword
offset in imm8.
VEX.128.66.0F3A.W1 22 /r ib
B
V/I2
AVX
Insert a qword integer value from r64/m64
VPINSRQ xmm1, xmm2, r/m64, imm8
and rest from xmm2 into xmm1 at the qword
offset in imm8.
EVEX.128.66.0F3A.WIG 20 /r ib
C
V/V
AVX512BW
Merge a byte integer value from r32/m8 and
VPINSRB xmm1, xmm2, r32/m8, imm8
rest from xmm2 into xmm1 at the byte offset
in imm8.
EVEX.128.66.0F3A.W0 22 /r ib
C
V/V
AVX512DQ
Insert a dword integer value from r32/m32
VPINSRD xmm1, xmm2, r32/m32, imm8
and rest from xmm2 into xmm1 at the dword
offset in imm8.
EVEX.128.66.0F3A.W1 22 /r ib
C
V/N.E.2
AVX512DQ
Insert a qword integer value from r64/m64
VPINSRQ xmm1, xmm2, r64/m64, imm8
and rest from xmm2 into xmm1 at the qword
offset in imm8.
NOTES:
1. In 64-bit mode, VEX.W1 is ignored for VPINSRB (similar to legacy REX.W=1 prefix with PINSRB).
2. VEX.W/EVEX.W in non-64 bit is ignored; the instructions behaves as if the W0 version is used.
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:reg (w)
ModRM:r/m (r)
imm8
N/A
B
N/A
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
imm8
C
Tuple1 Scalar
ModRM:reg (w)
EVEX.vvvv (r)
ModRM:r/m (r)
imm8
Description
Copies a byte/dword/qword from the source operand (second operand) and inserts it in the destination operand
(first operand) at the location specified with the count operand (third operand). (The other elements in the desti-
nation register are left untouched.) The source operand can be a general-purpose register or a memory location.
(When the source operand is a general-purpose register, PINSRB copies the low byte of the register.) The destina-
tion operand is an XMM register. The count operand is an 8-bit immediate. When specifying a qword[dword, byte]
location in an XMM register, the [2, 4] least-significant bit(s) of the count operand specify the location.
PINSRB/PINSRD/PINSRQ—Insert Byte/Dword/Qword
Vol. 2B
4-307
INSTRUCTION SET REFERENCE, M-U
In 64-bit mode and not encoded with VEX/EVEX, using a REX prefix in the form of REX.R permits this instruction to
access additional registers (XMM8-XMM15, R8-15). Use of REX.W permits the use of 64 bit general purpose regis-
ters.
128-bit Legacy SSE version: Bits (MAXVL-1:128) of the corresponding YMM destination register remain unchanged.
VEX.128 encoded version: Bits (MAXVL-1:128) of the destination register are zeroed. VEX.L must be 0, otherwise
the instruction will #UD. Attempt to execute VPINSRQ in non-64-bit mode will cause #UD.
EVEX.128 encoded version: Bits (MAXVL-1:128) of the destination register are zeroed. EVEX.L’L must be 0, other-
wise the instruction will #UD.
Operation
CASE OF
PINSRB: SEL := COUNT[3:0];
MASK := (0FFH << (SEL * 8));
TEMP := (((SRC[7:0] << (SEL *8)) AND MASK);
PINSRD: SEL := COUNT[1:0];
MASK := (0FFFFFFFFH << (SEL * 32));
TEMP := (((SRC << (SEL *32)) AND MASK)
;
PINSRQ: SEL := COUNT[0]
MASK := (0FFFFFFFFFFFFFFFFH << (SEL * 64));
TEMP := (((SRC << (SEL *64)) AND MASK)
;
ESAC;
DEST := ((DEST AND NOT MASK) OR TEMP);
VPINSRB (VEX/EVEX encoded version)
SEL := imm8[3:0]
DEST[127:0] := write_b_element(SEL, SRC2, SRC1)
DEST[MAXVL-1:128] := 0
VPINSRD (VEX/EVEX encoded version)
SEL := imm8[1:0]
DEST[127:0] := write_d_element(SEL, SRC2, SRC1)
DEST[MAXVL-1:128] := 0
VPINSRQ (VEX/EVEX encoded version)
SEL := imm8[0]
DEST[127:0] := write_q_element(SEL, SRC2, SRC1)
DEST[MAXVL-1:128] := 0
Intel C/C++ Compiler Intrinsic Equivalent
PINSRB:
__m128i _mm_insert_epi8 (__m128i s1, int s2, const int ndx);
PINSRD:
__m128i _mm_insert_epi32 (__m128i s2, int s, const int ndx);
PINSRQ:
__m128i _mm_insert_epi64(__m128i s2, __int64 s, const int ndx);
Flags Affected
None.
SIMD Floating-Point Exceptions
None.
4-308
Vol. 2B
PINSRB/PINSRD/PINSRQ—Insert Byte/Dword/Qword
INSTRUCTION SET REFERENCE, M-U
Other Exceptions
EVEX-encoded instruction, see Table 2-22, “Type 5 Class Exception Conditions”.
EVEX-encoded instruction, see Table 2-57, “Type E9NF Class Exception Conditions”.
Additionally:
#UD
If VEX.L = 1 or EVEX.L’L > 0.
PINSRB/PINSRD/PINSRQ—Insert Byte/Dword/Qword
Vol. 2B
4-309
INSTRUCTION SET REFERENCE, M-U
PINSRW—Insert Word
Opcode/
Op/ En
64/32 bit
CPUID
Description
Instruction
Mode
Feature
Support
Flag
NP 0F C4 /r ib1
A
V/V
SSE
Insert the low word from r32 or from m16
into mm at the word position specified by
PINSRW mm, r32/m16, imm8
imm8.
66 0F C4 /r ib
A
V/V
SSE2
Move the low word of r32 or from m16 into
xmm at the word position specified by imm8.
PINSRW xmm, r32/m16, imm8
VEX.128.66.0F.W0 C4 /r ib
B
V2/V
AVX
Insert the word from r32/m16 at the offset
indicated by imm8 into the value from xmm2
VPINSRW xmm1, xmm2, r32/m16, imm8
and store result in xmm1.
EVEX.128.66.0F.WIG C4 /r ib
C
V/V
AVX512BW
Insert the word from r32/m16 at the offset
VPINSRW xmm1, xmm2, r32/m16, imm8
indicated by imm8 into the value from xmm2
and store result in xmm1.
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures
Software Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX
Registers” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
2. In 64-bit mode, VEX.W1 is ignored for VPINSRW (similar to legacy REX.W=1 prefix in PINSRW).
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:reg (w)
ModRM:r/m (r)
imm8
N/A
B
N/A
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
imm8
C
Tuple1 Scalar
ModRM:reg (w)
EVEX.vvvv (r)
ModRM:r/m (r)
imm8
Description
Three operand MMX and SSE instructions:
Copies a word from the source operand and inserts it in the destination operand at the location specified with the
count operand. (The other words in the destination register are left untouched.) The source operand can be a
general-purpose register or a 16-bit memory location. (When the source operand is a general-purpose register, the
low word of the register is copied.) The destination operand can be an MMX technology register or an XMM register.
The count operand is an 8-bit immediate. When specifying a word location in an MMX technology register, the 2
least-significant bits of the count operand specify the location; for an XMM register, the 3 least-significant bits
specify the location.
Bits (MAXVL-1:128) of the corresponding YMM destination register remain unchanged.
Four operand AVX and AVX-512 instructions:
Combines a word from the first source operand with the second source operand, and inserts it in the destination
operand at the location specified with the count operand. The second source operand can be a general-purpose
register or a 16-bit memory location. (When the source operand is a general-purpose register, the low word of the
register is copied.) The first source and destination operands are XMM registers. The count operand is an 8-bit
immediate. When specifying a word location, the 3 least-significant bits specify the location.
Bits (MAXVL-1:128) of the destination YMM register are zeroed. VEX.L/EVEX.L’L must be 0, otherwise the instruc-
tion will #UD.
4-310
Vol. 2B
PINSRW—Insert Word
INSTRUCTION SET REFERENCE, M-U
Operation
PINSRW dest, src, imm8 (MMX)
SEL := imm8[1:0]
DEST.word[SEL] := src.word[0]
PINSRW dest, src, imm8 (SSE)
SEL := imm8[2:0]
DEST.word[SEL] := src.word[0]
VPINSRW dest, src1, src2, imm8 (AVX/AVX512)
SEL := imm8[2:0]
DEST := src1
DEST.word[SEL] := src2.word[0]
DEST[MAXVL-1:128] := 0
Intel C/C++ Compiler Intrinsic Equivalent
PINSRW:
__m64 _mm_insert_pi16 (__m64 a, int d, int n)
PINSRW:
__m128i _mm_insert_epi16 ( __m128i a, int b, int imm)
Flags Affected
None.
Numeric Exceptions
None.
Other Exceptions
EVEX-encoded instruction, see Table 2-22, “Type 5 Class Exception Conditions”.
EVEX-encoded instruction, see Table 2-57, “Type E9NF Class Exception Conditions”.
Additionally:
#UD
If VEX.L = 1 or EVEX.L’L > 0.
PINSRW—Insert Word
Vol. 2B
4-311
INSTRUCTION SET REFERENCE, M-U
PMADDUBSW—Multiply and Add Packed Signed and Unsigned Bytes
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
NP 0F 38 04 /r1
A
V/V
SSSE3
Multiply signed and unsigned bytes, add
horizontal pair of signed words, pack
PMADDUBSW mm1, mm2/m64
saturated signed-words to mm1.
66 0F 38 04 /r
A
V/V
SSSE3
Multiply signed and unsigned bytes, add
horizontal pair of signed words, pack
PMADDUBSW xmm1, xmm2/m128
saturated signed-words to xmm1.
VEX.128.66.0F38.WIG 04 /r
B
V/V
AVX
Multiply signed and unsigned bytes, add
horizontal pair of signed words, pack
VPMADDUBSW xmm1, xmm2, xmm3/m128
saturated signed-words to xmm1.
VEX.256.66.0F38.WIG 04 /r
B
V/V
AVX2
Multiply signed and unsigned bytes, add
horizontal pair of signed words, pack
VPMADDUBSW ymm1, ymm2, ymm3/m256
saturated signed-words to ymm1.
EVEX.128.66.0F38.WIG 04 /r
C
V/V
AVX512VL
Multiply signed and unsigned bytes, add
VPMADDUBSW xmm1 {k1}{z}, xmm2, xmm3/m128
AVX512BW
horizontal pair of signed words, pack
saturated signed-words to xmm1 under
writemask k1.
EVEX.256.66.0F38.WIG 04 /r
C
V/V
AVX512VL
Multiply signed and unsigned bytes, add
VPMADDUBSW ymm1 {k1}{z}, ymm2, ymm3/m256
AVX512BW
horizontal pair of signed words, pack
saturated signed-words to ymm1 under
writemask k1.
EVEX.512.66.0F38.WIG 04 /r
C
V/V
AVX512BW
Multiply signed and unsigned bytes, add
VPMADDUBSW zmm1 {k1}{z}, zmm2, zmm3/m512
horizontal pair of signed words, pack
saturated signed-words to zmm1 under
writemask k1.
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX Reg-
isters” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
B
N/A
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
C
Full Mem
ModRM:reg (w)
EVEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
(V)PMADDUBSW multiplies vertically each unsigned byte of the destination operand (first operand) with the corre-
sponding signed byte of the source operand (second operand), producing intermediate signed 16-bit integers. Each
adjacent pair of signed words is added and the saturated result is packed to the destination operand. For example,
the lowest-order bytes (bits 7-0) in the source and destination operands are multiplied and the intermediate signed
word result is added with the corresponding intermediate result from the 2nd lowest-order bytes (bits 15-8) of the
operands; the sign-saturated result is stored in the lowest word of the destination register (15-0). The same oper-
ation is performed on the other pairs of adjacent bytes. Both operands can be MMX register or XMM registers. When
the source operand is a 128-bit memory operand, the operand must be aligned on a 16-byte boundary or a
general-protection exception (#GP) will be generated.
In 64-bit mode and not encoded with VEX/EVEX, use the REX prefix to access XMM8-XMM15.
4-312
Vol. 2B
PMADDUBSW—Multiply and Add Packed Signed and Unsigned Bytes
INSTRUCTION SET REFERENCE, M-U
128-bit Legacy SSE version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding destination
register remain unchanged.
VEX.128 and EVEX.128 encoded versions: The first source and destination operands are XMM registers. The
second source operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding
destination register are zeroed.
VEX.256 and EVEX.256 encoded versions: The second source operand can be an YMM register or a 256-bit memory
location. The first source and destination operands are YMM registers. Bits (MAXVL-1:256) of the corresponding
ZMM register are zeroed.
EVEX.512 encoded version: The second source operand can be an ZMM register or a 512-bit memory location. The
first source and destination operands are ZMM registers.
Operation
PMADDUBSW (with 64 bit operands)
DEST[15-0] = SaturateToSignedWord(SRC[15-8]*DEST[15-8]+SRC[7-0]*DEST[7-0]);
DEST[31-16] = SaturateToSignedWord(SRC[31-24]*DEST[31-24]+SRC[23-16]*DEST[23-16]);
DEST[47-32] = SaturateToSignedWord(SRC[47-40]*DEST[47-40]+SRC[39-32]*DEST[39-32]);
DEST[63-48] = SaturateToSignedWord(SRC[63-56]*DEST[63-56]+SRC[55-48]*DEST[55-48]);
PMADDUBSW (with 128 bit operands)
DEST[15-0] = SaturateToSignedWord(SRC[15-8]* DEST[15-8]+SRC[7-0]*DEST[7-0]);
// Repeat operation for 2nd through 7th word
SRC1/DEST[127-112] = SaturateToSignedWord(SRC[127-120]*DEST[127-120]+ SRC[119-112]* DEST[119-112]);
VPMADDUBSW (VEX.128 encoded version)
DEST[15:0] := SaturateToSignedWord(SRC2[15:8]* SRC1[15:8]+SRC2[7:0]*SRC1[7:0])
// Repeat operation for 2nd through 7th word
DEST[127:112] := SaturateToSignedWord(SRC2[127:120]*SRC1[127:120]+ SRC2[119:112]* SRC1[119:112])
DEST[MAXVL-1:128] := 0
VPMADDUBSW (VEX.256 encoded version)
DEST[15:0] := SaturateToSignedWord(SRC2[15:8]* SRC1[15:8]+SRC2[7:0]*SRC1[7:0])
// Repeat operation for 2nd through 15th word
DEST[255:240] := SaturateToSignedWord(SRC2[255:248]*SRC1[255:248]+ SRC2[247:240]* SRC1[247:240])
DEST[MAXVL-1:256] := 0
VPMADDUBSW (EVEX encoded versions)
(KL, VL) = (8, 128), (16, 256), (32, 512)
FOR j := 0 TO KL-1
i := j * 16
IF k1[j] OR *no writemask*
THEN DEST[i+15:i] := SaturateToSignedWord(SRC2[i+15:i+8]* SRC1[i+15:i+8] + SRC2[i+7:i]*SRC1[i+7:i])
ELSE
IF *merging-masking*
; merging-masking
THEN *DEST[i+15:i] remains unchanged*
ELSE *zeroing-masking*
; zeroing-masking
DEST[i+15:i] = 0
FI
FI;
ENDFOR;
DEST[MAXVL-1:VL] := 0
PMADDUBSW—Multiply and Add Packed Signed and Unsigned Bytes
Vol. 2B
4-313
INSTRUCTION SET REFERENCE, M-U
Intel C/C++ Compiler Intrinsic Equivalents
VPMADDUBSW __m512i _mm512_maddubs_epi16( __m512i a, __m512i b);
VPMADDUBSW __m512i _mm512_mask_maddubs_epi16(__m512i s, __mmask32 k, __m512i a, __m512i b);
VPMADDUBSW __m512i _mm512_maskz_maddubs_epi16( __mmask32 k, __m512i a, __m512i b);
VPMADDUBSW __m256i _mm256_mask_maddubs_epi16(__m256i s, __mmask16 k, __m256i a, __m256i b);
VPMADDUBSW __m256i _mm256_maskz_maddubs_epi16( __mmask16 k, __m256i a, __m256i b);
VPMADDUBSW __m128i _mm_mask_maddubs_epi16(__m128i s, __mmask8 k, __m128i a, __m128i b);
VPMADDUBSW __m128i _mm_maskz_maddubs_epi16( __mmask8 k, __m128i a, __m128i b);
PMADDUBSW: __m64 _mm_maddubs_pi16 (__m64 a, __m64 b)
(V)PMADDUBSW: __m128i _mm_maddubs_epi16 (__m128i a, __m128i b)
VPMADDUBSW:
__m256i _mm256_maddubs_epi16 (__m256i a, __m256i b)
SIMD Floating-Point Exceptions
None.
Other Exceptions
Non-EVEX-encoded instruction, see Table 2-21, “Type 4 Class Exception Conditions”.
EVEX-encoded instruction, see Exceptions Type E4NF.nb in Table 2-50, “Type E4NF Class Exception Conditions”.
4-314
Vol. 2B
PMADDUBSW—Multiply and Add Packed Signed and Unsigned Bytes
INSTRUCTION SET REFERENCE, M-U
PMADDWD—Multiply and Add Packed Integers
Opcode/
Op/
64/32 bit
CPUID
Description
Instruction
En
Mode
Feature
Support
Flag
NP 0F F5 /r1
A
V/V
MMX
Multiply the packed words in mm by the packed
words in mm/m64, add adjacent doubleword
PMADDWD mm, mm/m64
results, and store in mm.
66 0F F5 /r
A
V/V
SSE2
Multiply the packed word integers in xmm1 by
the packed word integers in xmm2/m128, add
PMADDWD xmm1, xmm2/m128
adjacent doubleword results, and store in
xmm1.
VEX.128.66.0F.WIG F5 /r
B
V/V
AVX
Multiply the packed word integers in xmm2 by
the packed word integers in xmm3/m128, add
VPMADDWD xmm1, xmm2, xmm3/m128
adjacent doubleword results, and store in
xmm1.
VEX.256.66.0F.WIG F5 /r
B
V/V
AVX2
Multiply the packed word integers in ymm2 by
the packed word integers in ymm3/m256, add
VPMADDWD ymm1, ymm2, ymm3/m256
adjacent doubleword results, and store in
ymm1.
EVEX.128.66.0F.WIG F5 /r
C
V/V
AVX512VL
Multiply the packed word integers in xmm2 by
VPMADDWD xmm1 {k1}{z}, xmm2, xmm3/m128
AVX512BW
the packed word integers in xmm3/m128, add
adjacent doubleword results, and store in
xmm1 under writemask k1.
EVEX.256.66.0F.WIG F5 /r
C
V/V
AVX512VL
Multiply the packed word integers in ymm2 by
VPMADDWD ymm1 {k1}{z}, ymm2, ymm3/m256
AVX512BW
the packed word integers in ymm3/m256, add
adjacent doubleword results, and store in
ymm1 under writemask k1.
EVEX.512.66.0F.WIG F5 /r
C
V/V
AVX512BW
Multiply the packed word integers in zmm2 by
VPMADDWD zmm1 {k1}{z}, zmm2, zmm3/m512
the packed word integers in zmm3/m512, add
adjacent doubleword results, and store in
zmm1 under writemask k1.
NOTES:
1. See note in Section 2.5, “Intel® AVX and Intel® SSE Instruction Exception Specification” in the Intel® 64 and IA-32 Architectures Soft-
ware Developer’s Manual, Volume 2A and Section 23.25.3, “Exception Conditions of Legacy SIMD Instructions Operating on MMX Reg-
isters” in the Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 3A.
Instruction Operand Encoding
Op/En
Tuple Type
Operand 1
Operand 2
Operand 3
Operand 4
A
N/A
ModRM:reg (r, w)
ModRM:r/m (r)
N/A
N/A
B
N/A
ModRM:reg (w)
VEX.vvvv (r)
ModRM:r/m (r)
N/A
C
Full Mem
ModRM:reg (w)
EVEX.vvvv (r)
ModRM:r/m (r)
N/A
Description
Multiplies the individual signed words of the destination operand (first operand) by the corresponding signed words
of the source operand (second operand), producing temporary signed, doubleword results. The adjacent double-
word results are then summed and stored in the destination operand. For example, the corresponding low-order
words (15-0) and (31-16) in the source and destination operands are multiplied by one another and the double-
word results are added together and stored in the low doubleword of the destination register (31-0). The same
operation is performed on the other pairs of adjacent words. (Figure 4-11 shows this operation when using 64-bit
operands).
PMADDWD—Multiply and Add Packed Integers
Vol. 2B
4-315
INSTRUCTION SET REFERENCE, M-U
The (V)PMADDWD instruction wraps around only in one situation: when the 2 pairs of words being operated on in
a group are all 8000H. In this case, the result wraps around to 80000000H.
In 64-bit mode and not encoded with VEX/EVEX, using a REX prefix in the form of REX.R permits this instruction to
access additional registers (XMM8-XMM15).
Legacy SSE version: The first source and destination operands are MMX registers. The second source operand is an
MMX register or a 64-bit memory location.
128-bit Legacy SSE version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the corresponding YMM destina-
tion register remain unchanged.
VEX.128 encoded version: The first source and destination operands are XMM registers. The second source
operand is an XMM register or a 128-bit memory location. Bits (MAXVL-1:128) of the destination YMM register are
zeroed.
VEX.256 encoded version: The second source operand can be an YMM register or a 256-bit memory location. The
first source and destination operands are YMM registers.
EVEX.512 encoded version: The second source operand can be an ZMM register or a 512-bit memory location. The
first source and destination operands are ZMM registers.
SRC
X3
X2
X1
X0
DEST
Y3
Y2
Y1
Y0
TEMP
X3 Y3
X2 Y2
X1 Y1
X0 Y0
DEST
(X3Y3) + (X2Y2)
(X1Y1) + (X0Y0)
Figure 4-11. PMADDWD Execution Model Using 64-bit Operands
Operation
PMADDWD (with 64-bit operands)
DEST[31:0] := (DEST[15:0] SRC[15:0]) + (DEST[31:16] SRC[31:16]);
DEST[63:32] := (DEST[47:32] SRC[47:32]) + (DEST[63:48] SRC[63:48]);
PMADDWD (with 128-bit operands)
DEST[31:0] := (DEST[15:0] SRC[15:0]) + (DEST[31:16] SRC[31:16]);
DEST[63:32] := (DEST[47:32] SRC[47:32]) + (DEST[63:48] SRC[63:48]);
DEST[95:64] := (DEST[79:64] SRC[79:64]) + (DEST[95:80] SRC[95:80]);
DEST[127:96] := (DEST[111:96] SRC[111:96]) + (DEST[127:112] SRC[127:112]);
VPMADDWD (VEX.128 encoded version)
DEST[31:0] := (SRC1[15:0] * SRC2[15:0]) + (SRC1[31:16] * SRC2[31:16])
DEST[63:32] := (SRC1[47:32] * SRC2[47:32]) + (SRC1[63:48] * SRC2[63:48])
DEST[95:64] := (SRC1[79:64] * SRC2[79:64]) + (SRC1[95:80] * SRC2[95:80])
DEST[127:96] := (SRC1[111:96] * SRC2[111:96]) + (SRC1[127:112] * SRC2[127:112])
DEST[MAXVL-1:128] := 0
4-316
Vol. 2B
PMADDWD—Multiply and Add Packed Integers

 

 

 

 

 

 

 

Content      ..     80      81      82      83     ..