     if (!t) {
       uint32_t minrdpos;
       s->q.prefetch_wrpos = pos;
-      minrdpos            = pos - min(pos, PREFETCH_SIZE - 32u);
-      blen                = (int)min(32u, end - pos);
+      minrdpos            = pos - min(pos, PREFETCH_SIZE - PREFETCH_SECTORS * 32u);
+      blen                = (int)min(PREFETCH_SECTORS * 32u, end - pos);
       for (;;) {
         uint32_t rdpos = s->q.prefetch_rdpos;
         if (rdpos >= minrdpos) break;

#define BATCH_SIZE (1 << LOG2_BATCH_SIZE)
#define LOG2_BATCH_COUNT 2
#define BATCH_COUNT (1 << LOG2_BATCH_COUNT)
#define LOG2_PREFETCH_SIZE 9
#define PREFETCH_SIZE (1 << LOG2_PREFETCH_SIZE)  // 512B, in 32B chunks

#define LOG_CYCLECOUNT 0


      }
    }
    blen = SHFL0(blen);
    if (blen == PREFETCH_SECTORS * 32u) {
      uint8_t vals[PREFETCH_SECTORS];
      for(int i = 0; i < PREFETCH_SECTORS; ++i)
        vals[i] = base[pos + t + i * 32u];
      for(int i = 0; i < PREFETCH_SECTORS; ++i)
        s->q.buf[(pos + t + i * 32u) & (PREFETCH_SIZE - 1)] = vals[i];
    } else {
#pragma unroll 1
      for(int elem = t; elem < blen; elem += 32) {
        s->q.buf[(pos + elem) & (PREFETCH_SIZE - 1)] = base[pos + elem];
      }
    }
    pos += blen;
  } while (blen > 0);
}
