stdgpu/bit.h Source File

stdgpu/bit.h Source File#

stdgpu: stdgpu/bit.h Source File
stdgpu Latest
Efficient STL-like Data Structures on the GPU
bit.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Patrick Stotko
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef STDGPU_BIT_H
17#define STDGPU_BIT_H
18
28#include <type_traits>
29
30#include <stdgpu/platform.h>
31#include <stdgpu/type_traits.h>
32
33namespace stdgpu
34{
35
42template <typename T, STDGPU_DETAIL_OVERLOAD_IF(std::is_unsigned_v<T>)>
44has_single_bit(const T number) noexcept;
45
52template <typename T, STDGPU_DETAIL_OVERLOAD_IF(std::is_unsigned_v<T>)>
54bit_ceil(const T number) noexcept;
55
62template <typename T, STDGPU_DETAIL_OVERLOAD_IF(std::is_unsigned_v<T>)>
64bit_floor(const T number) noexcept;
65
76template <typename T, STDGPU_DETAIL_OVERLOAD_IF(std::is_unsigned_v<T>)>
78bit_mod(const T number, const T divider) noexcept;
79
88template <typename T, STDGPU_DETAIL_OVERLOAD_IF(std::is_unsigned_v<T>)>
90bit_width(const T number) noexcept;
91
100template <typename T, STDGPU_DETAIL_OVERLOAD_IF(std::is_unsigned_v<T>)>
102popcount(const T number) noexcept;
103
110template <typename To,
111 typename From,
112 STDGPU_DETAIL_OVERLOAD_IF(sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<To> &&
113 std::is_trivially_copyable_v<From>)>
115bit_cast(const From& object) noexcept;
116
117} // namespace stdgpu
118
119#include <stdgpu/impl/bit_detail.h>
120
121#endif // STDGPU_BIT_H
STDGPU_HOST_DEVICE T bit_ceil(const T number) noexcept
Computes the smallest power of two which is larger or equal than the given number.
STDGPU_HOST_DEVICE T bit_floor(const T number) noexcept
Computes the largest power of two which is smaller or equal than the given number.
STDGPU_HOST_DEVICE int popcount(const T number) noexcept
Counts the number of set bits in the number.
STDGPU_HOST_DEVICE T bit_width(const T number) noexcept
Computes the smallest number of bits to represent the given number.
STDGPU_HOST_DEVICE T bit_mod(const T number, const T divider) noexcept
Computes the modulus of the given number and a power of two divider.
STDGPU_HOST_DEVICE bool has_single_bit(const T number) noexcept
Determines whether the number is a power of two.
STDGPU_HOST_DEVICE To bit_cast(const From &object) noexcept
Reinterprets the object of the given type as an instance of the desired type.
#define STDGPU_HOST_DEVICE
Platform-independent host device function annotation.
Definition: platform.h:77