@@ -50,9 +50,12 @@ i16 GetNumBlockValues (IM3Compilation o) { return o->stackIndex - o->
50
50
51
51
u16 GetTypeNumSlots (u8 i_type )
52
52
{
53
- // return 1;
54
- u16 n = Is64BitType (i_type ) ? 2 : 1 ;
55
- return n ;
53
+ # if d_m3Use32BitSlots
54
+ u16 n = Is64BitType (i_type ) ? 2 : 1 ;
55
+ return n ;
56
+ # else
57
+ return 1 ;
58
+ # endif
56
59
}
57
60
58
61
i16 GetStackTopIndex (IM3Compilation o )
@@ -177,8 +180,9 @@ M3Result AllocateSlotsWithinRange (IM3Compilation o, u16 * o_slot, u8 i_type,
177
180
178
181
u16 numSlots = GetTypeNumSlots (i_type );
179
182
u16 searchOffset = numSlots - 1 ;
180
-
181
- AlignSlotIndexToType (& i_startSlot , i_type );
183
+
184
+ if (d_m3Use32BitSlots )
185
+ AlignSlotIndexToType (& i_startSlot , i_type );
182
186
183
187
// search for 1 or 2 consecutive slots in the execution stack
184
188
u16 i = i_startSlot ;
@@ -539,15 +543,15 @@ _ (Push (o, i_type, slot));
539
543
{
540
544
result = m3Err_none ;
541
545
542
- _ (EmitOp (o , numRequiredSlots == 1 ? op_Const32 : op_Const64 ));
546
+ _ (EmitOp (o , Is64BitType ( i_type ) ? op_Const64 : op_Const32 ));
543
547
EmitConstant64 (o , i_word );
544
548
_ (PushAllocatedSlotAndEmit (o , i_type ));
545
549
}
546
550
else
547
551
{
548
552
u16 constTableIndex = slot - o -> firstConstSlotIndex ;
549
553
550
- if (numRequiredSlots == 2 )
554
+ if (Is64BitType ( i_type ) )
551
555
{
552
556
u64 * constant64 = (u64 * ) & o -> constants [constTableIndex ];
553
557
* constant64 = i_word ;
@@ -618,6 +622,9 @@ bool PatchBranches (IM3Compilation o)
618
622
619
623
while (patches )
620
624
{ m3log (compile , "patching location: %p to pc: %p" , patches -> location , pc );
625
+ if (not patches -> location )
626
+ break ;
627
+
621
628
* (patches -> location ) = pc ;
622
629
623
630
endPatch = patches ;
@@ -1220,8 +1227,6 @@ void AlignSlotIndexToType (u16 * io_slotIndex, u8 i_type)
1220
1227
// align 64-bit words to even slots
1221
1228
u16 numSlots = GetTypeNumSlots (i_type );
1222
1229
1223
- // printf ("%d\n", (u32) numSlots);
1224
-
1225
1230
u16 mask = numSlots - 1 ;
1226
1231
* io_slotIndex = (* io_slotIndex + mask ) & ~mask ;
1227
1232
}
@@ -1251,12 +1256,14 @@ _ (Pop (o));
1251
1256
1252
1257
u32 numArgs = i_type -> numArgs ;
1253
1258
1259
+ u32 slotsPerArg = sizeof (u64 ) / sizeof (m3slot_t );
1260
+
1254
1261
// args are 64-bit aligned
1255
- u16 argTop = topSlot + numArgs * 2 ;
1262
+ u16 argTop = topSlot + numArgs * slotsPerArg ;
1256
1263
1257
1264
while (numArgs -- )
1258
1265
{
1259
- _ (CopyTopSlot (o , argTop -= 2 ));
1266
+ _ (CopyTopSlot (o , argTop -= slotsPerArg ));
1260
1267
_ (Pop (o ));
1261
1268
}
1262
1269
@@ -1803,7 +1810,7 @@ const M3OpInfo c_operations [] =
1803
1810
M3OP ( "local.get" , 1 , any , d_emptyOpList , Compile_GetLocal ), // 0x20
1804
1811
M3OP ( "local.set" , 1 , none , d_emptyOpList , Compile_SetLocal ), // 0x21
1805
1812
M3OP ( "local.tee" , 0 , any , d_emptyOpList , Compile_SetLocal ), // 0x22
1806
- M3OP ( "global.get" , 1 , none , d_logOp2 ( GetGlobal_s32 , GetGlobal_s64 ), Compile_GetSetGlobal ), // 0x23
1813
+ M3OP ( "global.get" , 1 , none , d_emptyOpList , Compile_GetSetGlobal ), // 0x23
1807
1814
M3OP ( "global.set" , 1 , none , d_emptyOpList , Compile_GetSetGlobal ), // 0x24
1808
1815
1809
1816
M3OP_RESERVED , M3OP_RESERVED , M3OP_RESERVED , // 0x25 - 0x27
@@ -1999,6 +2006,8 @@ const M3OpInfo c_operations [] =
1999
2006
# define d_m3DebugTypedOp (OP ) M3OP (#OP, 0, none, { op_##OP##_i32, op_##OP##_i64, op_##OP##_f32, op_##OP##_f64, })
2000
2007
2001
2008
d_m3DebugOp (Entry ), d_m3DebugOp (Compile ), d_m3DebugOp (End ),
2009
+
2010
+ d_m3DebugOp (GetGlobal_s32 ), d_m3DebugOp (GetGlobal_s64 ),
2002
2011
2003
2012
d_m3DebugOp (ContinueLoop ), d_m3DebugOp (ContinueLoopIf ),
2004
2013
@@ -2195,7 +2204,7 @@ M3Result Compile_Function (IM3Function io_function)
2195
2204
M3Result result = m3Err_none ; m3log (compile , "compiling: '%s'; wasm-size: %d; numArgs: %d; return: %s" ,
2196
2205
io_function -> name , (u32 ) (io_function -> wasmEnd - io_function -> wasm ), GetFunctionNumArgs (io_function ), c_waTypes [GetFunctionReturnType (io_function )]);
2197
2206
IM3Runtime runtime = io_function -> module -> runtime ;
2198
-
2207
+
2199
2208
IM3Compilation o = & runtime -> compilation ;
2200
2209
SetupCompilation (o );
2201
2210
@@ -2262,11 +2271,11 @@ _ (Compile_BlockStatements (o));
2262
2271
2263
2272
u32 numConstantSlots = o -> maxConstSlotIndex - o -> firstConstSlotIndex ; m3log (compile , "unique constant slots: %d; unused slots: %d" , numConstantSlots , o -> firstDynamicSlotIndex - o -> maxConstSlotIndex );
2264
2273
2265
- io_function -> numConstantBytes = numConstantSlots * sizeof (u32 );
2274
+ io_function -> numConstantBytes = numConstantSlots * sizeof (m3slot_t );
2266
2275
2267
2276
if (numConstantSlots )
2268
2277
{
2269
- _ (m3Alloc (& io_function -> constants , u32 , numConstantSlots ));
2278
+ _ (m3Alloc (& io_function -> constants , m3slot_t , numConstantSlots ));
2270
2279
2271
2280
memcpy (io_function -> constants , o -> constants , io_function -> numConstantBytes );
2272
2281
}
0 commit comments