_mm_permute2_ps
Visual Studio 2010 SP1 is required.
Microsoft Specific
Generates the XOP XMM instruction vpermil2ps to select floating-point values from its first two sources, with optional zeroing.
__m128 _mm_permute2_ps (
__m128 src1,
__m128 src2,
__m128i selector,
int control
);
Parameters
[in] src1
A 128-bit parameter that contains four 32-bit floating-point values.[in] src2
A 128-bit parameter that contains four 32-bit floating-point values.[in] selector
A 128-bit parameter that contains four 32-bit integer selector values.[in] control
A 32-bit integer parameter that controls the method of deciding whether to zero values in the result.
Return value
A 128-bit result r that contains four 32-bit floating-point values.
Each value in the result is either zero or a value chosen from the eight 32-bit floating-point values in src1 and src2.
Requirements
Intrinsic |
Architecture |
---|---|
_mm_permute2_ps |
XOP |
Header file <intrin.h>
Remarks
Each of the four doublewords in selector selects the value for its corresponding doubleword of the result from one of the eight 32-bit floating-point values in src1 and src2. This value may be replaced by zero before being written to the result, depending on the value of control and the value of bit 3 of the selector doubleword.
For each doubleword in selector, the three low-order bits select one of the floating-point values in src1 or src2, with values 0 through 3 selecting src1[0] through src1[3] and values 4 through 7 selecting src2[0] through src2[3].
The next bit of each doubleword in selector will be referred to as the "match" bit below. The high-order 28 bits of each doubleword in selector are ignored.
The fourth source, control, determines the conditions under which result values will be set to 0. The value of control must be 0, 1, 2, or 3. If control is 0 or 1, the selected floating-point value is written to the destination. If control is 2, then the selected floating-point value is written to the destination if the corresponding match bit in selector is 0, but zero is written if the match bit is 1. If control is 3, then the selected floating-point value is written to the destination if the corresponding match bit is 1, but zero is written if the match bit is 0.
The vpermil2ps 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.
Example
#include <stdio.h>
#include <intrin.h>
int main()
{
__m128 a, b, d;
__m128i select;
int i;
for (i = 0; i < 4; i++) {
a.m128_f32[i] = i;
b.m128_f32[i] = i+4;
}
select.m128i_i32[0] = 5;
select.m128i_i32[1] = 1 + 8; // turn on match bit
select.m128i_i32[2] = 2;
select.m128i_i32[3] = 6 + 8; // turn on match bit
d = _mm_permute2_ps(a, b, select, 0); // just select, don't zero
for (i = 0; i < 4; i++) printf_s(" %.3f", d.m128_f32[i]);
printf_s("\n");
d = _mm_permute2_ps(a, b, select, 2); // zero if match is 1
for (i = 0; i < 4; i++) printf_s(" %.3f", d.m128_f32[i]);
printf_s("\n");
d = _mm_permute2_ps(a, b, select, 3); // zero if match is 0
for (i = 0; i < 4; i++) printf_s(" %.3f", d.m128_f32[i]);
printf_s("\n");
}
5.000 1.000 2.000 6.000 5.000 0.000 2.000 0.000 0.000 1.000 0.000 6.000