esiaccel 0.1.5.dev254__cp311-cp311-win_amd64.whl → 0.2.3.dev47__cp311-cp311-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- esiaccel/CosimBackend.dll +0 -0
- esiaccel/CosimBackend.lib +0 -0
- esiaccel/CosimRpc.dll +0 -0
- esiaccel/CosimRpc.lib +0 -0
- esiaccel/ESICppRuntime.dll +0 -0
- esiaccel/ESICppRuntime.lib +0 -0
- esiaccel/EsiCosimDpiServer.dll +0 -0
- esiaccel/EsiCosimDpiServer.lib +0 -0
- esiaccel/MtiPli.dll +0 -0
- esiaccel/MtiPli.lib +0 -0
- esiaccel/__init__.py +12 -3
- esiaccel/abseil_dll.dll +0 -0
- esiaccel/accelerator.py +37 -5
- esiaccel/cares.dll +0 -0
- esiaccel/cmake/esiaccelConfig.cmake +34 -0
- esiaccel/codegen.py +3 -3
- esiaccel/esiCppAccel.cp312-win_amd64.pyd +0 -0
- esiaccel/esiquery.exe +0 -0
- esiaccel/include/esi/Accelerator.h +3 -16
- esiaccel/include/esi/CLI.h +5 -5
- esiaccel/include/esi/Common.h +11 -1
- esiaccel/include/esi/Context.h +17 -9
- esiaccel/include/esi/Design.h +9 -4
- esiaccel/include/esi/Manifest.h +0 -2
- esiaccel/include/esi/Ports.h +230 -23
- esiaccel/include/esi/Services.h +50 -18
- esiaccel/include/esi/Types.h +108 -31
- esiaccel/include/esi/Values.h +313 -0
- esiaccel/include/esi/backends/Cosim.h +5 -12
- esiaccel/include/esi/backends/RpcClient.h +97 -0
- esiaccel/include/esi/backends/RpcServer.h +21 -3
- esiaccel/libcrypto-3-x64.dll +0 -0
- esiaccel/libprotobuf.dll +0 -0
- esiaccel/libssl-3-x64.dll +0 -0
- esiaccel/re2.dll +0 -0
- esiaccel/types.py +6 -4
- esiaccel/zlib1.dll +0 -0
- {esiaccel-0.1.5.dev254.dist-info → esiaccel-0.2.3.dev47.dist-info}/METADATA +1 -1
- esiaccel-0.2.3.dev47.dist-info/RECORD +57 -0
- esiaccel/esiCppAccel.cp311-win_amd64.pyd +0 -0
- esiaccel-0.1.5.dev254.dist-info/RECORD +0 -53
- {esiaccel-0.1.5.dev254.dist-info → esiaccel-0.2.3.dev47.dist-info}/WHEEL +0 -0
- {esiaccel-0.1.5.dev254.dist-info → esiaccel-0.2.3.dev47.dist-info}/entry_points.txt +0 -0
- {esiaccel-0.1.5.dev254.dist-info → esiaccel-0.2.3.dev47.dist-info}/licenses/LICENSE +0 -0
- {esiaccel-0.1.5.dev254.dist-info → esiaccel-0.2.3.dev47.dist-info}/top_level.txt +0 -0
esiaccel/include/esi/Types.h
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
#include <vector>
|
|
27
27
|
|
|
28
28
|
#include "esi/Common.h"
|
|
29
|
+
#include "esi/Values.h" // For BitVector / Int / UInt
|
|
29
30
|
|
|
30
31
|
namespace esi {
|
|
31
32
|
|
|
@@ -39,20 +40,29 @@ public:
|
|
|
39
40
|
ID getID() const { return id; }
|
|
40
41
|
virtual std::ptrdiff_t getBitWidth() const { return -1; }
|
|
41
42
|
|
|
42
|
-
/// Serialize an object to
|
|
43
|
-
///
|
|
44
|
-
/// serialized
|
|
45
|
-
|
|
43
|
+
/// Serialize an object to a MutableBitVector (LSB-first stream). The object
|
|
44
|
+
/// should be passed via std::any. Implementations append fields in the order
|
|
45
|
+
/// they are iterated (the first serialized field occupies the
|
|
46
|
+
/// least-significant bits of the result).
|
|
47
|
+
virtual MutableBitVector serialize(const std::any &obj) const {
|
|
46
48
|
throw std::runtime_error("Serialization not implemented for type " + id);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
/// Deserialize from a
|
|
50
|
-
///
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
/// Deserialize from a BitVector stream (LSB-first). Implementations consume
|
|
52
|
+
/// bits from 'data' in-place (via logical right shifts) and return the
|
|
53
|
+
/// reconstructed value. Remaining bits stay in 'data'.
|
|
54
|
+
virtual std::any deserialize(BitVector &data) const {
|
|
53
55
|
throw std::runtime_error("Deserialization not implemented for type " + id);
|
|
54
56
|
}
|
|
55
57
|
|
|
58
|
+
// Deserialize from a MessageData buffer. Maps the MessageData onto a
|
|
59
|
+
// MutableBitVector, and proceeds with regular MutableBitVector
|
|
60
|
+
// deserialization.
|
|
61
|
+
std::any deserialize(const MessageData &data) const {
|
|
62
|
+
auto bv = MutableBitVector(std::vector<uint8_t>(data.getData()));
|
|
63
|
+
return deserialize(bv);
|
|
64
|
+
}
|
|
65
|
+
|
|
56
66
|
/// Ensure that a std::any object is valid for this type. Throws
|
|
57
67
|
/// std::runtime_error if the object is not valid.
|
|
58
68
|
virtual void ensureValid(const std::any &obj) const {
|
|
@@ -70,6 +80,12 @@ public:
|
|
|
70
80
|
}
|
|
71
81
|
}
|
|
72
82
|
|
|
83
|
+
// Dump a textual representation of this type to the provided stream.
|
|
84
|
+
void dump(std::ostream &os, bool oneLine = false) const;
|
|
85
|
+
|
|
86
|
+
// Return a textual representation of this type.
|
|
87
|
+
std::string toString(bool oneLine = false) const;
|
|
88
|
+
|
|
73
89
|
protected:
|
|
74
90
|
ID id;
|
|
75
91
|
};
|
|
@@ -101,14 +117,14 @@ protected:
|
|
|
101
117
|
/// carry one values of one type.
|
|
102
118
|
class ChannelType : public Type {
|
|
103
119
|
public:
|
|
120
|
+
using Type::deserialize;
|
|
104
121
|
ChannelType(const ID &id, const Type *inner) : Type(id), inner(inner) {}
|
|
105
122
|
const Type *getInner() const { return inner; }
|
|
106
123
|
std::ptrdiff_t getBitWidth() const override { return inner->getBitWidth(); };
|
|
107
124
|
|
|
108
125
|
void ensureValid(const std::any &obj) const override;
|
|
109
|
-
|
|
110
|
-
std::
|
|
111
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
126
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
127
|
+
std::any deserialize(BitVector &data) const override;
|
|
112
128
|
|
|
113
129
|
private:
|
|
114
130
|
const Type *inner;
|
|
@@ -117,14 +133,14 @@ private:
|
|
|
117
133
|
/// The "void" type is a special type which can be used to represent no type.
|
|
118
134
|
class VoidType : public Type {
|
|
119
135
|
public:
|
|
136
|
+
using Type::deserialize;
|
|
120
137
|
VoidType(const ID &id) : Type(id) {}
|
|
121
138
|
// 'void' is 1 bit by convention.
|
|
122
139
|
std::ptrdiff_t getBitWidth() const override { return 1; };
|
|
123
140
|
|
|
124
141
|
void ensureValid(const std::any &obj) const override;
|
|
125
|
-
|
|
126
|
-
std::
|
|
127
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
142
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
143
|
+
std::any deserialize(BitVector &data) const override;
|
|
128
144
|
};
|
|
129
145
|
|
|
130
146
|
/// The "any" type is a special type which can be used to represent any type, as
|
|
@@ -154,11 +170,11 @@ private:
|
|
|
154
170
|
class BitsType : public BitVectorType {
|
|
155
171
|
public:
|
|
156
172
|
using BitVectorType::BitVectorType;
|
|
173
|
+
using Type::deserialize;
|
|
157
174
|
|
|
158
175
|
void ensureValid(const std::any &obj) const override;
|
|
159
|
-
|
|
160
|
-
std::
|
|
161
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
176
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
177
|
+
std::any deserialize(BitVector &data) const override;
|
|
162
178
|
};
|
|
163
179
|
|
|
164
180
|
/// Integers are bit vectors which may be signed or unsigned and are interpreted
|
|
@@ -172,28 +188,29 @@ public:
|
|
|
172
188
|
class SIntType : public IntegerType {
|
|
173
189
|
public:
|
|
174
190
|
using IntegerType::IntegerType;
|
|
191
|
+
using Type::deserialize;
|
|
175
192
|
|
|
176
193
|
void ensureValid(const std::any &obj) const override;
|
|
177
|
-
|
|
178
|
-
std::
|
|
179
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
194
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
195
|
+
std::any deserialize(BitVector &data) const override;
|
|
180
196
|
};
|
|
181
197
|
|
|
182
198
|
/// Unsigned integer.
|
|
183
199
|
class UIntType : public IntegerType {
|
|
184
200
|
public:
|
|
185
201
|
using IntegerType::IntegerType;
|
|
202
|
+
using Type::deserialize;
|
|
186
203
|
|
|
187
204
|
void ensureValid(const std::any &obj) const override;
|
|
188
|
-
|
|
189
|
-
std::
|
|
190
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
205
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
206
|
+
std::any deserialize(BitVector &data) const override;
|
|
191
207
|
};
|
|
192
208
|
|
|
193
209
|
/// Structs are an ordered collection of fields, each with a name and a type.
|
|
194
210
|
class StructType : public Type {
|
|
195
211
|
public:
|
|
196
212
|
using FieldVector = std::vector<std::pair<std::string, const Type *>>;
|
|
213
|
+
using Type::deserialize;
|
|
197
214
|
|
|
198
215
|
StructType(const ID &id, const FieldVector &fields, bool reverse = true)
|
|
199
216
|
: Type(id), fields(fields), reverse(reverse) {}
|
|
@@ -211,9 +228,8 @@ public:
|
|
|
211
228
|
}
|
|
212
229
|
|
|
213
230
|
void ensureValid(const std::any &obj) const override;
|
|
214
|
-
|
|
215
|
-
std::
|
|
216
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
231
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
232
|
+
std::any deserialize(BitVector &data) const override;
|
|
217
233
|
|
|
218
234
|
// Returns whether this struct type should be reversed when
|
|
219
235
|
// serializing/deserializing.
|
|
@@ -230,11 +246,14 @@ private:
|
|
|
230
246
|
/// Arrays have a compile time specified (static) size and an element type.
|
|
231
247
|
class ArrayType : public Type {
|
|
232
248
|
public:
|
|
233
|
-
ArrayType(const ID &id, const Type *elementType, uint64_t size
|
|
234
|
-
|
|
249
|
+
ArrayType(const ID &id, const Type *elementType, uint64_t size,
|
|
250
|
+
bool reverse = true)
|
|
251
|
+
: Type(id), elementType(elementType), size(size), reverse(reverse) {}
|
|
252
|
+
using Type::deserialize;
|
|
235
253
|
|
|
236
254
|
const Type *getElementType() const { return elementType; }
|
|
237
255
|
uint64_t getSize() const { return size; }
|
|
256
|
+
bool isReverse() const { return reverse; }
|
|
238
257
|
std::ptrdiff_t getBitWidth() const override {
|
|
239
258
|
std::ptrdiff_t elementSize = elementType->getBitWidth();
|
|
240
259
|
if (elementSize < 0)
|
|
@@ -243,13 +262,71 @@ public:
|
|
|
243
262
|
}
|
|
244
263
|
|
|
245
264
|
void ensureValid(const std::any &obj) const override;
|
|
246
|
-
|
|
247
|
-
std::
|
|
248
|
-
deserialize(std::span<const uint8_t> data) const override;
|
|
265
|
+
MutableBitVector serialize(const std::any &obj) const override;
|
|
266
|
+
std::any deserialize(BitVector &data) const override;
|
|
249
267
|
|
|
250
268
|
private:
|
|
251
269
|
const Type *elementType;
|
|
252
270
|
uint64_t size;
|
|
271
|
+
// 'reverse' controls whether array elements are reversed during
|
|
272
|
+
// serialization/deserialization (to match SystemVerilog/Python ordering
|
|
273
|
+
// expectations).
|
|
274
|
+
bool reverse;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/// Windows represent a fixed-size sliding window over a stream of data.
|
|
278
|
+
/// They define an "into" type (the data structure being windowed) and a
|
|
279
|
+
/// "loweredType" (the hardware representation including control signals).
|
|
280
|
+
class WindowType : public Type {
|
|
281
|
+
public:
|
|
282
|
+
/// Field information describing a field within a frame.
|
|
283
|
+
struct Field {
|
|
284
|
+
std::string name;
|
|
285
|
+
uint64_t numItems = 0; // 0 means not specified (use all items)
|
|
286
|
+
uint64_t bulkCountWidth = 0; // 0 means parallel encoding, >0 means serial
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/// Frame information describing which fields are included in a particular
|
|
290
|
+
/// frame.
|
|
291
|
+
struct Frame {
|
|
292
|
+
std::string name;
|
|
293
|
+
std::vector<Field> fields;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
WindowType(const ID &id, const std::string &name, const Type *intoType,
|
|
297
|
+
const Type *loweredType, const std::vector<Frame> &frames)
|
|
298
|
+
: Type(id), name(name), intoType(intoType), loweredType(loweredType),
|
|
299
|
+
frames(frames) {}
|
|
300
|
+
|
|
301
|
+
const std::string &getName() const { return name; }
|
|
302
|
+
const Type *getIntoType() const { return intoType; }
|
|
303
|
+
const Type *getLoweredType() const { return loweredType; }
|
|
304
|
+
const std::vector<Frame> &getFrames() const { return frames; }
|
|
305
|
+
|
|
306
|
+
std::ptrdiff_t getBitWidth() const override {
|
|
307
|
+
return loweredType->getBitWidth();
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
private:
|
|
311
|
+
std::string name;
|
|
312
|
+
const Type *intoType;
|
|
313
|
+
const Type *loweredType;
|
|
314
|
+
std::vector<Frame> frames;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/// Lists represent variable-length sequences of elements of a single type.
|
|
318
|
+
/// Unlike arrays which have a fixed size, lists can have any length.
|
|
319
|
+
class ListType : public Type {
|
|
320
|
+
public:
|
|
321
|
+
ListType(const ID &id, const Type *elementType)
|
|
322
|
+
: Type(id), elementType(elementType) {}
|
|
323
|
+
|
|
324
|
+
const Type *getElementType() const { return elementType; }
|
|
325
|
+
|
|
326
|
+
std::ptrdiff_t getBitWidth() const override { return -1; }
|
|
327
|
+
|
|
328
|
+
private:
|
|
329
|
+
const Type *elementType;
|
|
253
330
|
};
|
|
254
331
|
|
|
255
332
|
} // namespace esi
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
//===- values.h - ESI value system -------------------------------* C++ -*-===//
|
|
2
|
+
//
|
|
3
|
+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
4
|
+
// See https://llvm.org/LICENSE.txt for license information.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
6
|
+
//
|
|
7
|
+
//===----------------------------------------------------------------------===//
|
|
8
|
+
//
|
|
9
|
+
// ESI arbitrary width bitvector and integer types.
|
|
10
|
+
// These types are not meant to be highly optimized. Rather, its a simple
|
|
11
|
+
// implementation to support arbitrary bit widths for ESI runtime values.
|
|
12
|
+
//
|
|
13
|
+
//===----------------------------------------------------------------------===//
|
|
14
|
+
// DO NOT EDIT!
|
|
15
|
+
// This file is distributed as part of an ESI package. The source for this file
|
|
16
|
+
// should always be modified within CIRCT.
|
|
17
|
+
//
|
|
18
|
+
//===----------------------------------------------------------------------===//
|
|
19
|
+
|
|
20
|
+
// NOLINTNEXTLINE(llvm-header-guard)
|
|
21
|
+
#ifndef ESI_VALUES_H
|
|
22
|
+
#define ESI_VALUES_H
|
|
23
|
+
|
|
24
|
+
#include <cstdint>
|
|
25
|
+
#include <format>
|
|
26
|
+
#include <memory> // (may be removable later)
|
|
27
|
+
#include <optional>
|
|
28
|
+
#include <ostream>
|
|
29
|
+
#include <span>
|
|
30
|
+
#include <stdexcept>
|
|
31
|
+
#include <string>
|
|
32
|
+
#include <vector>
|
|
33
|
+
|
|
34
|
+
namespace esi {
|
|
35
|
+
|
|
36
|
+
class MutableBitVector;
|
|
37
|
+
|
|
38
|
+
/// A lightweight, non-owning bit vector view backed by a byte array span.
|
|
39
|
+
/// BitVector is immutable wrt. modifying the underlying bits, and provides
|
|
40
|
+
/// read-only access to bits. It supports bit-level access and returns new views
|
|
41
|
+
/// for operations.
|
|
42
|
+
class BitVector {
|
|
43
|
+
public:
|
|
44
|
+
using byte = uint8_t;
|
|
45
|
+
|
|
46
|
+
/// Construct from an existing span. Width defaults to the number of bits in
|
|
47
|
+
/// the span (size * 8). The BitVector does not take ownership.
|
|
48
|
+
BitVector(std::span<const byte> bytes,
|
|
49
|
+
std::optional<size_t> width = std::nullopt, uint8_t bitIndex = 0);
|
|
50
|
+
BitVector() = default;
|
|
51
|
+
BitVector(const BitVector &other);
|
|
52
|
+
BitVector &operator=(const BitVector &other);
|
|
53
|
+
|
|
54
|
+
size_t width() const { return bitWidth; }
|
|
55
|
+
size_t size() const { return width(); }
|
|
56
|
+
|
|
57
|
+
/// Return the i-th bit (0 = LSB) as boolean.
|
|
58
|
+
bool getBit(size_t i) const;
|
|
59
|
+
|
|
60
|
+
/// Return a handle to the underlying span. Throws if the current bit index
|
|
61
|
+
/// is not 0 (since a non-zero bit offset breaks raw byte alignment).
|
|
62
|
+
std::span<const byte> getSpan() const {
|
|
63
|
+
if (bitIndex != 0)
|
|
64
|
+
throw std::runtime_error("Cannot get data span with non-zero bit index");
|
|
65
|
+
return data;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/// Logical right shift that drops the least-significant n bits by advancing
|
|
69
|
+
/// the byte/bit index and reducing width. Returns a new immutable
|
|
70
|
+
/// view. Does not modify the underlying storage contents.
|
|
71
|
+
BitVector operator>>(size_t n) const;
|
|
72
|
+
BitVector &operator>>=(size_t n);
|
|
73
|
+
|
|
74
|
+
/// Create a new immutable view of a contiguous bit slice [offset,
|
|
75
|
+
/// offset+sliceWidth). The returned BitVector is a view (not an owning copy)
|
|
76
|
+
/// into the same underlying span. Throws if the requested slice exceeds the
|
|
77
|
+
/// current width.
|
|
78
|
+
BitVector slice(size_t offset, size_t sliceWidth) const;
|
|
79
|
+
|
|
80
|
+
/// Return a view of the N least-significant bits.
|
|
81
|
+
BitVector lsb(size_t n) const { return slice(0, n); }
|
|
82
|
+
|
|
83
|
+
/// Return a view of the N most-significant bits.
|
|
84
|
+
BitVector msb(size_t n) const {
|
|
85
|
+
if (n > bitWidth)
|
|
86
|
+
throw std::invalid_argument("msb width exceeds bit width");
|
|
87
|
+
return slice(bitWidth - n, n);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
std::string toString(unsigned base = 16) const;
|
|
91
|
+
|
|
92
|
+
bool operator==(const BitVector &rhs) const;
|
|
93
|
+
bool operator!=(const BitVector &rhs) const { return !(*this == rhs); }
|
|
94
|
+
|
|
95
|
+
/// Bitwise AND: creates a new MutableBitVector with the result.
|
|
96
|
+
friend MutableBitVector operator&(const BitVector &a, const BitVector &b);
|
|
97
|
+
|
|
98
|
+
/// Bitwise OR: creates a new MutableBitVector with the result.
|
|
99
|
+
friend MutableBitVector operator|(const BitVector &a, const BitVector &b);
|
|
100
|
+
|
|
101
|
+
/// Bitwise XOR: creates a new MutableBitVector with the result.
|
|
102
|
+
friend MutableBitVector operator^(const BitVector &a, const BitVector &b);
|
|
103
|
+
|
|
104
|
+
/// Forward iterator for iterating over bits from LSB (index 0) to MSB.
|
|
105
|
+
class bit_iterator {
|
|
106
|
+
public:
|
|
107
|
+
using difference_type = std::ptrdiff_t;
|
|
108
|
+
using value_type = bool;
|
|
109
|
+
using pointer = const bool *;
|
|
110
|
+
using reference = bool;
|
|
111
|
+
using iterator_category = std::forward_iterator_tag;
|
|
112
|
+
|
|
113
|
+
/// Default constructor.
|
|
114
|
+
bit_iterator() = default;
|
|
115
|
+
|
|
116
|
+
/// Construct an iterator at the given bit position.
|
|
117
|
+
bit_iterator(const BitVector *bv, size_t pos = 0)
|
|
118
|
+
: bitVector(bv), position(pos) {}
|
|
119
|
+
|
|
120
|
+
/// Dereference: returns the bit value at the current position.
|
|
121
|
+
bool operator*() const {
|
|
122
|
+
if (bitVector == nullptr || position >= bitVector->bitWidth)
|
|
123
|
+
throw std::out_of_range("bit_iterator dereference out of range");
|
|
124
|
+
return bitVector->getBit(position);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// Pre-increment: move to next bit.
|
|
128
|
+
bit_iterator &operator++() {
|
|
129
|
+
++position;
|
|
130
|
+
return *this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// Post-increment: move to next bit.
|
|
134
|
+
bit_iterator operator++(int) {
|
|
135
|
+
bit_iterator tmp = *this;
|
|
136
|
+
++position;
|
|
137
|
+
return tmp;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Equality comparison.
|
|
141
|
+
bool operator==(const bit_iterator &other) const {
|
|
142
|
+
return bitVector == other.bitVector && position == other.position;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/// Inequality comparison.
|
|
146
|
+
bool operator!=(const bit_iterator &other) const {
|
|
147
|
+
return !(*this == other);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/// Less-than comparison (for ranges support).
|
|
151
|
+
bool operator<(const bit_iterator &other) const {
|
|
152
|
+
return bitVector == other.bitVector && position < other.position;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/// Sentinel-compatible equality (for ranges support).
|
|
156
|
+
bool operator==(std::default_sentinel_t) const {
|
|
157
|
+
return bitVector == nullptr || position >= bitVector->bitWidth;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/// Sentinel-compatible inequality.
|
|
161
|
+
bool operator!=(std::default_sentinel_t sent) const {
|
|
162
|
+
return !(*this == sent);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private:
|
|
166
|
+
const BitVector *bitVector = nullptr;
|
|
167
|
+
size_t position = 0;
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
/// Return an iterator to the first bit (LSB).
|
|
171
|
+
bit_iterator begin() const { return bit_iterator(this, 0); }
|
|
172
|
+
|
|
173
|
+
/// Return an iterator past the last bit.
|
|
174
|
+
bit_iterator end() const { return bit_iterator(this, bitWidth); }
|
|
175
|
+
|
|
176
|
+
protected:
|
|
177
|
+
// Underlying storage view. const, to allow for non-owning immutable views.
|
|
178
|
+
std::span<const byte> data{};
|
|
179
|
+
size_t bitWidth = 0; // Number of valid bits.
|
|
180
|
+
uint8_t bitIndex = 0; // Starting bit offset in first byte.
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/// A mutable bit vector that owns its underlying storage.
|
|
184
|
+
/// It supports in-place modifications and mutable operations.
|
|
185
|
+
class MutableBitVector : public BitVector {
|
|
186
|
+
public:
|
|
187
|
+
/// Owning, zero-initialized constructor of a given width.
|
|
188
|
+
explicit MutableBitVector(size_t width);
|
|
189
|
+
|
|
190
|
+
/// Owning constructor from an rvalue vector (must move in).
|
|
191
|
+
MutableBitVector(std::vector<byte> &&bytes,
|
|
192
|
+
std::optional<size_t> width = std::nullopt);
|
|
193
|
+
|
|
194
|
+
MutableBitVector() = default;
|
|
195
|
+
|
|
196
|
+
// Copy constructor: duplicate storage.
|
|
197
|
+
MutableBitVector(const MutableBitVector &other);
|
|
198
|
+
|
|
199
|
+
// Copy constructor from immutable BitVector: creates owning copy.
|
|
200
|
+
MutableBitVector(const BitVector &other);
|
|
201
|
+
|
|
202
|
+
// Move constructor: transfer ownership.
|
|
203
|
+
MutableBitVector(MutableBitVector &&other) noexcept;
|
|
204
|
+
|
|
205
|
+
// Move constructor from immutable BitVector: creates owning copy.
|
|
206
|
+
MutableBitVector(BitVector &&other);
|
|
207
|
+
|
|
208
|
+
MutableBitVector &operator=(const MutableBitVector &other);
|
|
209
|
+
|
|
210
|
+
MutableBitVector &operator=(MutableBitVector &&other) noexcept;
|
|
211
|
+
|
|
212
|
+
/// Set the i-th bit.
|
|
213
|
+
void setBit(size_t i, bool v);
|
|
214
|
+
|
|
215
|
+
/// Return a handle to the underlying span (always aligned since bitIndex=0).
|
|
216
|
+
std::span<const byte> getSpan() const { return data; }
|
|
217
|
+
|
|
218
|
+
/// Return and transfer ownership of the underlying storage.
|
|
219
|
+
std::vector<uint8_t> takeStorage() { return std::move(owner); }
|
|
220
|
+
|
|
221
|
+
/// In-place logical right shift that drops the least-significant n bits.
|
|
222
|
+
/// Reduces width and updates internal state. Does not modify underlying
|
|
223
|
+
/// storage.
|
|
224
|
+
MutableBitVector &operator>>=(size_t n);
|
|
225
|
+
|
|
226
|
+
/// In-place logical left shift shifts in n zero bits at LSB, shifting
|
|
227
|
+
/// existing bits upward.
|
|
228
|
+
MutableBitVector &operator<<=(size_t n);
|
|
229
|
+
|
|
230
|
+
/// In-place concatenate: appends bits from other to this.
|
|
231
|
+
MutableBitVector &operator<<=(const MutableBitVector &other);
|
|
232
|
+
|
|
233
|
+
MutableBitVector &operator|=(const MutableBitVector &other);
|
|
234
|
+
MutableBitVector &operator&=(const MutableBitVector &other);
|
|
235
|
+
MutableBitVector &operator^=(const MutableBitVector &other);
|
|
236
|
+
MutableBitVector operator~() const;
|
|
237
|
+
MutableBitVector operator|(const MutableBitVector &other) const;
|
|
238
|
+
MutableBitVector operator&(const MutableBitVector &other) const;
|
|
239
|
+
MutableBitVector operator^(const MutableBitVector &other) const;
|
|
240
|
+
|
|
241
|
+
private:
|
|
242
|
+
// Storage owned by this MutableBitVector.
|
|
243
|
+
std::vector<byte> owner;
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
std::ostream &operator<<(std::ostream &os, const BitVector &bv);
|
|
247
|
+
|
|
248
|
+
// Arbitrary width signed integer type built on MutableBitVector.
|
|
249
|
+
class Int : public MutableBitVector {
|
|
250
|
+
public:
|
|
251
|
+
using MutableBitVector::MutableBitVector;
|
|
252
|
+
Int() = default;
|
|
253
|
+
Int(int64_t v, unsigned width = 64);
|
|
254
|
+
operator int64_t() const { return toI64(); }
|
|
255
|
+
operator int32_t() const { return toInt<int32_t>(); }
|
|
256
|
+
operator int16_t() const { return toInt<int16_t>(); }
|
|
257
|
+
operator int8_t() const { return toInt<int8_t>(); }
|
|
258
|
+
|
|
259
|
+
private:
|
|
260
|
+
template <typename T>
|
|
261
|
+
T toInt() const {
|
|
262
|
+
static_assert(std::is_integral<T>::value && std::is_signed<T>::value,
|
|
263
|
+
"T must be a signed integral type");
|
|
264
|
+
int64_t v = toI64();
|
|
265
|
+
fits(v, sizeof(T) * 8);
|
|
266
|
+
return static_cast<T>(v);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Convert the bitvector to a signed intN_t, throwing if the value doesn't
|
|
270
|
+
// fit.
|
|
271
|
+
int64_t toI64() const;
|
|
272
|
+
|
|
273
|
+
// Check if the given value fits in the specified bit width.
|
|
274
|
+
static void fits(int64_t v, unsigned n);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
// Arbitrary width unsigned integer type built on MutableBitVector.
|
|
278
|
+
class UInt : public MutableBitVector {
|
|
279
|
+
public:
|
|
280
|
+
using MutableBitVector::MutableBitVector;
|
|
281
|
+
UInt() = default;
|
|
282
|
+
UInt(uint64_t v, unsigned width = 64);
|
|
283
|
+
operator uint64_t() const { return toUI64(); }
|
|
284
|
+
operator uint32_t() const { return toUInt<uint32_t>(); }
|
|
285
|
+
operator uint16_t() const { return toUInt<uint16_t>(); }
|
|
286
|
+
operator uint8_t() const { return toUInt<uint8_t>(); }
|
|
287
|
+
|
|
288
|
+
private:
|
|
289
|
+
uint64_t toUI64() const;
|
|
290
|
+
|
|
291
|
+
static void fits(uint64_t v, unsigned n);
|
|
292
|
+
|
|
293
|
+
template <typename T>
|
|
294
|
+
T toUInt() const {
|
|
295
|
+
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
|
|
296
|
+
"T must be an unsigned integral type");
|
|
297
|
+
uint64_t v = toUI64();
|
|
298
|
+
fits(v, sizeof(T) * 8);
|
|
299
|
+
return static_cast<T>(v);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
} // namespace esi
|
|
304
|
+
|
|
305
|
+
// Enable BitVector and MutableBitVector to work with std::ranges algorithms
|
|
306
|
+
template <>
|
|
307
|
+
inline constexpr bool std::ranges::enable_borrowed_range<esi::BitVector> = true;
|
|
308
|
+
|
|
309
|
+
template <>
|
|
310
|
+
inline constexpr bool
|
|
311
|
+
std::ranges::enable_borrowed_range<esi::MutableBitVector> = true;
|
|
312
|
+
|
|
313
|
+
#endif // ESI_VALUES_H
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
//===----------------------------------------------------------------------===//
|
|
8
8
|
//
|
|
9
9
|
// This is a specialization of the ESI C++ API (backend) for connection into a
|
|
10
|
-
// simulation of an ESI system. Currently uses
|
|
11
|
-
//
|
|
10
|
+
// simulation of an ESI system. Currently uses gRPC, but that could change.
|
|
11
|
+
// Requires gRPC C++ library.
|
|
12
12
|
//
|
|
13
13
|
// DO NOT EDIT!
|
|
14
14
|
// This file is distributed as part of an ESI package. The source for this file
|
|
@@ -26,13 +26,11 @@
|
|
|
26
26
|
#include <set>
|
|
27
27
|
|
|
28
28
|
namespace esi {
|
|
29
|
-
namespace cosim {
|
|
30
|
-
class ChannelDesc;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
namespace backends {
|
|
34
30
|
namespace cosim {
|
|
31
|
+
|
|
35
32
|
class CosimEngine;
|
|
33
|
+
class RpcClient;
|
|
36
34
|
|
|
37
35
|
/// Connect to an ESI simulation.
|
|
38
36
|
class CosimAccelerator : public esi::AcceleratorConnection {
|
|
@@ -53,11 +51,6 @@ public:
|
|
|
53
51
|
// Set the way this connection will retrieve the manifest.
|
|
54
52
|
void setManifestMethod(ManifestMethod method);
|
|
55
53
|
|
|
56
|
-
// C++ doesn't have a mechanism to forward declare a nested class and we don't
|
|
57
|
-
// want to include the generated header here. So we have to wrap it in a
|
|
58
|
-
// forward-declared struct we write ourselves.
|
|
59
|
-
struct StubContainer;
|
|
60
|
-
|
|
61
54
|
void createEngine(const std::string &engineTypeName, AppIDPath idPath,
|
|
62
55
|
const ServiceImplDetails &details,
|
|
63
56
|
const HWClientDetails &clients) override;
|
|
@@ -69,7 +62,7 @@ protected:
|
|
|
69
62
|
const HWClientDetails &clients) override;
|
|
70
63
|
|
|
71
64
|
private:
|
|
72
|
-
|
|
65
|
+
std::unique_ptr<RpcClient> rpcClient;
|
|
73
66
|
|
|
74
67
|
// We own all channels connected to rpcClient since their lifetime is tied to
|
|
75
68
|
// rpcClient.
|