Files
compute-runtime/common/helpers/bit_helpers.h
Maciej Plewka 9e52684f5b Change namespace from OCLRT to NEO
Change-Id: If965c79d70392db26597aea4c2f3b7ae2820fe96
Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
2019-03-26 15:48:19 +01:00

30 lines
633 B
C++

/*
* Copyright (C) 2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <cassert>
#include <cstdint>
#include <limits>
namespace NEO {
constexpr bool isBitSet(uint64_t field, uint64_t bitPosition) {
assert(bitPosition < std::numeric_limits<uint64_t>::digits); // undefined behavior
return (field & (1ull << bitPosition));
}
constexpr bool isValueSet(uint64_t field, uint64_t value) {
assert(value != 0);
return ((field & value) == value);
}
constexpr bool isFieldValid(uint64_t field, uint64_t acceptedBits) {
return ((field & (~acceptedBits)) == 0);
}
} // namespace NEO