packages/engine/scram/src/ext/bits.h
Helper constexpr functions to make bit operations explicit.
Namespaces
| Name |
|---|
| ext |
Source code
cpp
/*
* Copyright (C) 2014-2018 Olzhas Rakhimov
* Copyright (C) 2023 OpenPRA ORG Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace ext {
constexpr bool test_bit(std::uint64_t bits, int index) {
return bits & (std::uint64_t(1) << index);
}
constexpr int count_trailing_zero_bits(std::uint64_t bits) {
#if defined(__GNUC__)
return __builtin_ctzl(bits);
#else
int i = 0;
while (!test_bit(bits, i))
++i;
return i;
#endif
}
constexpr int one_bit_index(std::uint64_t bits) {
return count_trailing_zero_bits(bits);
}
} // namespace extUpdated on 2026-01-09 at 21:59:12 +0000
