proxygen
Select64Test.cpp File Reference
#include <folly/experimental/Select64.h>
#include <cstddef>
#include <cstdint>
#include <folly/experimental/Instructions.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Classes

class  Select64Test
 

Typedefs

using TestArch = folly::compression::instructions::Default
 

Functions

uint64_t check_select64_default (uint64_t x, uint64_t k)
 
uint64_t check_select64_haswell (uint64_t x, uint64_t k)
 
 TEST_F (Select64Test, SelectInByteTable)
 
 TEST_F (Select64Test, Select64)
 

Typedef Documentation

Function Documentation

uint64_t check_select64_default ( uint64_t  x,
uint64_t  k 
)

Definition at line 26 of file Select64Test.cpp.

References k, and x.

26  {
27  return folly::select64<folly::compression::instructions::Default>(x, k);
28 }
const int x
KeyT k
uint64_t check_select64_haswell ( uint64_t  x,
uint64_t  k 
)

Definition at line 29 of file Select64Test.cpp.

References k, and x.

29  {
30  return folly::select64<folly::compression::instructions::Haswell>(x, k);
31 }
const int x
KeyT k
TEST_F ( Select64Test  ,
SelectInByteTable   
)

Definition at line 37 of file Select64Test.cpp.

References EXPECT_EQ, i, folly::detail::kSelectInByte, and uint8_t.

37  {
38  for (size_t i = 0u; i < 256u; ++i) {
39  uint8_t decoded = 0;
40  for (size_t j = 0u; j < 8u; ++j) {
41  auto const entry = folly::detail::kSelectInByte[j][i];
42  decoded |= uint8_t(entry != 8) << entry;
43  }
44  EXPECT_EQ(i, decoded);
45  }
46 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
FOLLY_STORAGE_CONSTEXPR std::array< std::array< std::uint8_t, 256 >, 8 > const kSelectInByte
Definition: Select64.cpp:57
TEST_F ( Select64Test  ,
Select64   
)

Definition at line 48 of file Select64Test.cpp.

References i, k, folly::popcount(), uint64_t, and x.

48  {
49  using instr = TestArch;
50  constexpr uint64_t kPrime = uint64_t(-59);
51  for (uint64_t x = kPrime, i = 0; i < (1 << 20); x *= kPrime, i += 1) {
52  auto const w = instr::popcount(x);
53  for (size_t k = 0; k < w; ++k) {
54  auto const pos = folly::select64<instr>(x, k);
55  CHECK_EQ((x >> pos) & 1, 1);
56  CHECK_EQ(instr::popcount(x & ((uint64_t(1) << pos) - 1)), k);
57  }
58  }
59 }
constexpr unsigned int popcount(T const v)
Definition: Bits.h:130
Definition: InvokeTest.cpp:58
const int x
folly::compression::instructions::Default TestArch
KeyT k