Lib/v3d/SourceTranslate.cpp
/**
 * Add extra initialization code after uniform loads
 */
Add extra initialization code after uniform loads
Add extra initialization code after uniform loads
void add_init(Instr::List &code) {
  using namespace V3DLib::Target::instr;
  int insert_index = code.tag_index(INIT_BEGIN);
  assertq(insert_index >= 0, "Expecting init begin marker");
  Instr::List ret;
  Label endifLabel = freshLabel();
   Broadly:
   If (numQPUs() == 8)   Alternative is 1, then qpu num initalized to 0 is ok
     me() = (thread_index() >> 2) & 0b1111;
   End
   This works because the thread indexes are consecutive for multiple reserved
   threads. It's probably also the reason why you can select only 1 or 8 (max)
   threads, otherwise there would be gaps in the qpu id.
  ret << mov(rf(RSV_QPU_ID), 0)            not needed, already init'd to 0. Left here to counter future brainfarts
      << sub(ACC0, rf(RSV_NUM_QPUS), 8).pushz()
      << branch(endifLabel).allzc()        nop()'s added downstream
      << mov(ACC0, QPU_ID)
      << shr(ACC0, ACC0, 2)
      << band(rf(RSV_QPU_ID), ACC0, 15)
      << label(endifLabel)
      << add_uniform_pointer_offset(code);
  code.insert(insert_index + 1, ret);   Insert init code after the INIT_BEGIN marker
}
void add_init ( Instr :: List & code ) { using namespace V3DLib :: Target :: instr ; int insert_index = code . tag_index ( INIT_BEGIN ) ; assertq ( insert_index >= 0 , " " ) ; Instr :: List ret ; Label endifLabel = freshLabel ( ) ; ret << mov ( rf ( RSV_QPU_ID ) , 0 ) << sub ( ACC0 , rf ( RSV_NUM_QPUS ) , 8 ) . pushz ( ) << branch ( endifLabel ) . allzc ( ) << mov ( ACC0 , QPU_ID ) << shr ( ACC0 , ACC0 , 2 ) << band ( rf ( RSV_QPU_ID ) , ACC0 , 15 ) << label ( endifLabel ) << add_uniform_pointer_offset ( code ) ; code . insert ( insert_index + 1 , ret ) ; }
Add extra initialization code after uniform loads
Add extra initialization code after uniform loads
// Determine the qpu index for 'current' QPU // This is derived from the thread index.  // // Broadly: // // If (numQPUs() == 8)  // Alternative is 1, then qpu num initalized to 0 is ok //   me() = (thread_index() >> 2) & 0b1111; // End // // This works because the thread indexes are consecutive for multiple reserved // threads. It's probably also the reason why you can select only 1 or 8 (max) // threads, otherwise there would be gaps in the qpu id. // // not needed, already init'd to 0. Left here to counter future brainfarts // nop()'s added downstream // Insert init code after the INIT_BEGIN marker