From f96bd9673edd79e4304d8e60a4cb4a0119b12a28 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Tue, 16 Dec 2014 11:22:53 -0800 Subject: [PATCH] vc4: Add a helper for changing a field in an instruction. --- src/gallium/drivers/vc4/vc4_qpu.c | 20 +++++++++----------- src/gallium/drivers/vc4/vc4_qpu_defines.h | 3 +++ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/vc4/vc4_qpu.c b/src/gallium/drivers/vc4/vc4_qpu.c index 0c3353c61e4..0d9f5ec04ac 100644 --- a/src/gallium/drivers/vc4/vc4_qpu.c +++ b/src/gallium/drivers/vc4/vc4_qpu.c @@ -32,15 +32,13 @@ set_src_raddr(uint64_t inst, struct qpu_reg src) if (src.mux == QPU_MUX_A) { assert(QPU_GET_FIELD(inst, QPU_RADDR_A) == QPU_R_NOP || QPU_GET_FIELD(inst, QPU_RADDR_A) == src.addr); - return ((inst & ~QPU_RADDR_A_MASK) | - QPU_SET_FIELD(src.addr, QPU_RADDR_A)); + return QPU_UPDATE_FIELD(inst, src.addr, QPU_RADDR_A); } if (src.mux == QPU_MUX_B) { assert(QPU_GET_FIELD(inst, QPU_RADDR_B) == QPU_R_NOP || QPU_GET_FIELD(inst, QPU_RADDR_B) == src.addr); - return ((inst & ~QPU_RADDR_B_MASK) | - QPU_SET_FIELD(src.addr, QPU_RADDR_B)); + return QPU_UPDATE_FIELD(inst, src.addr, QPU_RADDR_B); } return inst; @@ -330,8 +328,8 @@ try_swap_ra_file(uint64_t *merge, uint64_t *a, uint64_t *b) /* Move raddr A to B in instruction a. */ *a = (*a & ~QPU_RADDR_A_MASK) | QPU_SET_FIELD(QPU_R_NOP, QPU_RADDR_A); *a = (*a & ~QPU_RADDR_B_MASK) | QPU_SET_FIELD(raddr_a_a, QPU_RADDR_B); - *merge = ((*merge & ~QPU_RADDR_A_MASK) | QPU_SET_FIELD(raddr_b_a, QPU_RADDR_A)); - *merge = ((*merge & ~QPU_RADDR_B_MASK) | QPU_SET_FIELD(raddr_a_a, QPU_RADDR_B)); + *merge = QPU_UPDATE_FIELD(*merge, raddr_b_a, QPU_RADDR_A); + *merge = QPU_UPDATE_FIELD(*merge, raddr_a_a, QPU_RADDR_B); swap_ra_file_mux_helper(merge, a, QPU_ADD_A_SHIFT); swap_ra_file_mux_helper(merge, a, QPU_ADD_B_SHIFT); swap_ra_file_mux_helper(merge, a, QPU_MUL_A_SHIFT); @@ -415,21 +413,21 @@ uint64_t qpu_set_sig(uint64_t inst, uint32_t sig) { assert(QPU_GET_FIELD(inst, QPU_SIG) == QPU_SIG_NONE); - return (inst & ~QPU_SIG_MASK) | QPU_SET_FIELD(sig, QPU_SIG); + return QPU_UPDATE_FIELD(inst, sig, QPU_SIG); } uint64_t -qpu_set_cond_add(uint64_t inst, uint32_t sig) +qpu_set_cond_add(uint64_t inst, uint32_t cond) { assert(QPU_GET_FIELD(inst, QPU_COND_ADD) == QPU_COND_ALWAYS); - return (inst & ~QPU_COND_ADD_MASK) | QPU_SET_FIELD(sig, QPU_COND_ADD); + return QPU_UPDATE_FIELD(inst, cond, QPU_COND_ADD); } uint64_t -qpu_set_cond_mul(uint64_t inst, uint32_t sig) +qpu_set_cond_mul(uint64_t inst, uint32_t cond) { assert(QPU_GET_FIELD(inst, QPU_COND_MUL) == QPU_COND_ALWAYS); - return (inst & ~QPU_COND_MUL_MASK) | QPU_SET_FIELD(sig, QPU_COND_MUL); + return QPU_UPDATE_FIELD(inst, cond, QPU_COND_MUL); } bool diff --git a/src/gallium/drivers/vc4/vc4_qpu_defines.h b/src/gallium/drivers/vc4/vc4_qpu_defines.h index b2f028f0194..a965b9635b1 100644 --- a/src/gallium/drivers/vc4/vc4_qpu_defines.h +++ b/src/gallium/drivers/vc4/vc4_qpu_defines.h @@ -217,6 +217,9 @@ enum qpu_unpack { #define QPU_GET_FIELD(word, field) ((uint32_t)(((word) & field ## _MASK) >> field ## _SHIFT)) +#define QPU_UPDATE_FIELD(inst, value, field) \ + (((inst) & ~(field ## _MASK)) | QPU_SET_FIELD(value, field)) + #define QPU_SIG_SHIFT 60 #define QPU_SIG_MASK QPU_MASK(63, 60) -- 2.30.2