1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
intrinsic %FromConstexpr<To: type, From: type>(b: From): To;
macro FromConstexpr<To: type, From: type>(o: From): To;
FromConstexpr<int31, constexpr int31>(i: constexpr int31): int31 {
return %FromConstexpr<int31>(i);
}
FromConstexpr<int32, constexpr int31>(i: constexpr int31): int32 {
return %FromConstexpr<int32>(i);
}
FromConstexpr<int32, constexpr int32>(i: constexpr int32): int32 {
return %FromConstexpr<int32>(i);
}
FromConstexpr<intptr, constexpr int31>(i: constexpr int31): intptr {
return %FromConstexpr<intptr>(i);
}
FromConstexpr<intptr, constexpr int32>(i: constexpr int32): intptr {
return %FromConstexpr<intptr>(i);
}
FromConstexpr<intptr, constexpr intptr>(i: constexpr intptr): intptr {
return %FromConstexpr<intptr>(i);
}
FromConstexpr<uintptr, constexpr uintptr>(i: constexpr uintptr): uintptr {
return %FromConstexpr<uintptr>(i);
}
FromConstexpr<Smi, constexpr int31>(i: constexpr int31): Smi {
return %FromConstexpr<Smi>(i);
}
FromConstexpr<PositiveSmi, constexpr int31>(i: constexpr int31): PositiveSmi {
assert(i >= 0);
return %FromConstexpr<PositiveSmi>(i);
}
FromConstexpr<String, constexpr string>(s: constexpr string): String {
return %FromConstexpr<String>(s);
}
FromConstexpr<Number, constexpr uint32>(i: constexpr uint32): Number {
return %FromConstexpr<Number>(i);
}
FromConstexpr<Number, constexpr int32>(i: constexpr int32): Number {
return %FromConstexpr<Number>(i);
}
FromConstexpr<Number, constexpr float64>(f: constexpr float64): Number {
return %FromConstexpr<Number>(f);
}
FromConstexpr<Number, constexpr int31>(i: constexpr int31): Number {
return %FromConstexpr<Number>(i);
}
FromConstexpr<uint8, constexpr int31>(i: constexpr int31): uint8 {
const i: uint32 = i;
StaticAssert(i <= 255);
return %RawDownCast<uint8>(i);
}
FromConstexpr<Number, constexpr Smi>(s: constexpr Smi): Number {
return SmiConstant(s);
}
FromConstexpr<Smi, constexpr Smi>(s: constexpr Smi): Smi {
return SmiConstant(s);
}
FromConstexpr<uint32, constexpr int31>(i: constexpr int31): uint32 {
return Unsigned(Int32Constant(i));
}
FromConstexpr<uint32, constexpr uint32>(i: constexpr uint32): uint32 {
return Unsigned(%FromConstexpr<int32>(i));
}
FromConstexpr<uintptr, constexpr int31>(i: constexpr int31): uintptr {
return ChangeUint32ToWord(i);
}
FromConstexpr<float64, constexpr int31>(i: constexpr int31): float64 {
return Float64Constant(i);
}
FromConstexpr<float64, constexpr float64>(i: constexpr float64): float64 {
return Float64Constant(i);
}
FromConstexpr<bool, constexpr bool>(b: constexpr bool): bool {
return BoolConstant(b);
}
FromConstexpr<Object, constexpr string>(s: constexpr string): Object {
return StringConstant(s);
}
FromConstexpr<JSAny, constexpr string>(s: constexpr string): JSAny {
return StringConstant(s);
}
FromConstexpr<ContextSlot, constexpr ContextSlot>(c: constexpr ContextSlot):
ContextSlot {
return IntPtrConstant(c);
}
FromConstexpr<LanguageModeSmi, constexpr LanguageMode>(
c: constexpr LanguageMode): LanguageModeSmi {
return %RawDownCast<LanguageModeSmi>(SmiConstant(c));
}
FromConstexpr<PromiseState, constexpr PromiseState>(c: constexpr PromiseState):
PromiseState {
return %RawDownCast<PromiseState>(Int32Constant(c));
}
macro Convert<To: type, From: type>(i: From): To {
return i;
}
macro Convert<To: type, From: type>(i: From): To labels Overflow {
return i;
}
extern macro ConvertElementsKindToInt(ElementsKind): int32;
Convert<int32, ElementsKind>(elementsKind: ElementsKind): int32 {
return ConvertElementsKindToInt(elementsKind);
}
Convert<Number, int32>(i: int32): Number {
return ChangeInt32ToTagged(i);
}
Convert<intptr, int32>(i: int32): intptr {
return ChangeInt32ToIntPtr(i);
}
Convert<intptr, uint32>(i: uint32): intptr {
return Signed(ChangeUint32ToWord(i));
}
Convert<Smi, int32>(i: int32): Smi {
return SmiFromInt32(i);
}
Convert<Number, uint32>(ui: uint32): Number {
return ChangeUint32ToTagged(ui);
}
Convert<Smi, uint32>(ui: uint32): Smi {
return SmiFromUint32(ui);
}
Convert<uintptr, uint32>(ui: uint32): uintptr {
return ChangeUint32ToWord(ui);
}
Convert<intptr, uint16>(ui: uint16): intptr {
return Signed(ChangeUint32ToWord(ui));
}
Convert<intptr, uint8>(ui: uint8): intptr {
return Signed(ChangeUint32ToWord(ui));
}
Convert<uint8, intptr>(i: intptr): uint8 {
return %RawDownCast<uint8>(Unsigned(TruncateIntPtrToInt32(i)) & 0xFF);
}
Convert<int32, uint8>(i: uint8): int32 {
return Signed(Convert<uint32>(i));
}
Convert<int32, uint16>(i: uint16): int32 {
return Signed(Convert<uint32>(i));
}
Convert<int32, uint31>(i: uint31): int32 {
return Signed(Convert<uint32>(i));
}
Convert<int32, intptr>(i: intptr): int32 {
return TruncateIntPtrToInt32(i);
}
Convert<int32, Number>(n: Number): int32 {
typeswitch (n) {
case (s: Smi): {
return Convert<int32>(s);
}
case (h: HeapNumber): {
return TruncateHeapNumberValueToWord32(h);
}
}
}
Convert<Smi, intptr>(i: intptr): Smi {
return SmiTag(i);
}
Convert<uint32, uintptr>(ui: uintptr): uint32 {
return Unsigned(TruncateIntPtrToInt32(Signed(ui)));
}
Convert<intptr, Smi>(s: Smi): intptr {
return SmiUntag(s);
}
Convert<uintptr, PositiveSmi>(ps: PositiveSmi): uintptr {
return Unsigned(SmiUntag(ps));
}
Convert<intptr, TaggedIndex>(ti: TaggedIndex): intptr {
return TaggedIndexToIntPtr(ti);
}
Convert<TaggedIndex, intptr>(i: intptr): TaggedIndex {
return IntPtrToTaggedIndex(i);
}
Convert<intptr, uintptr>(ui: uintptr): intptr {
const i = Signed(ui);
assert(i >= 0);
return i;
}
Convert<PositiveSmi, intptr>(i: intptr): PositiveSmi {
assert(IsValidPositiveSmi(i));
return %RawDownCast<PositiveSmi>(SmiTag(i));
}
Convert<PositiveSmi, uintptr>(ui: uintptr): PositiveSmi labels IfOverflow {
if (ui > kSmiMaxValue) deferred {
goto IfOverflow;
}
return %RawDownCast<PositiveSmi>(SmiTag(Signed(ui)));
}
Convert<PositiveSmi, intptr>(i: intptr): PositiveSmi labels IfOverflow {
if (IsValidPositiveSmi(i)) {
return %RawDownCast<PositiveSmi>(SmiTag(i));
} else
deferred {
goto IfOverflow;
}
}
Convert<int32, Smi>(s: Smi): int32 {
return SmiToInt32(s);
}
Convert<float64, HeapNumber>(h: HeapNumber): float64 {
return LoadHeapNumberValue(h);
}
Convert<float64, Number>(n: Number): float64 {
return ChangeNumberToFloat64(n);
}
Convert<uintptr, Number>(n: Number): uintptr {
return ChangeUintPtrNumberToUintPtr(n);
}
Convert<float64, int32>(f: int32): float64 {
return ChangeInt32ToFloat64(f);
}
Convert<float64, float32>(f: float32): float64 {
return ChangeFloat32ToFloat64(f);
}
Convert<float64_or_hole, float64>(f: float64): float64_or_hole {
return float64_or_hole{is_hole: false, value: f};
}
Convert<float64_or_hole, Number>(n: Number): float64_or_hole {
return Convert<float64_or_hole>(Convert<float64>(n));
}
Convert<float32, float64>(f: float64): float32 {
return TruncateFloat64ToFloat32(f);
}
Convert<float32, Number>(n: Number): float32 {
return Convert<float32>(ChangeNumberToFloat64(n));
}
Convert<Number, float64>(d: float64): Number {
return ChangeFloat64ToTagged(d);
}
Convert<float64, uintptr>(ui: uintptr): float64 {
return ChangeUintPtrToFloat64(ui);
}
Convert<Number, uintptr>(ui: uintptr): Number {
return ChangeUintPtrToTagged(ui);
}
Convert<Number, intptr>(i: intptr): Number {
return ChangeUintPtrToTagged(Unsigned(i));
}
Convert<uintptr, float64>(d: float64): uintptr {
return ChangeFloat64ToUintPtr(d);
}
Convert<uintptr, intptr>(i: intptr): uintptr {
return Unsigned(i);
}
Convert<uintptr, RawPtr>(r: RawPtr): uintptr {
return Unsigned(r);
}
Convert<intptr, RawPtr>(r: RawPtr): intptr {
return Signed(r);
}
Convert<intptr, Number>(n: Number): intptr {
return ChangeFloat64ToIntPtr(ChangeNumberToFloat64(n));
}
Convert<bint, int32>(v: int32): bint {
return IntPtrToBInt(Convert<intptr>(v));
}
extern macro IntPtrToBInt(intptr): bint;
Convert<bint, intptr>(v: intptr): bint {
return IntPtrToBInt(v);
}
extern macro BIntToIntPtr(bint): intptr;
Convert<intptr, bint>(v: bint): intptr {
return BIntToIntPtr(v);
}
extern macro SmiToBInt(Smi): bint;
Convert<bint, Smi>(v: Smi): bint {
return SmiToBInt(v);
}
extern macro BIntToSmi(bint): Smi;
Convert<Smi, bint>(v: bint): Smi {
return BIntToSmi(v);
}
Convert<PromiseState, int32>(s: int32): PromiseState {
return %RawDownCast<PromiseState>(s);
}
Convert<ScopeFlags, Smi>(s: Smi): ScopeFlags {
return %RawDownCast<ScopeFlags>(Unsigned(SmiToInt32(s)));
}
|