Skip to content
This repository has been archived by the owner on Mar 21, 2024. It is now read-only.

Commit

Permalink
Touch up c-style casts and test bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
djns99 committed Jan 4, 2022
1 parent ca86e2e commit 9e25fe9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions testing/shuffle.cu
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ void TestFunctionIsBijection(size_t m) {
thrust::system::detail::generic::feistel_bijection host_f(m, host_g);
thrust::system::detail::generic::feistel_bijection device_f(m, device_g);

if (host_f.nearest_power_of_two() >= std::numeric_limits<T>::max() || m == 0) {
if (static_cast<double>(host_f.nearest_power_of_two()) >= static_cast<double>(std::numeric_limits<T>::max()) || m == 0) {
return;
}

Expand All @@ -409,17 +409,17 @@ DECLARE_VARIABLE_UNITTEST(TestFunctionIsBijection);
void TestBijectionLength() {
thrust::default_random_engine g(0xD5);

uint64_t m = 3;
uint64_t m = 31;
thrust::system::detail::generic::feistel_bijection f(m, g);
ASSERT_EQUAL(f.nearest_power_of_two(), uint64_t(4));
ASSERT_EQUAL(f.nearest_power_of_two(), uint64_t(32));

m = 2;
m = 32;
f = thrust::system::detail::generic::feistel_bijection(m, g);
ASSERT_EQUAL(f.nearest_power_of_two(), uint64_t(2));
ASSERT_EQUAL(f.nearest_power_of_two(), uint64_t(32));

m = 0;
m = 1;
f = thrust::system::detail::generic::feistel_bijection(m, g);
ASSERT_EQUAL(f.nearest_power_of_two(), uint64_t(1));
ASSERT_EQUAL(f.nearest_power_of_two(), uint64_t(16));
}
DECLARE_UNITTEST(TestBijectionLength);

Expand Down Expand Up @@ -560,7 +560,7 @@ void TestShuffleEvenDistribution() {
const uint64_t shuffle_sizes[] = {10, 100, 500};
thrust::default_random_engine g(0xD5);
for (auto shuffle_size : shuffle_sizes) {
if(shuffle_size > std::numeric_limits<T>::max())
if(shuffle_size > (uint64_t)std::numeric_limits<T>::max())
continue;
const uint64_t num_samples = shuffle_size == 500 ? 1000 : 200;

Expand Down
8 changes: 4 additions & 4 deletions thrust/system/detail/generic/shuffle.inl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class feistel_bijection {
}

__host__ __device__ std::uint64_t operator()(const std::uint64_t val) const {
std::uint32_t state[2] = { uint32_t( val >> right_side_bits ), uint32_t( val & right_side_mask ) };
std::uint32_t state[2] = { static_cast<std::uint32_t>( val >> right_side_bits ), static_cast<std::uint32_t>( val & right_side_mask ) };
for( std::uint32_t i = 0; i < num_rounds; i++ )
{
std::uint32_t hi, lo;
Expand All @@ -69,16 +69,16 @@ class feistel_bijection {
state[1] = lo & right_side_mask;
}
// Combine the left and right sides together to get result
return (std::uint64_t)state[0] << right_side_bits | (std::uint64_t)state[1];
return static_cast<std::uint64_t>(state[0] << right_side_bits) | static_cast<std::uint64_t>(state[1]);
}

private:
// Perform 64 bit multiplication and save result in two 32 bit int
constexpr static __host__ __device__ void mulhilo( std::uint64_t a, std::uint64_t b, std::uint32_t& hi, std::uint32_t& lo )
{
std::uint64_t product = a * b;
hi = std::uint32_t( product >> 32 );
lo = std::uint32_t( product );
hi = static_cast<std::uint32_t>( product >> 32 );
lo = static_cast<std::uint32_t>( product );
}

// Find the nearest power of two
Expand Down

0 comments on commit 9e25fe9

Please sign in to comment.