Skip to content

Commit a5f0423

Browse files
authored
Use fewer bits for BasicHeapType (#7404)
Now that we aren't supporting exact reference types, we no longer need to leave bit 2 free for use by the Type representation. Shift the basic HeapType representations down to start at bit 2 instead of bit 3.
1 parent fbf2010 commit a5f0423

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/wasm-type.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,13 @@ class HeapType {
9595
// should also be passed by value.
9696
uintptr_t id;
9797

98-
static constexpr int TypeBits = 3;
98+
static constexpr int TypeBits = 2;
9999
static constexpr int UsedBits = TypeBits + 1;
100100
static constexpr int SharedMask = 1 << TypeBits;
101101

102102
public:
103-
// Bits 0-2 are used by the Type representation, so need to be left free.
104-
// Bit 3 determines whether the basic heap type is shared (1) or unshared (0).
103+
// Bits 0-1 are used by the Type representation, so need to be left free.
104+
// Bit 2 determines whether the basic heap type is shared (1) or unshared (0).
105105
enum BasicHeapType : uint32_t {
106106
ext = 1 << UsedBits,
107107
func = 2 << UsedBits,
@@ -278,7 +278,7 @@ class Type {
278278
// bit 0 set. When that bit is masked off, they are pointers to the underlying
279279
// vectors of types. Otherwise, the type is a reference type, and is
280280
// represented as a heap type with bit 1 set iff the reference type is
281-
// nullable and bit 2 set iff the reference type is exact.
281+
// nullable.
282282
//
283283
// Since `Type` is really just a single integer, it should be passed by value.
284284
// This is a uintptr_t rather than a TypeID (uint64_t) to save memory on
@@ -287,7 +287,6 @@ class Type {
287287

288288
static constexpr int TupleMask = 1 << 0;
289289
static constexpr int NullMask = 1 << 1;
290-
static constexpr int ExactMask = 1 << 2;
291290

292291
public:
293292
enum BasicType : uint32_t {
@@ -320,8 +319,7 @@ class Type {
320319
// Signature, Struct or Array via implicit conversion to HeapType.
321320
Type(HeapType heapType, Nullability nullable)
322321
: Type(heapType.getID() | (nullable == Nullable ? NullMask : 0)) {
323-
assert(heapType.isBasic() ||
324-
!(heapType.getID() & (TupleMask | NullMask | ExactMask)));
322+
assert(heapType.isBasic() || !(heapType.getID() & (TupleMask | NullMask)));
325323
}
326324

327325
// Predicates
@@ -372,7 +370,7 @@ class Type {
372370
bool isNonNullable() const { return isRef() && !(id & NullMask); }
373371
HeapType getHeapType() const {
374372
assert(isRef());
375-
return HeapType(id & ~(NullMask | ExactMask));
373+
return HeapType(id & ~NullMask);
376374
}
377375

378376
bool isFunction() const { return isRef() && getHeapType().isFunction(); }

test/example/c-api-kitchen-sink.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ BinaryenTypeAuto: -1
2020
BinaryenPackedTypeNotPacked: 0
2121
BinaryenPackedTypeInt8: 1
2222
BinaryenPackedTypeInt16: 2
23-
BinaryenHeapTypeExt: 16
24-
BinaryenHeapTypeFunc: 32
25-
BinaryenHeapTypeAny: 64
26-
BinaryenHeapTypeEq: 80
27-
BinaryenHeapTypeI31: 96
28-
BinaryenHeapTypeStruct: 112
29-
BinaryenHeapTypeArray: 128
30-
BinaryenHeapTypeString: 160
31-
BinaryenHeapTypeNone: 176
32-
BinaryenHeapTypeNoext: 192
33-
BinaryenHeapTypeNofunc: 208
23+
BinaryenHeapTypeExt: 8
24+
BinaryenHeapTypeFunc: 16
25+
BinaryenHeapTypeAny: 32
26+
BinaryenHeapTypeEq: 40
27+
BinaryenHeapTypeI31: 48
28+
BinaryenHeapTypeStruct: 56
29+
BinaryenHeapTypeArray: 64
30+
BinaryenHeapTypeString: 80
31+
BinaryenHeapTypeNone: 88
32+
BinaryenHeapTypeNoext: 96
33+
BinaryenHeapTypeNofunc: 104
3434
BinaryenFeatureMVP: 0
3535
BinaryenFeatureAtomics: 1
3636
BinaryenFeatureBulkMemory: 16

0 commit comments

Comments
 (0)