@@ -231,7 +231,8 @@ bool FormulaGenerator::generateSingle(const Program& p) {
231
231
return false ;
232
232
}
233
233
const int64_t numCells = ProgramUtil::getLargestDirectMemoryCell (p) + 1 ;
234
- const bool useIncEval = incEval.init (p, true ); // skip input transformations
234
+ const bool useIncEval =
235
+ incEval.init (p, true , true ); // skip input transformations and offset
235
236
236
237
// initialize function names for memory cells
237
238
cellNames.clear ();
@@ -291,12 +292,13 @@ bool FormulaGenerator::generateSingle(const Program& p) {
291
292
simplifyFormulaUsingVariants (formula, numTerms);
292
293
293
294
// evaluate program and add initial terms to formula
294
- if (!addInitialTerms (numCells, numTerms)) {
295
+ const int64_t offset = ProgramUtil::getOffset (p);
296
+ if (!addInitialTerms (numCells, offset, numTerms)) {
295
297
return false ;
296
298
}
297
299
298
300
// prepare post-loop processing
299
- prepareForPostLoop (numCells, preloopExprs);
301
+ prepareForPostLoop (numCells, offset, preloopExprs);
300
302
Log::get ().debug (" Prepared post-loop: " + formula.toString ());
301
303
302
304
// handle post-loop code
@@ -329,7 +331,8 @@ bool FormulaGenerator::generateSingle(const Program& p) {
329
331
}
330
332
331
333
void FormulaGenerator::prepareForPostLoop (
332
- int64_t numCells, const std::map<int64_t , Expression>& preloopExprs) {
334
+ int64_t numCells, int64_t offset,
335
+ const std::map<int64_t , Expression>& preloopExprs) {
333
336
// prepare post-loop processing
334
337
auto preloopCounter = preloopExprs.at (incEval.getSimpleLoop ().counter );
335
338
for (int64_t cell = 0 ; cell < numCells; cell++) {
@@ -365,7 +368,8 @@ void FormulaGenerator::prepareForPostLoop(
365
368
}
366
369
367
370
bool FormulaGenerator::addInitialTerms (
368
- int64_t numCells, const std::map<std::string, int64_t >& numTerms) {
371
+ int64_t numCells, int64_t offset,
372
+ const std::map<std::string, int64_t >& numTerms) {
369
373
// calculate maximum offset
370
374
int64_t maxNumTerms = 0 ;
371
375
for (auto it : numTerms) {
@@ -374,7 +378,7 @@ bool FormulaGenerator::addInitialTerms(
374
378
maxNumTerms = std::max (maxNumTerms, it.second );
375
379
}
376
380
// evaluate program and add initial terms to formula
377
- for (int64_t offset = 0 ; offset < maxNumTerms; offset ++) {
381
+ for (int64_t n = 0 ; n < maxNumTerms; n ++) {
378
382
try {
379
383
incEval.next (true , true ); // skip final iteration and post loop code
380
384
} catch (const std::exception &) {
@@ -384,9 +388,13 @@ bool FormulaGenerator::addInitialTerms(
384
388
const auto state = incEval.getLoopStates ().at (incEval.getPreviousSlice ());
385
389
for (int64_t cell = 0 ; cell < numCells; cell++) {
386
390
auto name = getCellName (cell);
387
- if (offset < numTerms.at (name)) {
391
+ if (n < numTerms.at (name)) {
392
+ auto arg = n;
393
+ if (cell == Program::INPUT_CELL) {
394
+ arg += offset;
395
+ }
388
396
Expression func (Expression::Type::FUNCTION, name,
389
- {ExpressionUtil::newConstant (offset )});
397
+ {ExpressionUtil::newConstant (arg )});
390
398
Expression val (Expression::Type::CONSTANT, " " , state.get (cell));
391
399
formula.entries [func] = val;
392
400
Log::get ().debug (" Added intial term: " + func.toString () + " = " +
0 commit comments