Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic


Visual Studio 2010

Visual Studio 2010 SP1 is required.

Microsoft Specific

Generates the XOP instruction vpperm to select bytes from its first two sources and optionally transform them.

__m128i _mm_perm_epi8 (
   __m128i src1,
   __m128i src2,
   __m128i selector
[in] src1

A 128-bit parameter that contains sixteen bytes.

[in] src2

A 128-bit parameter that contains sixteen bytes.

[in] selector

A 128-bit parameter that selects bytes from src1 and src2 and optionally chooses a transformation to apply to the selected byte.

A 128-bit result r that contains bytes selected from src1 and src2 and is optionally transformed.





Header file <intrin.h>

For each byte in selector, the low-order bits select a byte from src1 or src2. Values 0 to 15 select bytes 0 to 15 of src1, while values 16 to 31 select bytes 0 to 15 of src2. The high-order bits of each byte in selector determine what transformation, if any, to apply to the selected byte.

Value of high-order 3 bits of selector

Transformation chosen


No transformation


Invert (ones complement) source byte


Bit reverse source byte


Bit reverse inverted source byte


Set result byte to 0x00


Set result byte to 0xFF


Replicate most significant bit of source byte


Replicate inverted most significant bit of source byte

The vpperm instruction is part of the XOP family of instructions. Before you use this intrinsic, you must ensure that the processor supports this instruction. To determine hardware support for this instruction, call the __cpuid intrinsic with InfoType = 0x80000001 and check bit 11 of CPUInfo[2] (ECX). This bit is 1 when the instruction is supported, and 0 otherwise.

#include <stdio.h>
#include <intrin.h>
int main()
    __m128i a, b, selector, d;
    int i;
    for (i = 15; i >= 0; i--) {
        a.m128i_u8[i] = i;               // 0x0f0e0d0c...
        b.m128i_u8[i] = (i << 4) | i;    // 0xffeeddcc...
    selector.m128i_u64[1] = 0xfedcba9876543210ll;
    selector.m128i_u64[0] = 0x0011223344556677ll;
    d = _mm_perm_epi8(a, b, selector);
    printf_s("%016I64x %016I64x\n", d.m128i_u64[1], d.m128i_u64[0]);
00ffff009922dd00 0011fdcc20aa9f11
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.