uint16_t mir_from_bytemask(uint16_t bytemask, midgard_reg_mode mode);
uint16_t mir_to_bytemask(midgard_reg_mode mode, unsigned mask);
uint16_t mir_bytemask(midgard_instruction *ins);
-uint16_t mir_round_bytemask_down(uint16_t mask, midgard_reg_mode mode);
+uint16_t mir_round_bytemask_up(uint16_t mask, midgard_reg_mode mode);
void mir_set_bytemask(midgard_instruction *ins, uint16_t bytemask);
unsigned mir_upper_override(midgard_instruction *ins);
midgard_reg_mode mode = mir_typesize(ins);
unsigned oldmask = ins->mask;
- unsigned rounded = mir_round_bytemask_down(live[ins->dest], mode);
+ unsigned rounded = mir_round_bytemask_up(live[ins->dest], mode);
unsigned cmask = mir_from_bytemask(rounded, mode);
ins->mask &= cmask;
return value;
}
-/* Rounds down a bytemask to fit a given component count. Iterate each
- * component, and check if all bytes in the component are masked on */
+/* Rounds up a bytemask to fill a given component count. Iterate each
+ * component, and check if any bytes in the component are masked on */
uint16_t
-mir_round_bytemask_down(uint16_t mask, midgard_reg_mode mode)
+mir_round_bytemask_up(uint16_t mask, midgard_reg_mode mode)
{
unsigned bytes = mir_bytes_for_mode(mode);
unsigned maxmask = mask_of(bytes);
unsigned channels = 16 / bytes;
for (unsigned c = 0; c < channels; ++c) {
- /* Get bytes in component */
- unsigned submask = (mask >> (c * bytes)) & maxmask;
+ unsigned submask = maxmask << (c * bytes);
- if (submask != maxmask)
- mask &= ~(maxmask << (c * bytes));
+ if (mask & submask)
+ mask |= submask;
}
return mask;