_mm_ternarylogic_epi32
Classification
AVX-512, Logical, CPUID Test: AVX512F
Header File
immintrin.h
Instruction
VPTERNLOGD xmm, xmm, xmm, imm8
Synopsis
 _mm_ternarylogic_epi32(__m128i a, __m128i b, __m128i c, int imm8);
Description
Bitwise ternary logic that provides the capability to implement any three-operand binary function; the specific binary function is specified by value in "imm8". For each bit in each packed 32-bit integer, the corresponding bit from "a", "b", and "c" are used according to "imm8", and the result is written to the corresponding bit in "dst".
Operation
DEFINE TernaryOP(imm8, a, b, c) {
	CASE imm8[7:0] OF
	0: dst[0] := 0                   // imm8[7:0] := 0
	1: dst[0] := NOT (a OR b OR c)   // imm8[7:0] := NOT (_MM_TERNLOG_A OR _MM_TERNLOG_B OR _MM_TERNLOG_C)
	// ...
	254: dst[0] := a OR b OR c       // imm8[7:0] := _MM_TERNLOG_A OR _MM_TERNLOG_B OR _MM_TERNLOG_C
	255: dst[0] := 1                 // imm8[7:0] := 1
	ESAC
}
imm8[7:0] = LogicExp(_MM_TERNLOG_A, _MM_TERNLOG_B, _MM_TERNLOG_C)
FOR j := 0 to 3
	i := j*32
	FOR h := 0 to 31
		dst[i+h] := TernaryOP(imm8[7:0], a[i+h], b[i+h], c[i+h])
	ENDFOR
ENDFOR
dst[MAX:128] := 0