@@ -117,14 +117,16 @@ struct LLVMMemoryCopyFillLowering
117117 void createMemoryCopyFunc (Module* module ) {
118118 Builder b (*module );
119119 Index dst = 0 , src = 1 , size = 2 , start = 3 , end = 4 , step = 5 , i = 6 ;
120- Name memory = module ->memories .front ()->name ;
120+ Name memory_name = module ->memories .front ()->name ;
121+ Address::address32_t memory_page_size = module ->memories .front ()->pageSizeLog2 ;
121122 Block* body = b.makeBlock ();
122123 // end = memory size in bytes
123124 body->list .push_back (
124125 b.makeLocalSet (end,
125- b.makeBinary (BinaryOp::MulInt32,
126- b.makeMemorySize (memory),
127- b.makeConst (Memory::kPageSize ))));
126+ memory_page_size == 0 ? static_cast <Expression*>(b.makeMemorySize (memory_name)):
127+ static_cast <Expression*>(b.makeBinary (BinaryOp::ShlInt32,
128+ b.makeMemorySize (memory_name),
129+ b.makeConst (memory_page_size)))));
128130 // if dst + size > memsize or src + size > memsize, then trap.
129131 body->list .push_back (b.makeIf (
130132 b.makeBinary (BinaryOp::OrInt32,
@@ -187,9 +189,9 @@ struct LLVMMemoryCopyFillLowering
187189 b.makeLocalGet (src, Type::i32 ),
188190 b.makeLocalGet (i, Type::i32 )),
189191 Type::i32 ,
190- memory ),
192+ memory_name ),
191193 Type::i32 ,
192- memory ),
194+ memory_name ),
193195 // i += step
194196 b.makeLocalSet (i,
195197 b.makeBinary (BinaryOp::AddInt32,
@@ -203,7 +205,9 @@ struct LLVMMemoryCopyFillLowering
203205 void createMemoryFillFunc (Module* module ) {
204206 Builder b (*module );
205207 Index dst = 0 , val = 1 , size = 2 ;
206- Name memory = module ->memories .front ()->name ;
208+ Name memory_name = module ->memories .front ()->name ;
209+ Address::address32_t memory_page_size =
210+ module ->memories .front ()->pageSizeLog2 ;
207211 Block* body = b.makeBlock ();
208212
209213 // if dst + size > memsize in bytes, then trap.
@@ -212,9 +216,10 @@ struct LLVMMemoryCopyFillLowering
212216 b.makeBinary (BinaryOp::AddInt32,
213217 b.makeLocalGet (dst, Type::i32 ),
214218 b.makeLocalGet (size, Type::i32 )),
215- b.makeBinary (BinaryOp::MulInt32,
216- b.makeMemorySize (memory),
217- b.makeConst (Memory::kPageSize ))),
219+ memory_page_size == 0 ? static_cast <Expression*>(b.makeMemorySize (memory_name)):
220+ static_cast <Expression*>(b.makeBinary (BinaryOp::ShlInt32,
221+ b.makeMemorySize (memory_name),
222+ b.makeConst (memory_page_size)))),
218223 b.makeUnreachable ()));
219224
220225 body->list .push_back (b.makeBlock (
@@ -241,7 +246,7 @@ struct LLVMMemoryCopyFillLowering
241246 b.makeLocalGet (size, Type::i32 )),
242247 b.makeLocalGet (val, Type::i32 ),
243248 Type::i32 ,
244- memory ),
249+ memory_name ),
245250 b.makeBreak (" copy" , nullptr )}))));
246251 module ->getFunction (memFillFuncName)->body = body;
247252 }
0 commit comments