-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathVPCLMULQDQ_Demo_Test.cpp
87 lines (76 loc) · 3.36 KB
/
VPCLMULQDQ_Demo_Test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// VPCLMULQDQ_Demo.cpp
#include "stdafx.h"
#include "VPCLMULQDQ_Demo.h"
extern CPU_Props cpu_props;
using namespace std;
void VPCLMULQDQ_Demo_prefix_xor(void) {
//PS-XOR(x) ^ PS-XOR(y) == PS-XOR(x ^ y)
unsigned long long q64_0 = 0, q64_1 = 0;
#if !defined(_M_X64)
while (!_rdrand32_step((unsigned int *)&q64_0));
while (!_rdrand32_step((unsigned int *)&q64_0 + 1));
while (!_rdrand32_step((unsigned int *)&q64_1));
while (!_rdrand32_step((unsigned int *)&q64_1 + 1));
#else
while (!_rdrand64_step(&q64_0));
while (!_rdrand64_step(&q64_1));
#endif
if (cpu_props.IsFeat(FEAT_CLMUL)) {
__m128i x128 = _mm_set_epi64x(q64_0, _rotl64(q64_0, q64_0 & 0x3f));
__m128i y128 = _mm_set_epi64x(q64_1, _rotl64(q64_1, q64_1 & 0x3f));
__m128i test128 = _mm_xor_si128(
_mm_xor_si128(_mm_prefix_xor_clmul_si128(x128), _mm_prefix_xor_clmul_si128(y128)),
_mm_prefix_xor_clmul_si128(_mm_xor_si128(x128, y128)));
assert(_mm_testz_si128(test128, test128));
printRes("x128 ", x128);
printRes("_mm_prefix_xor_clmul_si128 ", _mm_prefix_xor_clmul_si128(x128));
}
#if defined(__AVX2__)
if (cpu_props.IsFeat(FEAT_AVX_VPCLMULQDQ)) {
unsigned long long q64_2 = 0, q64_3 = 0;
#if !defined(_M_X64)
while (!_rdrand32_step((unsigned int *)&q64_2));
while (!_rdrand32_step((unsigned int *)&q64_2 + 1));
while (!_rdrand32_step((unsigned int *)&q64_3));
while (!_rdrand32_step((unsigned int *)&q64_3 + 1));
#else
while (!_rdrand64_step(&q64_2));
while (!_rdrand64_step(&q64_3));
#endif
__m256i x256 = _mm256_set_epi64x(q64_0, _rotl64(q64_0, q64_0 & 0x3f), q64_2, _rotl64(q64_2, q64_2 & 0x3f));
__m256i y256 = _mm256_set_epi64x(q64_1, _rotl64(q64_1, q64_1 & 0x3f), q64_3, _rotl64(q64_3, q64_3 & 0x3f));
__m256i test256 = _mm256_xor_si256(
_mm256_xor_si256(_mm256_prefix_xor_clmul_si256(x256), _mm256_prefix_xor_clmul_si256(y256)),
_mm256_prefix_xor_clmul_si256(_mm256_xor_si256(x256, y256)));
assert(_mm256_testz_si256(test256, test256));
printRes("x256 ", x256);
printRes("_mm256_prefix_xor_clmul_si256 ", _mm256_prefix_xor_clmul_si256(x256));
}
#endif
#if defined(__AVX512F__)
if (cpu_props.IsFeat(FEAT_AVX512_VPCLMULQDQ)) {
unsigned long long q64_2 = 0, q64_3 = 0;
#if !defined(_M_X64)
while (!_rdrand32_step((unsigned int *)&q64_2));
while (!_rdrand32_step((unsigned int *)&q64_2 + 1));
while (!_rdrand32_step((unsigned int *)&q64_3));
while (!_rdrand32_step((unsigned int *)&q64_3 + 1));
#else
while (!_rdrand64_step(&q64_2));
while (!_rdrand64_step(&q64_3));
#endif
__m512i x512 = _mm512_set_epi64(q64_0, _rotl64(q64_0, q64_0 & 0x3f), q64_2, _rotl64(q64_2, q64_2 & 0x3f), q64_1, _rotl64(q64_1, q64_0 & 0x3f), q64_3, _rotl64(q64_2, q64_2 & 0x3f));
__m512i y512 = _mm512_set_epi64(q64_1, _rotl64(q64_1, q64_1 & 0x3f), q64_3, _rotl64(q64_3, q64_3 & 0x3f), q64_0, _rotl64(q64_0, q64_1 & 0x3f), q64_2, _rotl64(q64_3, q64_3 & 0x3f));
__mmask64 test512 =_mm512_cmpeq_epi8_mask(
_mm512_xor_si512(_mm512_prefix_xor_clmul_si512(x512), _mm512_prefix_xor_clmul_si512(y512)),
_mm512_prefix_xor_clmul_si512(_mm512_xor_si512(x512, y512)));
assert(test512);
printRes("x512 ", x512);
printRes("_mm512_prefix_xor_clmul_si512 ", _mm512_prefix_xor_clmul_si512(x512));
}
#endif
}
void VPCLMULQDQ_Demo(void) {
cout << "-----------------------------------" << endl;
VPCLMULQDQ_Demo_prefix_xor();
}