Esempio n. 1
0
void petabricks::IterationDefinition::genScratchRegionLoopBegin(CodeGenerator& o){
  if(isSingleCall()){
    genLoopBegin(o);
  }else{
    o.comment("Iterate along all the directions");

    // Compute size
    for(size_t i=0; i<_size.size(); ++i){
      o.write("int " + _size[i]->toString() + " = " + _end[i]->toString() +
              " - " + _begin[i]->toString() + ";");
    }

    for(size_t i=0; i<_var.size(); ++i){
      FormulaPtr b= new FormulaLiteral<int>(0);
      FormulaPtr e=_size[i];
      FormulaPtr s=_step[i];
      FormulaPtr v=_var[i];
      //TODO: expand to reorder dimensions
      if(_order.canIterateForward(i) || !_order.canIterateBackward(i)){
        JWARNING(_order.canIterateForward(i))(_order).Text("couldn't find valid iteration order, assuming forward");
        o.beginFor(v->toString(), b, e, s);
      } else {
        o.beginReverseFor(v->toString(), b, e, s);
      }
    }
  }
}
Esempio n. 2
0
void petabricks::IterationDefinition::genLoopBegin(CodeGenerator& o){
  if(isSingleCall()){
    o.write("{");
    for(size_t i=0; i<_var.size(); ++i){
      o.varDecl("const IndexT "+_var[i]->toString()+" = "+_begin[i]->toString());
    }
  }else{
    o.comment("Iterate along all the directions");
    for(size_t i=0; i<_var.size(); ++i){
      FormulaPtr b=_begin[i];
      FormulaPtr e=_end[i];
      FormulaPtr s=_step[i];
      FormulaPtr v=_var[i];
      //TODO: expand to reorder dimensions
      if(_order.canIterateForward(i) || !_order.canIterateBackward(i)){
        JWARNING(_order.canIterateForward(i))(_order).Text("couldn't find valid iteration order, assuming forward");
        o.beginFor(v->toString(), b, e, s);
      } else {
        o.beginReverseFor(v->toString(), b, e, s);
      }
    }
  }
}