Skip to content

Commit 0193b3e

Browse files
Change maxNBitValue to a constexpr function
Now maxNBitValue can be used with run time variables. Change-Id: I323071400305e05e6303a33e24e90c521246d73f Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
1 parent 0ba31a4 commit 0193b3e

36 files changed

+66
-63
lines changed

core/memory_manager/gfx_partition.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
106106
const uint64_t gfxHeap32Size = 4 * MemoryConstants::gigaByte;
107107

108108
if (is32bit) {
109-
gfxBase = maxNBitValue<32> + 1;
109+
gfxBase = maxNBitValue(32) + 1;
110110
heapInit(HeapIndex::HEAP_SVM, 0ull, gfxBase);
111111
} else {
112-
if (gpuAddressSpace == maxNBitValue<48>) {
113-
gfxBase = maxNBitValue<48 - 1> + 1;
112+
if (gpuAddressSpace == maxNBitValue(48)) {
113+
gfxBase = maxNBitValue(48 - 1) + 1;
114114
heapInit(HeapIndex::HEAP_SVM, 0ull, gfxBase);
115-
} else if (gpuAddressSpace == maxNBitValue<47>) {
115+
} else if (gpuAddressSpace == maxNBitValue(47)) {
116116
reservedCpuAddressRangeSize = cpuAddressRangeSizeToReserve;
117117
UNRECOVERABLE_IF(reservedCpuAddressRangeSize == 0);
118118
reservedCpuAddressRange = osMemory->reserveCpuAddressRange(reservedCpuAddressRangeSize);
@@ -121,7 +121,7 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
121121
gfxBase = reinterpret_cast<uint64_t>(reservedCpuAddressRange);
122122
gfxTop = gfxBase + reservedCpuAddressRangeSize;
123123
heapInit(HeapIndex::HEAP_SVM, 0ull, gpuAddressSpace + 1);
124-
} else if (gpuAddressSpace < maxNBitValue<47>) {
124+
} else if (gpuAddressSpace < maxNBitValue(47)) {
125125
gfxBase = 0ull;
126126
heapInit(HeapIndex::HEAP_SVM, 0ull, 0ull);
127127
} else {

core/memory_manager/graphics_allocation.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
230230
uint32_t inspectionId = 0u;
231231
};
232232
struct AubInfo {
233-
uint32_t aubWritable = maxNBitValue<32>;
234-
uint32_t tbxWritable = maxNBitValue<32>;
233+
uint32_t aubWritable = std::numeric_limits<uint32_t>::max();
234+
uint32_t tbxWritable = std::numeric_limits<uint32_t>::max();
235235
bool allocDumpable = false;
236236
bool memObjectsAllocationWithWritableFlags = false;
237237
};

core/memory_manager/memory_constants.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
constexpr bool is32bit = (sizeof(void *) == 4);
1414
constexpr bool is64bit = (sizeof(void *) == 8);
1515

16-
template <uint8_t N>
17-
constexpr uint64_t maxNBitValue = ((1ULL << N) - 1);
18-
static_assert(maxNBitValue<8> == std::numeric_limits<uint8_t>::max(), "");
19-
static_assert(maxNBitValue<16> == std::numeric_limits<uint16_t>::max(), "");
20-
static_assert(maxNBitValue<32> == std::numeric_limits<uint32_t>::max(), "");
16+
constexpr uint64_t maxNBitValue(uint64_t n) {
17+
return ((1ULL << n) - 1);
18+
}
19+
static_assert(maxNBitValue(8) == std::numeric_limits<uint8_t>::max(), "");
20+
static_assert(maxNBitValue(16) == std::numeric_limits<uint16_t>::max(), "");
21+
static_assert(maxNBitValue(32) == std::numeric_limits<uint32_t>::max(), "");
2122

2223
namespace MemoryConstants {
2324
static const uint64_t zoneHigh = ~(uint64_t)0xFFFFFFFF;
@@ -35,16 +36,16 @@ static const size_t slmWindowAlignment = 128 * kiloByte;
3536
static const size_t slmWindowSize = 64 * kiloByte;
3637
static const uintptr_t pageMask = (pageSize - 1);
3738
static const uintptr_t page64kMask = (pageSize64k - 1);
38-
static const uint64_t max32BitAppAddress = maxNBitValue<31>;
39-
static const uint64_t max64BitAppAddress = maxNBitValue<47>;
39+
static const uint64_t max32BitAppAddress = maxNBitValue(31);
40+
static const uint64_t max64BitAppAddress = maxNBitValue(47);
4041
static const uint32_t sizeOf4GBinPageEntities = (MemoryConstants::gigaByte * 4 - MemoryConstants::pageSize) / MemoryConstants::pageSize;
41-
static const uint64_t max32BitAddress = maxNBitValue<32>;
42-
static const uint64_t max36BitAddress = ((1ULL << 36) - 1);
43-
static const uint64_t max48BitAddress = maxNBitValue<48>;
42+
static const uint64_t max32BitAddress = maxNBitValue(32);
43+
static const uint64_t max36BitAddress = (maxNBitValue(36));
44+
static const uint64_t max48BitAddress = maxNBitValue(48);
4445
static const uintptr_t page4kEntryMask = std::numeric_limits<uintptr_t>::max() & ~MemoryConstants::pageMask;
4546
static const uintptr_t page64kEntryMask = std::numeric_limits<uintptr_t>::max() & ~MemoryConstants::page64kMask;
4647
static const int GfxAddressBits = is64bit ? 48 : 32;
47-
static const uint64_t maxSvmAddress = is64bit ? maxNBitValue<47> : maxNBitValue<32>;
48+
static const uint64_t maxSvmAddress = is64bit ? maxNBitValue(47) : maxNBitValue(32);
4849

4950
} // namespace MemoryConstants
5051

core/unit_tests/compiler_interface/compiler_interface_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ TEST(TranslateTest, givenNullPtrAsGtPinInputWhenTranslatorReturnsNullptrThenNull
581581
TEST(TranslateTest, whenTranslatorReturnsInvalidOutputThenNullptrIsReturned) {
582582
TranslationCtxMock mockTranslationCtx;
583583
auto mockCifBuffer = CIF::RAII::UPtr_t<MockCIFBuffer>(new MockCIFBuffer());
584-
for (uint32_t i = 1; i <= (1 << 3) - 1; ++i) {
584+
for (uint32_t i = 1; i <= maxNBitValue(3); ++i) {
585585
mockTranslationCtx.returnNullptrDebugData = (i & 1) != 0;
586586
mockTranslationCtx.returnNullptrLog = (i & (1 << 1)) != 0;
587587
mockTranslationCtx.returnNullptrOutput = (i & (1 << 2)) != 0;
@@ -593,7 +593,7 @@ TEST(TranslateTest, whenTranslatorReturnsInvalidOutputThenNullptrIsReturned) {
593593
TEST(TranslateTest, givenNullPtrAsGtPinInputWhenTranslatorReturnsInvalidOutputThenNullptrIsReturned) {
594594
TranslationCtxMock mockTranslationCtx;
595595
auto mockCifBuffer = CIF::RAII::UPtr_t<MockCIFBuffer>(new MockCIFBuffer());
596-
for (uint32_t i = 1; i <= (1 << 3) - 1; ++i) {
596+
for (uint32_t i = 1; i <= maxNBitValue(3); ++i) {
597597
mockTranslationCtx.returnNullptrDebugData = (i & 1) != 0;
598598
mockTranslationCtx.returnNullptrLog = (i & (1 << 1)) != 0;
599599
mockTranslationCtx.returnNullptrOutput = (i & (1 << 2)) != 0;
@@ -605,7 +605,7 @@ TEST(TranslateTest, givenNullPtrAsGtPinInputWhenTranslatorReturnsInvalidOutputTh
605605
TEST(TranslateTest, givenSpecConstantsBuffersAndNullPtrAsGtPinInputWhenTranslatorReturnsInvalidOutputThenNullptrIsReturned) {
606606
TranslationCtxMock mockTranslationCtx;
607607
auto mockCifBuffer = CIF::RAII::UPtr_t<MockCIFBuffer>(new MockCIFBuffer());
608-
for (uint32_t i = 1; i <= (1 << 3) - 1; ++i) {
608+
for (uint32_t i = 1; i <= maxNBitValue(3); ++i) {
609609
mockTranslationCtx.returnNullptrDebugData = (i & 1) != 0;
610610
mockTranslationCtx.returnNullptrLog = (i & (1 << 1)) != 0;
611611
mockTranslationCtx.returnNullptrOutput = (i & (1 << 2)) != 0;
@@ -617,7 +617,7 @@ TEST(TranslateTest, givenSpecConstantsBuffersAndNullPtrAsGtPinInputWhenTranslato
617617
TEST(TranslateTest, whenAnyArgIsNullThenNullptrIsReturnedAndTranslatorIsNotInvoked) {
618618
TranslationCtxMock mockTranslationCtx;
619619
auto mockCifBuffer = CIF::RAII::UPtr_t<MockCIFBuffer>(new MockCIFBuffer());
620-
for (uint32_t i = 0; i < (1 << 3) - 1; ++i) {
620+
for (uint32_t i = 0; i < maxNBitValue(3); ++i) {
621621
auto src = (i & 1) ? mockCifBuffer.get() : nullptr;
622622
auto opts = (i & (1 << 1)) ? mockCifBuffer.get() : nullptr;
623623
auto intOpts = (i & (1 << 2)) ? mockCifBuffer.get() : nullptr;

core/unit_tests/utilities/numeric_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ TEST(FixedU4D8, whenCreatingFromTooBigFloatThenValueIsClamped) {
3838
FixedU4D8 u4d8Max{maxU4D8};
3939
FixedU4D8 u4d8MaxPlus1{maxU4D8 + 1};
4040
EXPECT_EQ(u4d8Max.getRawAccess(), u4d8MaxPlus1.getRawAccess());
41-
EXPECT_EQ((1U << (4 + 8)) - 1, u4d8Max.getRawAccess()); // all 12 bits should be set
41+
EXPECT_EQ(maxNBitValue(4 + 8), u4d8Max.getRawAccess()); // all 12 bits should be set
4242
EXPECT_EQ(maxU4D8, u4d8Max.asFloat());
4343
}
4444

core/utilities/numeric.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#pragma once
99

10+
#include "core/memory_manager/memory_constants.h"
11+
1012
#include <cstdint>
1113

1214
namespace NEO {
@@ -64,7 +66,7 @@ struct UnsignedFixedPointValue {
6466
template <typename FloatingType>
6567
static constexpr FloatingType getMaxRepresentableFloatingPointValue() {
6668
return static_cast<FloatingType>(
67-
static_cast<FloatingType>((1U << IntegerBits) - 1) + (static_cast<FloatingType>((1U << FractionalBits) - 1) / (1U << FractionalBits)));
69+
static_cast<FloatingType>(maxNBitValue(IntegerBits)) + (static_cast<FloatingType>(maxNBitValue(FractionalBits)) / (1U << FractionalBits)));
6870
}
6971

7072
template <typename FloatingType>

runtime/command_queue/gpgpu_walker_bdw_plus.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ inline size_t GpgpuWalkerHelper<GfxFamily>::setGpgpuWalkerThreadData(
3535

3636
// compute executionMask - to tell which SIMD lines are active within thread
3737
auto remainderSimdLanes = localWorkSize & (simd - 1);
38-
uint64_t executionMask = (1ull << remainderSimdLanes) - 1;
38+
uint64_t executionMask = maxNBitValue(remainderSimdLanes);
3939
if (!executionMask)
4040
executionMask = ~executionMask;
4141

runtime/dll/linux/allocator_helper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
namespace NEO {
1414

1515
size_t getSizeToReserve() {
16-
return (maxNBitValue<47> + 1) / 4;
16+
return (maxNBitValue(47) + 1) / 4;
1717
}
1818

1919
} // namespace NEO

runtime/event/event.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ void Event::updateCompletionStamp(uint32_t taskCount, uint32_t tasklevel, FlushS
232232

233233
cl_ulong Event::getDelta(cl_ulong startTime,
234234
cl_ulong endTime) {
235-
cl_ulong Max = (1ULL << OCLRT_NUM_TIMESTAMP_BITS) - 1;
235+
cl_ulong Max = maxNBitValue(OCLRT_NUM_TIMESTAMP_BITS);
236236
cl_ulong Delta = 0;
237237

238238
startTime &= Max;

runtime/execution_environment/execution_environment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ BuiltIns *ExecutionEnvironment::getBuiltIns() {
9898
}
9999

100100
bool ExecutionEnvironment::isFullRangeSvm() const {
101-
return hwInfo->capabilityTable.gpuAddressSpace >= maxNBitValue<47>;
101+
return hwInfo->capabilityTable.gpuAddressSpace >= maxNBitValue(47);
102102
}
103103

104104
void ExecutionEnvironment::prepareRootDeviceEnvironments(uint32_t numRootDevices) {

0 commit comments

Comments
 (0)