
#pragma once

#include "utils.hpp"
#include <cfloat>
#include <cstdint>
#include <cuda_fp16.h>
#include <raft/core/detail/macros.hpp>

namespace cuvs::neighbors::cagra::detail {
namespace device {

// warpSize for compile time calculation
constexpr unsigned warp_size = 32;

/** Xorshift rondem number generator.
 *
 * See https://en.wikipedia.org/wiki/Xorshift#xorshift for reference.
 */
_RAFT_HOST_DEVICE inline uint64_t xorshift64(uint64_t u)
{
  u ^= u >> 12;
  u ^= u << 25;
  u ^= u >> 27;
  return u * 0x2545F4914F6CDD1DULL;
}

template <class T>
_RAFT_DEVICE inline T swizzling(T x)
{
  // Address swizzling reduces bank conflicts in shared memory, but increases
  // the amount of operation instead.
  // return x;
  return x ^ (x >> 5);  // "x" must be less than 1024
}

}  // namespace device
}  // namespace cuvs::neighbors::cagra::detail
