-
Notifications
You must be signed in to change notification settings - Fork 1
/
bit.h
29 lines (24 loc) · 794 Bytes
/
bit.h
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
// A few bit twiddling functions beyond <bit>
#pragma once
#include "cutil.h"
#include <bit>
#include <cstdint>
#include <type_traits>
namespace mandelbrot {
using std::is_same_v;
using std::is_unsigned_v;
using std::bit_ceil;
using std::countl_zero;
using std::countr_zero;
using std::has_single_bit;
template<class I> I byteswap(I n) {
static_assert(is_unsigned_v<I>);
if constexpr (is_same_v<I,uint32_t>) return __builtin_bswap32(n);
else if constexpr (is_same_v<I,uint64_t>) return __builtin_bswap64(n);
}
template<class I> __host__ __device__ I bitreverse(I n) {
static_assert(is_unsigned_v<I>);
if constexpr (is_same_v<I,uint32_t>) return __builtin_bitreverse32(n);
else if constexpr (is_same_v<I,uint64_t>) return __builtin_bitreverse64(n);
}
} // namespace mandelbrot