@@ -117,14 +117,19 @@ 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 memoryName = module ->memories .front ()->name ;
121
+ Address::address32_t memory_page_size =
122
+ module ->memories .front ()->pageSizeLog2 ;
121
123
Block* body = b.makeBlock ();
122
124
// end = memory size in bytes
123
125
body->list .push_back (
124
126
b.makeLocalSet (end,
125
- b.makeBinary (BinaryOp::MulInt32,
126
- b.makeMemorySize (memory),
127
- b.makeConst (Memory::kPageSize ))));
127
+ memory_page_size == 0
128
+ ? static_cast <Expression*>(b.makeMemorySize (memoryName))
129
+ : static_cast <Expression*>(
130
+ b.makeBinary (BinaryOp::ShlInt32,
131
+ b.makeMemorySize (memoryName),
132
+ b.makeConst (memory_page_size)))));
128
133
// if dst + size > memsize or src + size > memsize, then trap.
129
134
body->list .push_back (b.makeIf (
130
135
b.makeBinary (BinaryOp::OrInt32,
@@ -187,9 +192,9 @@ struct LLVMMemoryCopyFillLowering
187
192
b.makeLocalGet (src, Type::i32 ),
188
193
b.makeLocalGet (i, Type::i32 )),
189
194
Type::i32 ,
190
- memory ),
195
+ memoryName ),
191
196
Type::i32 ,
192
- memory ),
197
+ memoryName ),
193
198
// i += step
194
199
b.makeLocalSet (i,
195
200
b.makeBinary (BinaryOp::AddInt32,
@@ -203,19 +208,24 @@ struct LLVMMemoryCopyFillLowering
203
208
void createMemoryFillFunc (Module* module ) {
204
209
Builder b (*module );
205
210
Index dst = 0 , val = 1 , size = 2 ;
206
- Name memory = module ->memories .front ()->name ;
211
+ Name memoryName = module ->memories .front ()->name ;
212
+ Address::address32_t memory_page_size =
213
+ module ->memories .front ()->pageSizeLog2 ;
207
214
Block* body = b.makeBlock ();
208
215
209
216
// if dst + size > memsize in bytes, then trap.
210
- body->list .push_back (
211
- b.makeIf (b.makeBinary (BinaryOp::GtUInt32,
212
- b.makeBinary (BinaryOp::AddInt32,
213
- b.makeLocalGet (dst, Type::i32 ),
214
- b.makeLocalGet (size, Type::i32 )),
215
- b.makeBinary (BinaryOp::MulInt32,
216
- b.makeMemorySize (memory),
217
- b.makeConst (Memory::kPageSize ))),
218
- b.makeUnreachable ()));
217
+ body->list .push_back (b.makeIf (
218
+ b.makeBinary (BinaryOp::GtUInt32,
219
+ b.makeBinary (BinaryOp::AddInt32,
220
+ b.makeLocalGet (dst, Type::i32 ),
221
+ b.makeLocalGet (size, Type::i32 )),
222
+ memory_page_size == 0
223
+ ? static_cast <Expression*>(b.makeMemorySize (memoryName))
224
+ : static_cast <Expression*>(
225
+ b.makeBinary (BinaryOp::ShlInt32,
226
+ b.makeMemorySize (memoryName),
227
+ b.makeConst (memory_page_size)))),
228
+ b.makeUnreachable ()));
219
229
220
230
body->list .push_back (b.makeBlock (
221
231
" out" ,
@@ -241,7 +251,7 @@ struct LLVMMemoryCopyFillLowering
241
251
b.makeLocalGet (size, Type::i32 )),
242
252
b.makeLocalGet (val, Type::i32 ),
243
253
Type::i32 ,
244
- memory ),
254
+ memoryName ),
245
255
b.makeBreak (" copy" , nullptr )}))));
246
256
module ->getFunction (memFillFuncName)->body = body;
247
257
}
0 commit comments