_mm512_mask_ternarylogic_epi32
Classification
AVX-512, Logical, CPUID Test: AVX512F
Header File
immintrin.h
Instruction
VPTERNLOGD zmm {k}, zmm, zmm, imm8
Synopsis
 _mm512_mask_ternarylogic_epi32(__m512i a, __mmask16 k, __m512i b, __m512i 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" using writemask "k" at 32-bit granularity (32-bit elements are copied from "a" when the corresponding mask bit is not set).
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 15
	i := j*32
	IF k[j]
		FOR h := 0 to 31
			dst[i+h] := TernaryOP(imm8[7:0], a[i+h], b[i+h], c[i+h])
		ENDFOR
	ELSE
		dst[i+31:i] := src[i+31:i]
	FI
ENDFOR
dst[MAX:512] := 0