Skip to content

Commit c1abf6a

Browse files
author
Derek Hower
committed
C++ cleanup
1 parent 0c3aa83 commit c1abf6a

File tree

3 files changed

+22
-61
lines changed

3 files changed

+22
-61
lines changed

backends/cpp_hart_gen/cpp/include/udb/bitfield.hpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#pragma once
22

3-
// #include <boost/multiprecision/cpp_int.hpp>
4-
53
#include <bit>
64
#include <cmath>
75
#include <concepts>
@@ -14,48 +12,8 @@
1412
#include <udb/bits.hpp>
1513
#include <udb/defines.hpp>
1614

17-
// extern "C" {
18-
// #include "softfloat.h"
19-
// }
20-
2115
namespace udb {
2216

23-
// empty struct used as the parent of any user-defined enum
24-
// we use this to identify enum types at compile time
25-
struct Enum {};
26-
27-
template <unsigned N> struct FixedString {
28-
char buf[N + 1]{};
29-
constexpr FixedString(char const *s) {
30-
for (unsigned i = 0; i != N; ++i)
31-
buf[i] = s[i];
32-
}
33-
constexpr operator char const *() const { return buf; }
34-
};
35-
template <unsigned N> FixedString(char const (&)[N]) -> FixedString<N - 1>;
36-
37-
template <unsigned N> static consteval bool is_power_of_2() {
38-
if constexpr (N == 0) {
39-
return true;
40-
} else {
41-
unsigned M = N;
42-
while ((M & 1) == 0) {
43-
M = M >> 1;
44-
}
45-
return M == 1;
46-
}
47-
}
48-
static_assert(is_power_of_2<128>());
49-
static_assert(is_power_of_2<64>());
50-
static_assert(is_power_of_2<32>());
51-
static_assert(is_power_of_2<16>());
52-
static_assert(is_power_of_2<32>());
53-
static_assert(is_power_of_2<16>());
54-
static_assert(is_power_of_2<8>());
55-
static_assert(is_power_of_2<4>());
56-
static_assert(is_power_of_2<2>());
57-
static_assert(is_power_of_2<1>());
58-
5917
using uint128_t = unsigned __int128;
6018
using int128_t = __int128;
6119

backends/cpp_hart_gen/cpp/include/udb/hart.hpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,6 @@
2323

2424
namespace udb {
2525

26-
// probably unwise to change these
27-
static constexpr uint64_t LOG_MEM_REGION_SZ = 12; // 4k regions
28-
static constexpr uint64_t LOG_EXECMAP_CHUNK_SZ = 12;
29-
30-
// derived values - do not modify
31-
static constexpr uint64_t MEM_REGION_SZ = 1UL << LOG_MEM_REGION_SZ;
32-
static constexpr uint64_t MEM_REGION_MASK = ~(MEM_REGION_SZ - 1);
33-
34-
static const constexpr uint64_t NS_BIT_OFFSET = 52; // non-secure bit
35-
static const constexpr uint64_t NS_MASK = 1UL << NS_BIT_OFFSET;
36-
37-
// hash used to initialize each 64-bit word in memory
38-
// assumes addr is the aligned physical address plus NS bit
39-
inline uint64_t mem_init_hash(uint64_t addr) {
40-
uint8_t ns = addr >> NS_BIT_OFFSET; // NOLINT
41-
return ((addr ^ (addr >> 4)) & 0x0f0f0f0f0f0f0f0eUL) | // NOLINT
42-
(0x1010101010101010UL << ns); // NOLINT
43-
}
44-
4526
class AbstractTracer {
4627
public:
4728
AbstractTracer() = default;

backends/cpp_hart_gen/cpp/include/udb/util.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,4 +255,26 @@ RuntimeBits concat(BitsTypes... bits) {
255255
static_assert(std::is_same_v<
256256
decltype(concat(Bits<4>{1}, Bits<4>(2), Bits<4>(3))), Bits<12>>);
257257
static_assert(concat(Bits<4>{1}, Bits<4>(2), Bits<4>(3)) == Bits<12>(0x123));
258+
259+
template <unsigned N> static consteval bool is_power_of_2() {
260+
if constexpr (N == 0) {
261+
return true;
262+
} else {
263+
unsigned M = N;
264+
while ((M & 1) == 0) {
265+
M = M >> 1;
266+
}
267+
return M == 1;
268+
}
269+
}
270+
static_assert(is_power_of_2<128>());
271+
static_assert(is_power_of_2<64>());
272+
static_assert(is_power_of_2<32>());
273+
static_assert(is_power_of_2<16>());
274+
static_assert(is_power_of_2<32>());
275+
static_assert(is_power_of_2<16>());
276+
static_assert(is_power_of_2<8>());
277+
static_assert(is_power_of_2<4>());
278+
static_assert(is_power_of_2<2>());
279+
static_assert(is_power_of_2<1>());
258280
} // namespace udb

0 commit comments

Comments
 (0)