tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
rotl.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_BIT_ROTL_HPP
5#define TETL_BIT_ROTL_HPP
6
7#include <etl/_concepts/builtin_unsigned_integer.hpp>
8#include <etl/_limits/numeric_limits.hpp>
9
10namespace etl {
11
12/// \brief Computes the result of bitwise left-rotating the value of x by s
13/// positions. This operation is also known as a left circular shift.
14///
15/// \ingroup bit
16template <etl::builtin_unsigned_integer UInt>
17constexpr auto rotl(UInt t, int s) noexcept -> UInt
18{
19 auto const c = static_cast<unsigned>(s);
20 auto const d = static_cast<unsigned>(etl::numeric_limits<UInt>::digits);
21 if ((c % d) == 0U) {
22 return t;
23 }
24 return static_cast<UInt>((t << (c % d)) | (t >> (d - (c % d))));
25}
26
27} // namespace etl
28
29#endif // TETL_BIT_ROTL_HPP
constexpr auto rotl(UInt t, int s) noexcept -> UInt
Computes the result of bitwise left-rotating the value of x by s positions. This operation is also kn...
Definition rotl.hpp:17
Definition adjacent_find.hpp:9
Definition numeric_limits.hpp:18