@@ -42,6 +42,11 @@ bool IsFpRegisterLocation (i16 i_location) { return (i_location == d_m3
42
42
bool IsIntRegisterLocation (i16 i_location ) { return (i_location == d_m3Reg0SlotAlias ); }
43
43
44
44
45
+ u32 GetTypeNumSlots (u8 i_type )
46
+ {
47
+ return Is64BitType (i_type ) ? 1 : 1 ;
48
+ }
49
+
45
50
i16 GetStackTopIndex (IM3Compilation o )
46
51
{
47
52
return o -> stackIndex - 1 ;
@@ -77,7 +82,6 @@ u8 GetStackBottomType (IM3Compilation o, u16 i_offset)
77
82
}
78
83
79
84
80
-
81
85
u8 GetBlockType (IM3Compilation o )
82
86
{
83
87
return o -> block .type ;
@@ -154,10 +158,10 @@ void MarkSlotAllocated (IM3Compilation o, u16 i_slot)
154
158
}
155
159
156
160
157
- bool AllocateSlot (IM3Compilation o , u16 * o_execSlot )
161
+ bool AllocateSlots (IM3Compilation o , u16 * o_execSlot , u8 i_type )
158
162
{
159
163
bool found = false;
160
-
164
+
161
165
// search for empty slot in the execution stack
162
166
i16 i = o -> firstSlotIndex ;
163
167
while (i < d_m3MaxFunctionStackHeight )
@@ -194,11 +198,15 @@ M3Result IncrementSlotUsageCount (IM3Compilation o, u16 i_slot)
194
198
}
195
199
196
200
197
- void DeallocateSlot (IM3Compilation o , i16 i_slotIndex )
201
+ void DeallocateSlot (IM3Compilation o , i16 i_slotIndex , u8 i_type )
198
202
{ d_m3Assert (i_slotIndex >= o -> firstSlotIndex );
199
203
d_m3Assert (o -> m3Slots [i_slotIndex ]);
200
- if (-- o -> m3Slots [i_slotIndex ] == 0 )
201
- o -> numAllocatedExecSlots -- ;
204
+ for (u32 i = 0 ; i < GetTypeNumSlots (i_type ); ++ i , ++ i_slotIndex )
205
+ {
206
+ if (-- o -> m3Slots [i_slotIndex ] == 0 )
207
+ o -> numAllocatedExecSlots -- ;
208
+ }
209
+
202
210
}
203
211
204
212
@@ -268,15 +276,15 @@ M3Result PreserveRegisterIfOccupied (IM3Compilation o, u8 i_registerType)
268
276
{
269
277
u16 stackIndex = GetRegisterStackIndex (o , regSelect );
270
278
DeallocateRegister (o , regSelect );
279
+
280
+ u8 type = GetStackBottomType (o , stackIndex );
271
281
272
282
// and point to a exec slot
273
283
u16 slot ;
274
- if (AllocateSlot (o , & slot ))
284
+ if (AllocateSlots (o , & slot , type ))
275
285
{
276
286
o -> wasmStack [stackIndex ] = slot ;
277
287
278
- u8 type = o -> typeStack [stackIndex ];
279
-
280
288
_ (EmitOp (o , c_setSetOps [type ]));
281
289
EmitSlotOffset (o , slot );
282
290
}
@@ -328,7 +336,7 @@ _ (PreserveRegisterIfOccupied (o, c_m3Type_f64));
328
336
//----------------------------------------------------------------------------------------------------------------------
329
337
330
338
331
- M3Result Push (IM3Compilation o , u8 i_m3Type , i16 i_location )
339
+ M3Result Push (IM3Compilation o , u8 i_type , i16 i_location )
332
340
{
333
341
M3Result result = m3Err_none ;
334
342
@@ -344,7 +352,7 @@ M3Result Push (IM3Compilation o, u8 i_m3Type, i16 i_location)
344
352
}
345
353
346
354
o -> wasmStack [stackIndex ] = i_location ;
347
- o -> typeStack [stackIndex ] = i_m3Type ;
355
+ o -> typeStack [stackIndex ] = i_type ;
348
356
349
357
if (IsRegisterLocation (i_location ))
350
358
{
@@ -358,10 +366,10 @@ M3Result Push (IM3Compilation o, u8 i_m3Type, i16 i_location)
358
366
}
359
367
360
368
361
- M3Result PushRegister (IM3Compilation o , u8 i_m3Type )
369
+ M3Result PushRegister (IM3Compilation o , u8 i_type )
362
370
{
363
- i16 location = IsFpType (i_m3Type ) ? d_m3Fp0SlotAlias : d_m3Reg0SlotAlias ; d_m3Assert (i_m3Type or IsStackPolymorphic (o ));
364
- return Push (o , i_m3Type , location );
371
+ i16 location = IsFpType (i_type ) ? d_m3Fp0SlotAlias : d_m3Reg0SlotAlias ; d_m3Assert (i_type or IsStackPolymorphic (o ));
372
+ return Push (o , i_type , location );
365
373
}
366
374
367
375
@@ -374,6 +382,7 @@ M3Result Pop (IM3Compilation o)
374
382
o -> stackIndex -- ; // printf ("pop: %d\n", (i32) o->stackIndex);
375
383
376
384
i16 location = o -> wasmStack [o -> stackIndex ];
385
+ u8 type = o -> typeStack [o -> stackIndex ];
377
386
378
387
if (IsRegisterLocation (location ))
379
388
{
@@ -382,7 +391,7 @@ M3Result Pop (IM3Compilation o)
382
391
}
383
392
else if (location >= o -> firstSlotIndex )
384
393
{
385
- DeallocateSlot (o , location );
394
+ DeallocateSlot (o , location , type );
386
395
}
387
396
388
397
m3logif (stack , dump_type_stack (o ))
@@ -414,15 +423,15 @@ _ (Pop (o));
414
423
}
415
424
416
425
417
- M3Result _PushAllocatedSlotAndEmit (IM3Compilation o , u8 i_m3Type , bool i_doEmit )
426
+ M3Result _PushAllocatedSlotAndEmit (IM3Compilation o , u8 i_type , bool i_doEmit )
418
427
{
419
428
M3Result result = m3Err_none ;
420
429
421
430
u16 slot ;
422
431
423
- if (AllocateSlot (o , & slot ))
432
+ if (AllocateSlots (o , & slot , i_type ))
424
433
{
425
- _ (Push (o , i_m3Type , slot ));
434
+ _ (Push (o , i_type , slot ));
426
435
427
436
if (i_doEmit )
428
437
EmitSlotOffset (o , slot );
@@ -433,19 +442,19 @@ _ (Push (o, i_m3Type, slot));
433
442
}
434
443
435
444
436
- M3Result PushAllocatedSlotAndEmit (IM3Compilation o , u8 i_m3Type )
445
+ M3Result PushAllocatedSlotAndEmit (IM3Compilation o , u8 i_type )
437
446
{
438
- return _PushAllocatedSlotAndEmit (o , i_m3Type , true);
447
+ return _PushAllocatedSlotAndEmit (o , i_type , true);
439
448
}
440
449
441
450
442
- M3Result PushAllocatedSlot (IM3Compilation o , u8 i_m3Type )
451
+ M3Result PushAllocatedSlot (IM3Compilation o , u8 i_type )
443
452
{
444
- return _PushAllocatedSlotAndEmit (o , i_m3Type , false);
453
+ return _PushAllocatedSlotAndEmit (o , i_type , false);
445
454
}
446
455
447
456
448
- M3Result PushConst (IM3Compilation o , u64 i_word , u8 i_m3Type )
457
+ M3Result PushConst (IM3Compilation o , u64 i_word , u8 i_type )
449
458
{
450
459
M3Result result = m3Err_none ;
451
460
@@ -459,7 +468,7 @@ M3Result PushConst (IM3Compilation o, u64 i_word, u8 i_m3Type)
459
468
if (o -> constants [i ] == i_word )
460
469
{
461
470
location = o -> firstConstSlotIndex + i ;
462
- _ (Push (o , i_m3Type , location ));
471
+ _ (Push (o , i_type , location ));
463
472
break ;
464
473
}
465
474
}
@@ -471,13 +480,13 @@ _ (Push (o, i_m3Type, location));
471
480
o -> constants [numConstants ] = i_word ;
472
481
location = o -> constSlotIndex ++ ;
473
482
474
- _ (Push (o , i_m3Type , location ));
483
+ _ (Push (o , i_type , location ));
475
484
}
476
485
else
477
486
{
478
487
_ (EmitOp (o , op_Const ));
479
488
EmitConstant64 (o , i_word );
480
- _ (PushAllocatedSlotAndEmit (o , i_m3Type ));
489
+ _ (PushAllocatedSlotAndEmit (o , i_type ));
481
490
}
482
491
}
483
492
@@ -686,7 +695,9 @@ M3Result FindReferencedLocalWithinCurrentBlock (IM3Compilation o, u16 * o_pres
686
695
{
687
696
if (* o_preservedSlotIndex == i_localIndex )
688
697
{
689
- if (not AllocateSlot (o , o_preservedSlotIndex ))
698
+ u8 localType = GetStackBottomType (o , i_localIndex );
699
+
700
+ if (not AllocateSlots (o , o_preservedSlotIndex , localType ))
690
701
_throw (m3Err_functionStackOverflow );
691
702
}
692
703
else
@@ -1239,7 +1250,7 @@ _ (ReadLEB_i7 (& reserved, & o->wasm, o->wasmEnd));
1239
1250
1240
1251
_ (EmitOp (o , op_MemCurrent ));
1241
1252
1242
- _ (PushRegister (o , c_m3Type_i32 )); // i32?
1253
+ _ (PushRegister (o , c_m3Type_i32 ));
1243
1254
1244
1255
_catch : return result ;
1245
1256
}
@@ -1257,7 +1268,7 @@ _ (Pop (o));
1257
1268
1258
1269
_ (EmitOp (o , op_MemGrow ));
1259
1270
1260
- _ (PushRegister (o , c_m3Type_i32 )); // i32?
1271
+ _ (PushRegister (o , c_m3Type_i32 ));
1261
1272
1262
1273
_catch : return result ;
1263
1274
}
@@ -1760,9 +1771,9 @@ const M3OpInfo c_operations [] =
1760
1771
M3OP ( "i32.div_u" , -1 , i_32 , d_binOpList (u32 , Divide ) ), // 0x6e
1761
1772
M3OP ( "i32.rem_s" , -1 , i_32 , d_binOpList (i32 , Remainder ) ), // 0x6f
1762
1773
M3OP ( "i32.rem_u" , -1 , i_32 , d_binOpList (u32 , Remainder ) ), // 0x70
1763
- M3OP ( "i32.and" , -1 , i_32 , d_commutativeBinOpList (u64 , And ) ), // 0x71
1764
- M3OP ( "i32.or" , -1 , i_32 , d_commutativeBinOpList (u64 , Or ) ), // 0x72
1765
- M3OP ( "i32.xor" , -1 , i_32 , d_commutativeBinOpList (u64 , Xor ) ), // 0x73
1774
+ M3OP ( "i32.and" , -1 , i_32 , d_commutativeBinOpList (u32 , And ) ), // 0x71
1775
+ M3OP ( "i32.or" , -1 , i_32 , d_commutativeBinOpList (u32 , Or ) ), // 0x72
1776
+ M3OP ( "i32.xor" , -1 , i_32 , d_commutativeBinOpList (u32 , Xor ) ), // 0x73
1766
1777
M3OP ( "i32.shl" , -1 , i_32 , d_binOpList (u32 , ShiftLeft ) ), // 0x74
1767
1778
M3OP ( "i32.shr_s" , -1 , i_32 , d_binOpList (i32 , ShiftRight ) ), // 0x75
1768
1779
M3OP ( "i32.shr_u" , -1 , i_32 , d_binOpList (u32 , ShiftRight ) ), // 0x76
0 commit comments