int immd_nr;
struct nv50_reg **addr;
int addr_nr;
+ uint8_t addr_alloc; /* set bit indicates used for TGSI_FILE_ADDRESS */
struct nv50_reg *temp_temp[16];
unsigned temp_temp_nr;
/* remove records of temporary address register values */
for (i = 0; i < NV50_SU_MAX_ADDR; ++i)
- if (pc->r_addr[i].index < 0)
- pc->r_addr[i].rhw = -1;
+ pc->r_addr[i].rhw = -1;
}
static void
static struct nv50_reg *
alloc_addr(struct nv50_pc *pc, struct nv50_reg *ref)
{
- int i;
struct nv50_reg *a_tgsi = NULL, *a = NULL;
+ int i;
+ uint8_t avail = ~pc->addr_alloc;
if (!ref) {
- /* allocate for TGSI address reg */
- for (i = 0; i < NV50_SU_MAX_ADDR; ++i) {
- if (pc->r_addr[i].index >= 0)
- continue;
- if (pc->r_addr[i].rhw >= 0 &&
- pc->r_addr[i].acc == pc->insn_cur)
- continue;
+ /* allocate for TGSI_FILE_ADDRESS */
+ while (avail) {
+ i = ffs(avail) - 1;
- pc->r_addr[i].rhw = -1;
- pc->r_addr[i].index = i;
- return &pc->r_addr[i];
+ if (pc->r_addr[i].rhw < 0 ||
+ pc->r_addr[i].acc != pc->insn_cur) {
+ pc->addr_alloc |= (1 << i);
+
+ pc->r_addr[i].rhw = -1;
+ pc->r_addr[i].index = i;
+ return &pc->r_addr[i];
+ }
+ avail &= ~(1 << i);
}
assert(0);
return NULL;
/* Allocate and set an address reg so we can access 'ref'.
*
- * If and r_addr has index < 0, it is not reserved for TGSI,
- * and index will be the negative of the TGSI addr index the
- * value in rhw is relative to, or -256 if rhw is an offset
- * from 0. If rhw < 0, the reg has not been initialized.
+ * If and r_addr->index will be -1 or the hw index the value
+ * value in rhw is relative to. If rhw < 0, the reg has not
+ * been initialized or is in use for TGSI_FILE_ADDRESS.
*/
- for (i = NV50_SU_MAX_ADDR - 1; i >= 0; --i) {
- if (pc->r_addr[i].index >= 0) /* occupied for TGSI */
- continue;
- if (pc->r_addr[i].rhw < 0) { /* unused */
+ while (avail) { /* only consider regs that are not TGSI */
+ i = ffs(avail) - 1;
+ avail &= ~(1 << i);
+
+ if ((!a || a->rhw >= 0) && pc->r_addr[i].rhw < 0) {
+ /* prefer an usused reg with low hw index */
a = &pc->r_addr[i];
continue;
}
if (ref->hw - pc->r_addr[i].rhw >= 128)
continue;
- if ((ref->acc >= 0 && pc->r_addr[i].index == -256) ||
- (ref->acc < 0 && -pc->r_addr[i].index == ref->index)) {
+ if ((ref->acc >= 0 && pc->r_addr[i].index < 0) ||
+ (ref->acc < 0 && pc->r_addr[i].index == ref->index)) {
pc->r_addr[i].acc = pc->insn_cur;
return &pc->r_addr[i];
}
a->rhw = ref->hw & ~0x7f;
a->acc = pc->insn_cur;
- a->index = a_tgsi ? -ref->index : -256;
+ a->index = a_tgsi ? ref->index : -1;
return a;
}