@@ -117,14 +117,16 @@ struct LLVMMemoryCopyFillLowering
117
117
void createMemoryCopyFunc (Module* module ) {
118
118
Builder b (*module );
119
119
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 ;
121
122
Block* body = b.makeBlock ();
122
123
// end = memory size in bytes
123
124
body->list .push_back (
124
125
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)))));
128
130
// if dst + size > memsize or src + size > memsize, then trap.
129
131
body->list .push_back (b.makeIf (
130
132
b.makeBinary (BinaryOp::OrInt32,
@@ -187,9 +189,9 @@ struct LLVMMemoryCopyFillLowering
187
189
b.makeLocalGet (src, Type::i32 ),
188
190
b.makeLocalGet (i, Type::i32 )),
189
191
Type::i32 ,
190
- memory ),
192
+ memory_name ),
191
193
Type::i32 ,
192
- memory ),
194
+ memory_name ),
193
195
// i += step
194
196
b.makeLocalSet (i,
195
197
b.makeBinary (BinaryOp::AddInt32,
@@ -203,7 +205,9 @@ struct LLVMMemoryCopyFillLowering
203
205
void createMemoryFillFunc (Module* module ) {
204
206
Builder b (*module );
205
207
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 ;
207
211
Block* body = b.makeBlock ();
208
212
209
213
// if dst + size > memsize in bytes, then trap.
@@ -212,9 +216,10 @@ struct LLVMMemoryCopyFillLowering
212
216
b.makeBinary (BinaryOp::AddInt32,
213
217
b.makeLocalGet (dst, Type::i32 ),
214
218
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)))),
218
223
b.makeUnreachable ()));
219
224
220
225
body->list .push_back (b.makeBlock (
@@ -241,7 +246,7 @@ struct LLVMMemoryCopyFillLowering
241
246
b.makeLocalGet (size, Type::i32 )),
242
247
b.makeLocalGet (val, Type::i32 ),
243
248
Type::i32 ,
244
- memory ),
249
+ memory_name ),
245
250
b.makeBreak (" copy" , nullptr )}))));
246
251
module ->getFunction (memFillFuncName)->body = body;
247
252
}
0 commit comments