limex_shuffle added and it's unit tests

This commit is contained in:
apostolos
2021-07-27 11:44:35 +03:00
committed by Konstantinos Margaritis
parent b9fbfb1204
commit 150ae10ea4
3 changed files with 320 additions and 10 deletions

View File

@@ -33,6 +33,9 @@
#include "util/arch.h"
#include "util/simd_utils.h"
#include "nfa/limex_shuffle.h"
#include"util/supervector/supervector.hpp"
#include "nfa/limex_shuffle.hpp"
namespace {
@@ -196,6 +199,26 @@ TEST(Shuffle, PackedExtract128_1) {
}
}
TEST(Shuffle, PackedExtract_templatized_128_1) {
// Try all possible one-bit masks
for (unsigned int i = 0; i < 128; i++) {
// shuffle a single 1 bit to the front
SuperVector<16> permute = SuperVector<16>::Zeroes();
SuperVector<16> compare = SuperVector<16>::Zeroes();
build_pshufb_masks_onebit(i, &permute.u.v128[0], &compare.u.v128[0]);
EXPECT_EQ(1U, packedExtract<16>(setbit<m128>(i), permute, compare));
EXPECT_EQ(1U, packedExtract<16>(SuperVector<16>::Ones(), permute, compare));
// we should get zero out of these cases
EXPECT_EQ(0U, packedExtract<16>(SuperVector<16>::Zeroes(), permute, compare));
EXPECT_EQ(0U, packedExtract<16>(not128(setbit<m128>(i)), permute, compare));
// we should get zero out of all the other bit positions
for (unsigned int j = 0; (j != i && j < 128); j++) {
EXPECT_EQ(0U, packedExtract<16>(setbit<m128>(j), permute, compare));
}
}
}
#if defined(HAVE_AVX2)
TEST(Shuffle, PackedExtract256_1) {
// Try all possible one-bit masks
@@ -214,6 +237,27 @@ TEST(Shuffle, PackedExtract256_1) {
}
}
}
TEST(Shuffle, PackedExtract_templatized_256_1) {
// Try all possible one-bit masks
for (unsigned int i = 0; i < 256; i++) {
// shuffle a single 1 bit to the front
SuperVector<32> permute = SuperVector<32>::Zeroes();
SuperVector<32> compare = SuperVector<32>::Zeroes();
build_pshufb_masks_onebit(i, &permute.u.v256[0], &compare.u.v256[0]);
EXPECT_EQ(1U, packedExtract<32>(setbit<m256>(i), permute, compare));
EXPECT_EQ(1U, packedExtract<32>(SuperVector<32>::Ones(), permute, compare));
// we should get zero out of these cases
EXPECT_EQ(0U, packedExtract<32>(SuperVector<32>::Zeroes(), permute, compare));
EXPECT_EQ(0U, packedExtract<32>(not256(setbit<m256>(i)), permute, compare));
// we should get zero out of all the other bit positions
for (unsigned int j = 0; (j != i && j < 256); j++) {
EXPECT_EQ(0U, packedExtract<32>(setbit<m256>(j), permute, compare));
}
}
}
#endif
#if defined(HAVE_AVX512)
@@ -234,5 +278,25 @@ TEST(Shuffle, PackedExtract512_1) {
}
}
}
TEST(Shuffle, PackedExtract_templatized_512_1) {
// Try all possible one-bit masks
for (unsigned int i = 0; i < 512; i++) {
// shuffle a single 1 bit to the front
SuperVector<64> permute = SuperVector<64>::Zeroes();
SuperVector<64> compare = SuperVector<64>::Zeroes();
build_pshufb_masks_onebit(i, &permute.u.v512[0], &compare.u.v512[0]);
EXPECT_EQ(1U, packedExtract<64>(setbit<m512>(i), permute, compare));
EXPECT_EQ(1U, packedExtract<64>(SuperVector<64>::Ones(), permute, compare));
// we should get zero out of these cases
EXPECT_EQ(0U, packedExtract<64>(SuperVector<64>::Zeroes(), permute, compare));
EXPECT_EQ(0U, packedExtract<64>(not512(setbit<m512>(i)), permute, compare));
// we should get zero out of all the other bit positions
for (unsigned int j = 0; (j != i && j < 512); j++) {
EXPECT_EQ(0U, packedExtract<64>(setbit<m512>(j), permute, compare));
}
}
}
#endif
} // namespace