template<typename Scalar> void check_all_in_range(Scalar x, Scalar y) { Array<int,1,Dynamic> mask(y-x+1); mask.fill(0); long n = (y-x+1)*32; for(long k=0; k<n; ++k) { mask( check_in_range(x,y)-x )++; } for(Index i=0; i<mask.size(); ++i) if(mask(i)==0) std::cout << "WARNING: value " << x+i << " not reached." << std::endl; VERIFY( (mask>0).all() ); }
MVar *ComparisonStageIR::get_element(MVar *input_set, MVar *outer_loop_idx, MVar *tile_size, MVar *inner_loop_idx, MBlock *tiled_loop_body, MFor *continue_to, std::vector<MVar *> *args, MVar *range_max, MBlock **set_block) const { int insert_idx = 0; MBlock *linear_block = new MBlock(); linear_block->register_for_delete(); MVar *linear_idx = compute_linear_index(outer_loop_idx, tile_size, inner_loop_idx, linear_block); tiled_loop_body->insert_at(linear_block, insert_idx++); // check that the index is still in range (< range_max) MBlock *range = new MBlock(); range->register_for_delete(); MIfThenElse *ite = check_in_range(linear_idx, range_max, range); tiled_loop_body->insert_at(range, insert_idx++); // If in range, get the element then go to the next loop. // Since the next inner loop is already in the current loop's body, remove it from there (and any other stuff that should only // execute if the we are in range) and then add it to the is_in_range block MIndex *get_input = new MIndex(input_set, linear_idx, create_type<MElementType *>(), "outer_input_element"); get_input->register_for_delete(); ite->get_if_mblock()->add_expr(get_input); args->push_back(get_input->get_result()); ite->get_if_mblock()->add_exprs(tiled_loop_body->remove_range(insert_idx++, -1)); // If out of range, continue to the next iteration of the inner_loop MContinue *to_m_loop = new MContinue(continue_to); to_m_loop->register_for_delete(); ite->get_else_mblock()->add_expr(to_m_loop); if (set_block) { *set_block = ite->get_if_mblock();//inner_is_in_range; } return linear_idx; }