-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlgr_material_set.hpp
93 lines (85 loc) · 2.13 KB
/
lgr_material_set.hpp
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#pragma once
#include <lgr_mesh_indices.hpp>
namespace lgr {
HPC_ALWAYS_INLINE HPC_HOST_DEVICE int
popcount(unsigned x) noexcept
{
#ifdef __CUDA_ARCH__
return __popc(x);
#else
return __builtin_popcount(x);
#endif
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE int
popcount(unsigned long x) noexcept
{
#ifdef __CUDA_ARCH__
return __popcll(x);
#else
return __builtin_popcountl(x);
#endif
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE int
popcount(unsigned long long x) noexcept
{
#ifdef __CUDA_ARCH__
return __popcll(x);
#else
return __builtin_popcountll(x);
#endif
}
class material_set
{
std::uint64_t bits{0};
HPC_ALWAYS_INLINE HPC_HOST_DEVICE explicit constexpr material_set(std::uint64_t const bits_in) noexcept
: bits(bits_in)
{
}
public:
HPC_ALWAYS_INLINE HPC_HOST_DEVICE explicit constexpr material_set(material_index const material) noexcept
: bits(std::uint64_t(1) << hpc::weaken(material))
{
}
HPC_ALWAYS_INLINE
material_set() noexcept = default;
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr material_set
operator|(material_set const other) const noexcept
{
return material_set(bits | other.bits);
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr bool
contains(material_set const other) const noexcept
{
return (bits | other.bits) == bits;
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr explicit operator std::uint64_t() const noexcept
{
return bits;
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE int
size() const noexcept
{
return popcount(bits);
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr material_set
operator-(material_set const other) const noexcept
{
return material_set(bits & (~other.bits));
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr static material_set
none() noexcept
{
return material_set(std::uint64_t(0));
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr static material_set
all(material_index const size) noexcept
{
return material_set((std::uint64_t(1) << hpc::weaken(size)) - 1);
}
HPC_ALWAYS_INLINE HPC_HOST_DEVICE constexpr bool
operator==(material_set const other) const noexcept
{
return bits == other.bits;
}
};
} // namespace lgr