#ifndef IR3_H_
#define IR3_H_
#include <stdbool.h>
#include <stdint.h>
#include "compiler/shader_enums.h"
#include "util/bitscan.h"
#include "util/list.h"
#include "util/set.h"
#include "util/u_debug.h"
#include "instr-a3xx.h"
struct ir3_compiler;
struct ir3;
struct ir3_instruction;
struct ir3_block;
struct ir3_info {
void *data;
uint32_t size;
uint32_t constant_data_offset;
uint16_t sizedwords;
uint16_t instrs_count;
uint16_t nops_count;
uint16_t mov_count;
uint16_t cov_count;
int8_t max_reg;
int8_t max_half_reg;
int16_t max_const;
int8_t max_waves;
bool double_threadsize;
bool multi_dword_ldp_stp;
uint16_t ss, sy;
uint16_t sstall;
uint16_t last_baryf;
uint16_t instrs_per_cat[8];
};
struct ir3_merge_set {
uint16_t preferred_reg;
uint16_t size;
uint16_t alignment;
unsigned interval_start;
unsigned regs_count;
struct ir3_register **regs;
};
struct ir3_register {
enum {
IR3_REG_CONST = 0x001,
IR3_REG_IMMED = 0x002,
IR3_REG_HALF = 0x004,
IR3_REG_SHARED = 0x008,
IR3_REG_RELATIV = 0x010,
IR3_REG_R = 0x020,
IR3_REG_FNEG = 0x040,
IR3_REG_FABS = 0x080,
IR3_REG_SNEG = 0x100,
IR3_REG_SABS = 0x200,
IR3_REG_BNOT = 0x400,
IR3_REG_EI = 0x2000,
IR3_REG_SSA = 0x4000,
IR3_REG_ARRAY = 0x8000,
IR3_REG_KILL = 0x10000,
IR3_REG_FIRST_KILL = 0x20000,
IR3_REG_UNUSED = 0x40000,
} flags;
unsigned wrmask : 16;
unsigned size : 16;
uint16_t num;
uint16_t name;
union {
int32_t iim_val;
uint32_t uim_val;
float fim_val;
struct {
uint16_t id;
int16_t offset;
uint16_t base;
} array;
};
struct ir3_instruction *instr;
struct ir3_register *def;
struct ir3_register *tied;
unsigned merge_set_offset;
struct ir3_merge_set *merge_set;
unsigned interval_start, interval_end;
};
#define DECLARE_ARRAY(type, name) \
unsigned name##_count, name##_sz; \
type *name;
#define array_insert(ctx, arr, ...) \
do { \
if (arr##_count == arr##_sz) { \
arr##_sz = MAX2(2 * arr##_sz, 16); \
arr = reralloc_size(ctx, arr, arr##_sz * sizeof(arr[0])); \
} \
arr[arr##_count++] = __VA_ARGS__; \
} while (0)
struct ir3_instruction {
struct ir3_block *block;
opc_t opc;
enum {
IR3_INSTR_SY = 0x001,
IR3_INSTR_SS = 0x002,
IR3_INSTR_JP = 0x004,
IR3_INSTR_UL = 0x008,
IR3_INSTR_3D = 0x010,
IR3_INSTR_A = 0x020,
IR3_INSTR_O = 0x040,
IR3_INSTR_P = 0x080,
IR3_INSTR_S = 0x100,
IR3_INSTR_S2EN = 0x200,
IR3_INSTR_G = 0x400,
IR3_INSTR_SAT = 0x800,
IR3_INSTR_B = 0x1000,
IR3_INSTR_NONUNIF = 0x02000,
IR3_INSTR_A1EN = 0x04000,
IR3_INSTR_MARK = 0x08000,
IR3_INSTR_UNUSED = 0x10000,
} flags;
uint8_t repeat;
uint8_t nop;
#ifdef DEBUG
unsigned srcs_max, dsts_max;
#endif
unsigned srcs_count, dsts_count;
struct ir3_register **dsts;
struct ir3_register **srcs;
union {
struct {
char inv1, inv2;
char comp1, comp2;
int immed;
struct ir3_block *target;
const char *target_label;
brtype_t brtype;
unsigned idx;
} cat0;
struct {
type_t src_type, dst_type;
round_t round;
} cat1;
struct {
enum {
IR3_COND_LT = 0,
IR3_COND_LE = 1,
IR3_COND_GT = 2,
IR3_COND_GE = 3,
IR3_COND_EQ = 4,
IR3_COND_NE = 5,
} condition;
} cat2;
struct {
unsigned samp, tex;
unsigned tex_base : 3;
type_t type;
} cat5;
struct {
type_t type;
int dst_offset;
int iim_val : 3;
unsigned d : 3;
bool typed : 1;
unsigned base : 3;
} cat6;
struct {
unsigned w : 1;
unsigned r : 1;
unsigned l : 1;
unsigned g : 1;
} cat7;
struct {
int off;
} split;
struct {
unsigned *outidxs;
} end;
struct {
void *nphi;
} phi;
struct {
unsigned samp, tex;
unsigned input_offset;
unsigned samp_base : 3;
unsigned tex_base : 3;
} prefetch;
struct {
int inidx;
gl_system_value sysval;
} input;
};
uint16_t ip;
uint16_t name;
void *data;
struct set *uses;
int use_count;
struct ir3_register *address;
DECLARE_ARRAY(struct ir3_instruction *, deps);
enum {
IR3_BARRIER_EVERYTHING = 1 << 0,
IR3_BARRIER_SHARED_R = 1 << 1,
IR3_BARRIER_SHARED_W = 1 << 2,
IR3_BARRIER_IMAGE_R = 1 << 3,
IR3_BARRIER_IMAGE_W = 1 << 4,
IR3_BARRIER_BUFFER_R = 1 << 5,
IR3_BARRIER_BUFFER_W = 1 << 6,
IR3_BARRIER_ARRAY_R = 1 << 7,
IR3_BARRIER_ARRAY_W = 1 << 8,
IR3_BARRIER_PRIVATE_R = 1 << 9,
IR3_BARRIER_PRIVATE_W = 1 << 10,
} barrier_class,
barrier_conflict;
struct list_head node;
uint32_t serialno;
int line;
};
struct ir3 {
struct ir3_compiler *compiler;
gl_shader_stage type;
DECLARE_ARRAY(struct ir3_instruction *, inputs);
DECLARE_ARRAY(struct ir3_instruction *, baryfs);
DECLARE_ARRAY(struct ir3_instruction *, a0_users);
DECLARE_ARRAY(struct ir3_instruction *, a1_users);
DECLARE_ARRAY(struct ir3_instruction *, predicates);
DECLARE_ARRAY(struct ir3_instruction *, astc_srgb);
struct list_head block_list;
struct list_head array_list;
#ifdef DEBUG
unsigned block_count;
#endif
unsigned instr_count;
};
struct ir3_array {
struct list_head node;
unsigned length;
unsigned id;
struct nir_register *r;
struct ir3_register *last_write;
unsigned base;
unsigned reg;
uint16_t start_ip, end_ip;
bool half;
bool unused;
};
struct ir3_array *ir3_lookup_array(struct ir3 *ir, unsigned id);
enum ir3_branch_type {
IR3_BRANCH_COND,
IR3_BRANCH_ANY,
IR3_BRANCH_ALL,
IR3_BRANCH_GETONE,
};
struct ir3_block {
struct list_head node;
struct ir3 *shader;
const struct nir_block *nblock;
struct list_head instr_list;
enum ir3_branch_type brtype;
struct ir3_instruction *condition;
struct ir3_block *successors[2];
struct ir3_block *physical_successors[2];
DECLARE_ARRAY(struct ir3_block *, predecessors);
DECLARE_ARRAY(struct ir3_block *, physical_predecessors);
uint16_t start_ip, end_ip;
DECLARE_ARRAY(struct ir3_instruction *, keeps);
void *data;
uint32_t index;
struct ir3_block *imm_dom;
DECLARE_ARRAY(struct ir3_block *, dom_children);
uint32_t dom_pre_index;
uint32_t dom_post_index;
uint32_t loop_id;
#ifdef DEBUG
uint32_t serialno;
#endif
};
static inline uint32_t
block_id(struct ir3_block *block)
{
#ifdef DEBUG
return block->serialno;
#else
return (uint32_t)(unsigned long)block;
#endif
}
static inline struct ir3_block *
ir3_start_block(struct ir3 *ir)
{
return list_first_entry(&ir->block_list, struct ir3_block, node);
}
void ir3_block_add_predecessor(struct ir3_block *block, struct ir3_block *pred);
void ir3_block_add_physical_predecessor(struct ir3_block *block,
struct ir3_block *pred);
void ir3_block_remove_predecessor(struct ir3_block *block,
struct ir3_block *pred);
unsigned ir3_block_get_pred_index(struct ir3_block *block,
struct ir3_block *pred);
void ir3_calc_dominance(struct ir3 *ir);
bool ir3_block_dominates(struct ir3_block *a, struct ir3_block *b);
struct ir3_shader_variant;
struct ir3 *ir3_create(struct ir3_compiler *compiler,
struct ir3_shader_variant *v);
void ir3_destroy(struct ir3 *shader);
void ir3_collect_info(struct ir3_shader_variant *v);
void *ir3_alloc(struct ir3 *shader, int sz);
unsigned ir3_get_reg_dependent_max_waves(const struct ir3_compiler *compiler,
unsigned reg_count,
bool double_threadsize);
unsigned ir3_get_reg_independent_max_waves(struct ir3_shader_variant *v,
bool double_threadsize);
bool ir3_should_double_threadsize(struct ir3_shader_variant *v,
unsigned regs_count);
struct ir3_block *ir3_block_create(struct ir3 *shader);
struct ir3_instruction *ir3_instr_create(struct ir3_block *block, opc_t opc,
int ndst, int nsrc);
struct ir3_instruction *ir3_instr_clone(struct ir3_instruction *instr);
void ir3_instr_add_dep(struct ir3_instruction *instr,
struct ir3_instruction *dep);
const char *ir3_instr_name(struct ir3_instruction *instr);
struct ir3_register *ir3_src_create(struct ir3_instruction *instr, int num,
int flags);
struct ir3_register *ir3_dst_create(struct ir3_instruction *instr, int num,
int flags);
struct ir3_register *ir3_reg_clone(struct ir3 *shader,
struct ir3_register *reg);
static inline void
ir3_reg_tie(struct ir3_register *dst, struct ir3_register *src)
{
assert(!dst->tied && !src->tied);
dst->tied = src;
src->tied = dst;
}
void ir3_reg_set_last_array(struct ir3_instruction *instr,
struct ir3_register *reg,
struct ir3_register *last_write);
void ir3_instr_set_address(struct ir3_instruction *instr,
struct ir3_instruction *addr);
static inline bool
ir3_instr_check_mark(struct ir3_instruction *instr)
{
if (instr->flags & IR3_INSTR_MARK)
return true;
instr->flags |= IR3_INSTR_MARK;
return false;
}
void ir3_block_clear_mark(struct ir3_block *block);
void ir3_clear_mark(struct ir3 *shader);
unsigned ir3_count_instructions(struct ir3 *ir);
unsigned ir3_count_instructions_ra(struct ir3 *ir);
static inline void
ir3_instr_move_before(struct ir3_instruction *instr,
struct ir3_instruction *after)
{
list_delinit(&instr->node);
list_addtail(&instr->node, &after->node);
}
static inline void
ir3_instr_move_after(struct ir3_instruction *instr,
struct ir3_instruction *before)
{
list_delinit(&instr->node);
list_add(&instr->node, &before->node);
}
void ir3_find_ssa_uses(struct ir3 *ir, void *mem_ctx, bool falsedeps);
void ir3_set_dst_type(struct ir3_instruction *instr, bool half);
void ir3_fixup_src_type(struct ir3_instruction *instr);
int ir3_flut(struct ir3_register *src_reg);
bool ir3_valid_flags(struct ir3_instruction *instr, unsigned n, unsigned flags);
#include "util/set.h"
#define foreach_ssa_use(__use, __instr) \
for (struct ir3_instruction *__use = (void *)~0; __use && (__instr)->uses; \
__use = NULL) \
set_foreach ((__instr)->uses, __entry) \
if ((__use = (void *)__entry->key))
static inline uint32_t
reg_num(const struct ir3_register *reg)
{
return reg->num >> 2;
}
static inline uint32_t
reg_comp(const struct ir3_register *reg)
{
return reg->num & 0x3;
}
static inline bool
is_flow(struct ir3_instruction *instr)
{
return (opc_cat(instr->opc) == 0);
}
static inline bool
is_kill_or_demote(struct ir3_instruction *instr)
{
return instr->opc == OPC_KILL || instr->opc == OPC_DEMOTE;
}
static inline bool
is_nop(struct ir3_instruction *instr)
{
return instr->opc == OPC_NOP;
}
static inline bool
is_same_type_reg(struct ir3_register *dst, struct ir3_register *src)
{
unsigned dst_type = (dst->flags & IR3_REG_HALF);
unsigned src_type = (src->flags & IR3_REG_HALF);
if (dst_type != src_type ||
((dst->flags & IR3_REG_SHARED) && !(src->flags & IR3_REG_SHARED)))
return false;
else
return true;
}
static inline bool
is_same_type_mov(struct ir3_instruction *instr)
{
struct ir3_register *dst;
switch (instr->opc) {
case OPC_MOV:
if (instr->cat1.src_type != instr->cat1.dst_type)
return false;
if (!is_same_type_reg(instr->dsts[0], instr->srcs[0]))
return false;
break;
case OPC_ABSNEG_F:
case OPC_ABSNEG_S:
if (instr->flags & IR3_INSTR_SAT)
return false;
if (!is_same_type_reg(instr->dsts[0], instr->srcs[0]))
return false;
break;
default:
return false;
}
dst = instr->dsts[0];
if (dst->num == regid(REG_P0, 0))
return false;
if (reg_num(dst) == REG_A0)
return false;
if (dst->flags & (IR3_REG_RELATIV | IR3_REG_ARRAY))
return false;
return true;
}
static inline bool
is_const_mov(struct ir3_instruction *instr)
{
if (instr->opc != OPC_MOV)
return false;
if (!(instr->srcs[0]->flags & IR3_REG_CONST))
return false;
type_t src_type = instr->cat1.src_type;
type_t dst_type = instr->cat1.dst_type;
return (type_float(src_type) && type_float(dst_type)) ||
(type_uint(src_type) && type_uint(dst_type)) ||
(type_sint(src_type) && type_sint(dst_type));
}
static inline bool
is_alu(struct ir3_instruction *instr)
{
return (1 <= opc_cat(instr->opc)) && (opc_cat(instr->opc) <= 3);
}
static inline bool
is_sfu(struct ir3_instruction *instr)
{
return (opc_cat(instr->opc) == 4);
}
static inline bool
is_tex(struct ir3_instruction *instr)
{
return (opc_cat(instr->opc) == 5);
}
static inline bool
is_tex_or_prefetch(struct ir3_instruction *instr)
{
return is_tex(instr) || (instr->opc == OPC_META_TEX_PREFETCH);
}
static inline bool
is_mem(struct ir3_instruction *instr)
{
return (opc_cat(instr->opc) == 6);
}
static inline bool
is_barrier(struct ir3_instruction *instr)
{
return (opc_cat(instr->opc) == 7);
}
static inline bool
is_half(struct ir3_instruction *instr)
{
return !!(instr->dsts[0]->flags & IR3_REG_HALF);
}
static inline bool
is_shared(struct ir3_instruction *instr)
{
return !!(instr->dsts[0]->flags & IR3_REG_SHARED);
}
static inline bool
is_store(struct ir3_instruction *instr)
{
switch (instr->opc) {
case OPC_STG:
case OPC_STG_A:
case OPC_STGB:
case OPC_STIB:
case OPC_STP:
case OPC_STL:
case OPC_STLW:
case OPC_L2G:
case OPC_G2L:
return true;
default:
return false;
}
}
static inline bool
is_load(struct ir3_instruction *instr)
{
switch (instr->opc) {
case OPC_LDG:
case OPC_LDG_A:
case OPC_LDGB:
case OPC_LDIB:
case OPC_LDL:
case OPC_LDP:
case OPC_L2G:
case OPC_LDLW:
case OPC_LDC:
case OPC_LDLV:
return true;
default:
return false;
}
}
static inline bool
is_input(struct ir3_instruction *instr)
{
switch (instr->opc) {
case OPC_LDLV:
case OPC_BARY_F:
return true;
default:
return false;
}
}
static inline bool
is_bool(struct ir3_instruction *instr)
{
switch (instr->opc) {
case OPC_CMPS_F:
case OPC_CMPS_S:
case OPC_CMPS_U:
return true;
default:
return false;
}
}
static inline opc_t
cat3_half_opc(opc_t opc)
{
switch (opc) {
case OPC_MAD_F32:
return OPC_MAD_F16;
case OPC_SEL_B32:
return OPC_SEL_B16;
case OPC_SEL_S32:
return OPC_SEL_S16;
case OPC_SEL_F32:
return OPC_SEL_F16;
case OPC_SAD_S32:
return OPC_SAD_S16;
default:
return opc;
}
}
static inline opc_t
cat3_full_opc(opc_t opc)
{
switch (opc) {
case OPC_MAD_F16:
return OPC_MAD_F32;
case OPC_SEL_B16:
return OPC_SEL_B32;
case OPC_SEL_S16:
return OPC_SEL_S32;
case OPC_SEL_F16:
return OPC_SEL_F32;
case OPC_SAD_S16:
return OPC_SAD_S32;
default:
return opc;
}
}
static inline opc_t
cat4_half_opc(opc_t opc)
{
switch (opc) {
case OPC_RSQ:
return OPC_HRSQ;
case OPC_LOG2:
return OPC_HLOG2;
case OPC_EXP2:
return OPC_HEXP2;
default:
return opc;
}
}
static inline opc_t
cat4_full_opc(opc_t opc)
{
switch (opc) {
case OPC_HRSQ:
return OPC_RSQ;
case OPC_HLOG2:
return OPC_LOG2;
case OPC_HEXP2:
return OPC_EXP2;
default:
return opc;
}
}
static inline bool
is_meta(struct ir3_instruction *instr)
{
return (opc_cat(instr->opc) == -1);
}
static inline unsigned
reg_elems(const struct ir3_register *reg)
{
if (reg->flags & IR3_REG_ARRAY)
return reg->size;
else
return util_last_bit(reg->wrmask);
}
static inline unsigned
reg_elem_size(const struct ir3_register *reg)
{
return (reg->flags & IR3_REG_HALF) ? 1 : 2;
}
static inline unsigned
reg_size(const struct ir3_register *reg)
{
return reg_elems(reg) * reg_elem_size(reg);
}
static inline unsigned
dest_regs(struct ir3_instruction *instr)
{
if (instr->dsts_count == 0)
return 0;
debug_assert(instr->dsts_count == 1);
return util_last_bit(instr->dsts[0]->wrmask);
}
static inline bool
is_dest_gpr(struct ir3_register *dst)
{
if (dst->wrmask == 0)
return false;
if ((reg_num(dst) == REG_A0) || (dst->num == regid(REG_P0, 0)))
return false;
return true;
}
static inline bool
writes_gpr(struct ir3_instruction *instr)
{
if (dest_regs(instr) == 0)
return false;
return is_dest_gpr(instr->dsts[0]);
}
static inline bool
writes_addr0(struct ir3_instruction *instr)
{
if (instr->dsts_count > 0) {
struct ir3_register *dst = instr->dsts[0];
return dst->num == regid(REG_A0, 0);
}
return false;
}
static inline bool
writes_addr1(struct ir3_instruction *instr)
{
if (instr->dsts_count > 0) {
struct ir3_register *dst = instr->dsts[0];
return dst->num == regid(REG_A0, 1);
}
return false;
}
static inline bool
writes_pred(struct ir3_instruction *instr)
{
if (instr->dsts_count > 0) {
struct ir3_register *dst = instr->dsts[0];
return reg_num(dst) == REG_P0;
}
return false;
}
static inline bool
is_reg_special(const struct ir3_register *reg)
{
return (reg->flags & IR3_REG_SHARED) || (reg_num(reg) == REG_A0) ||
(reg_num(reg) == REG_P0);
}
static inline struct ir3_instruction *
ssa(struct ir3_register *reg)
{
if ((reg->flags & (IR3_REG_SSA | IR3_REG_ARRAY)) && reg->def)
return reg->def->instr;
return NULL;
}
static inline bool
conflicts(struct ir3_register *a, struct ir3_register *b)
{
return (a && b) && (a->def != b->def);
}
static inline bool
reg_gpr(struct ir3_register *r)
{
if (r->flags & (IR3_REG_CONST | IR3_REG_IMMED))
return false;
if ((reg_num(r) == REG_A0) || (reg_num(r) == REG_P0))
return false;
return true;
}
static inline type_t
half_type(type_t type)
{
switch (type) {
case TYPE_F32:
return TYPE_F16;
case TYPE_U32:
return TYPE_U16;
case TYPE_S32:
return TYPE_S16;
case TYPE_F16:
case TYPE_U16:
case TYPE_S16:
return type;
default:
assert(0);
return ~0;
}
}
static inline type_t
full_type(type_t type)
{
switch (type) {
case TYPE_F16:
return TYPE_F32;
case TYPE_U16:
return TYPE_U32;
case TYPE_S16:
return TYPE_S32;
case TYPE_F32:
case TYPE_U32:
case TYPE_S32:
return type;
default:
assert(0);
return ~0;
}
}
static inline bool
ir3_cat2_int(opc_t opc)
{
switch (opc) {
case OPC_ADD_U:
case OPC_ADD_S:
case OPC_SUB_U:
case OPC_SUB_S:
case OPC_CMPS_U:
case OPC_CMPS_S:
case OPC_MIN_U:
case OPC_MIN_S:
case OPC_MAX_U:
case OPC_MAX_S:
case OPC_CMPV_U:
case OPC_CMPV_S:
case OPC_MUL_U24:
case OPC_MUL_S24:
case OPC_MULL_U:
case OPC_CLZ_S:
case OPC_ABSNEG_S:
case OPC_AND_B:
case OPC_OR_B:
case OPC_NOT_B:
case OPC_XOR_B:
case OPC_BFREV_B:
case OPC_CLZ_B:
case OPC_SHL_B:
case OPC_SHR_B:
case OPC_ASHR_B:
case OPC_MGEN_B:
case OPC_GETBIT_B:
case OPC_CBITS_B:
case OPC_BARY_F:
return true;
default:
return false;
}
}
static inline unsigned
ir3_cat2_absneg(opc_t opc)
{
switch (opc) {
case OPC_ADD_F:
case OPC_MIN_F:
case OPC_MAX_F:
case OPC_MUL_F:
case OPC_SIGN_F:
case OPC_CMPS_F:
case OPC_ABSNEG_F:
case OPC_CMPV_F:
case OPC_FLOOR_F:
case OPC_CEIL_F:
case OPC_RNDNE_F:
case OPC_RNDAZ_F:
case OPC_TRUNC_F:
case OPC_BARY_F:
return IR3_REG_FABS | IR3_REG_FNEG;
case OPC_ADD_U:
case OPC_ADD_S:
case OPC_SUB_U:
case OPC_SUB_S:
case OPC_CMPS_U:
case OPC_CMPS_S:
case OPC_MIN_U:
case OPC_MIN_S:
case OPC_MAX_U:
case OPC_MAX_S:
case OPC_CMPV_U:
case OPC_CMPV_S:
case OPC_MUL_U24:
case OPC_MUL_S24:
case OPC_MULL_U:
case OPC_CLZ_S:
return 0;
case OPC_ABSNEG_S:
return IR3_REG_SABS | IR3_REG_SNEG;
case OPC_AND_B:
case OPC_OR_B:
case OPC_NOT_B:
case OPC_XOR_B:
case OPC_BFREV_B:
case OPC_CLZ_B:
case OPC_SHL_B:
case OPC_SHR_B:
case OPC_ASHR_B:
case OPC_MGEN_B:
case OPC_GETBIT_B:
case OPC_CBITS_B:
return IR3_REG_BNOT;
default:
return 0;
}
}
static inline unsigned
ir3_cat3_absneg(opc_t opc)
{
switch (opc) {
case OPC_MAD_F16:
case OPC_MAD_F32:
case OPC_SEL_F16:
case OPC_SEL_F32:
return IR3_REG_FNEG;
case OPC_MAD_U16:
case OPC_MADSH_U16:
case OPC_MAD_S16:
case OPC_MADSH_M16:
case OPC_MAD_U24:
case OPC_MAD_S24:
case OPC_SEL_S16:
case OPC_SEL_S32:
case OPC_SAD_S16:
case OPC_SAD_S32:
case OPC_SEL_B16:
case OPC_SEL_B32:
case OPC_SHLG_B16:
default:
return 0;
}
}
static inline type_t
ir3_output_conv_type(struct ir3_instruction *instr, bool *can_fold)
{
*can_fold = true;
switch (instr->opc) {
case OPC_ADD_F:
case OPC_MUL_F:
case OPC_BARY_F:
case OPC_MAD_F32:
case OPC_MAD_F16:
return TYPE_F32;
case OPC_ADD_U:
case OPC_SUB_U:
case OPC_MIN_U:
case OPC_MAX_U:
case OPC_AND_B:
case OPC_OR_B:
case OPC_NOT_B:
case OPC_XOR_B:
case OPC_MUL_U24:
case OPC_MULL_U:
case OPC_SHL_B:
case OPC_SHR_B:
case OPC_ASHR_B:
case OPC_MAD_U24:
case OPC_CMPS_F:
case OPC_CMPV_F:
case OPC_CMPS_U:
case OPC_CMPS_S:
return TYPE_U32;
case OPC_ADD_S:
case OPC_SUB_S:
case OPC_MIN_S:
case OPC_MAX_S:
case OPC_ABSNEG_S:
case OPC_MUL_S24:
case OPC_MAD_S24:
return TYPE_S32;
case OPC_MOV:
default:
*can_fold = false;
return TYPE_U32;
}
}
static inline type_t
ir3_output_conv_src_type(struct ir3_instruction *instr, type_t base_type)
{
switch (instr->opc) {
case OPC_CMPS_F:
case OPC_CMPV_F:
case OPC_CMPS_U:
case OPC_CMPS_S:
return (instr->dsts[0]->flags & IR3_REG_HALF) ? half_type(base_type)
: full_type(base_type);
case OPC_BARY_F:
return TYPE_F32;
default:
return (instr->dsts[1]->flags & IR3_REG_HALF) ? half_type(base_type)
: full_type(base_type);
}
}
static inline type_t
ir3_output_conv_dst_type(struct ir3_instruction *instr, type_t base_type)
{
return (instr->dsts[0]->flags & IR3_REG_HALF) ? half_type(base_type)
: full_type(base_type);
}
static inline opc_t
ir3_try_swap_signedness(opc_t opc, bool *can_swap)
{
switch (opc) {
#define PAIR(u, s) \
case OPC_##u: \
return OPC_##s; \
case OPC_##s: \
return OPC_##u;
PAIR(ADD_U, ADD_S)
PAIR(SUB_U, SUB_S)
PAIR(MUL_U24, MUL_S24)
default:
*can_swap = false;
return opc;
}
}
#define MASK(n) ((1 << (n)) - 1)
#define foreach_src_n(__srcreg, __n, __instr) \
if ((__instr)->srcs_count) \
for (struct ir3_register *__srcreg = (void *)~0; __srcreg; \
__srcreg = NULL) \
for (unsigned __cnt = (__instr)->srcs_count, __n = 0; __n < __cnt; \
__n++) \
if ((__srcreg = (__instr)->srcs[__n]))
#define foreach_src(__srcreg, __instr) foreach_src_n (__srcreg, __i, __instr)
#define foreach_dst_n(__dstreg, __n, __instr) \
if ((__instr)->dsts_count) \
for (struct ir3_register *__dstreg = (void *)~0; __dstreg; \
__dstreg = NULL) \
for (unsigned __cnt = (__instr)->dsts_count, __n = 0; __n < __cnt; \
__n++) \
if ((__dstreg = (__instr)->dsts[__n]))
#define foreach_dst(__dstreg, __instr) foreach_dst_n (__dstreg, __i, __instr)
static inline unsigned
__ssa_src_cnt(struct ir3_instruction *instr)
{
return instr->srcs_count + instr->deps_count;
}
static inline bool
__is_false_dep(struct ir3_instruction *instr, unsigned n)
{
if (n >= instr->srcs_count)
return true;
return false;
}
static inline struct ir3_instruction **
__ssa_srcp_n(struct ir3_instruction *instr, unsigned n)
{
if (__is_false_dep(instr, n))
return &instr->deps[n - instr->srcs_count];
if (ssa(instr->srcs[n]))
return &instr->srcs[n]->def->instr;
return NULL;
}
#define foreach_ssa_srcp_n(__srcp, __n, __instr) \
for (struct ir3_instruction **__srcp = (void *)~0; __srcp; __srcp = NULL) \
for (unsigned __cnt = __ssa_src_cnt(__instr), __n = 0; __n < __cnt; \
__n++) \
if ((__srcp = __ssa_srcp_n(__instr, __n)))
#define foreach_ssa_srcp(__srcp, __instr) \
foreach_ssa_srcp_n (__srcp, __i, __instr)
#define foreach_ssa_src_n(__srcinst, __n, __instr) \
for (struct ir3_instruction *__srcinst = (void *)~0; __srcinst; \
__srcinst = NULL) \
foreach_ssa_srcp_n (__srcp, __n, __instr) \
if ((__srcinst = *__srcp))
#define foreach_ssa_src(__srcinst, __instr) \
foreach_ssa_src_n (__srcinst, __i, __instr)
#define foreach_input_n(__ininstr, __cnt, __ir) \
for (struct ir3_instruction *__ininstr = (void *)~0; __ininstr; \
__ininstr = NULL) \
for (unsigned __cnt = 0; __cnt < (__ir)->inputs_count; __cnt++) \
if ((__ininstr = (__ir)->inputs[__cnt]))
#define foreach_input(__ininstr, __ir) foreach_input_n (__ininstr, __i, __ir)
#define foreach_instr(__instr, __list) \
list_for_each_entry (struct ir3_instruction, __instr, __list, node)
#define foreach_instr_rev(__instr, __list) \
list_for_each_entry_rev (struct ir3_instruction, __instr, __list, node)
#define foreach_instr_safe(__instr, __list) \
list_for_each_entry_safe (struct ir3_instruction, __instr, __list, node)
#define foreach_instr_from_safe(__instr, __start, __list) \
list_for_each_entry_from_safe(struct ir3_instruction, __instr, __start, \
__list, node)
#define foreach_block(__block, __list) \
list_for_each_entry (struct ir3_block, __block, __list, node)
#define foreach_block_safe(__block, __list) \
list_for_each_entry_safe (struct ir3_block, __block, __list, node)
#define foreach_block_rev(__block, __list) \
list_for_each_entry_rev (struct ir3_block, __block, __list, node)
#define foreach_array(__array, __list) \
list_for_each_entry (struct ir3_array, __array, __list, node)
#define foreach_array_safe(__array, __list) \
list_for_each_entry_safe (struct ir3_array, __array, __list, node)
#define IR3_PASS(ir, pass, ...) \
({ \
bool progress = pass(ir, ##__VA_ARGS__); \
if (progress) { \
ir3_debug_print(ir, "AFTER: " #pass); \
ir3_validate(ir); \
} \
progress; \
})
void ir3_validate(struct ir3 *ir);
void ir3_print(struct ir3 *ir);
void ir3_print_instr(struct ir3_instruction *instr);
int ir3_delayslots(struct ir3_instruction *assigner,
struct ir3_instruction *consumer, unsigned n, bool soft);
unsigned ir3_delay_calc_prera(struct ir3_block *block,
struct ir3_instruction *instr);
unsigned ir3_delay_calc_postra(struct ir3_block *block,
struct ir3_instruction *instr, bool soft,
bool mergedregs);
unsigned ir3_delay_calc_exact(struct ir3_block *block,
struct ir3_instruction *instr, bool mergedregs);
void ir3_remove_nops(struct ir3 *ir);
struct ir3_shader_variant;
bool ir3_dce(struct ir3 *ir, struct ir3_shader_variant *so);
bool ir3_cf(struct ir3 *ir);
bool ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so);
bool ir3_cp_postsched(struct ir3 *ir);
bool ir3_cse(struct ir3 *ir);
bool ir3_array_to_ssa(struct ir3 *ir);
bool ir3_sched_add_deps(struct ir3 *ir);
int ir3_sched(struct ir3 *ir);
struct ir3_context;
bool ir3_postsched(struct ir3 *ir, struct ir3_shader_variant *v);
int ir3_ra(struct ir3_shader_variant *v);
bool ir3_lower_subgroups(struct ir3 *ir);
bool ir3_legalize(struct ir3 *ir, struct ir3_shader_variant *so, int *max_bary);
static inline bool
ir3_has_latency_to_hide(struct ir3 *ir)
{
if (ir->type != MESA_SHADER_FRAGMENT)
return true;
foreach_block (block, &ir->block_list) {
foreach_instr (instr, &block->instr_list) {
if (is_tex_or_prefetch(instr))
return true;
if (is_load(instr)) {
switch (instr->opc) {
case OPC_LDLV:
case OPC_LDL:
case OPC_LDLW:
break;
default:
return true;
}
}
}
}
return false;
}
static inline struct ir3_register *
__ssa_src(struct ir3_instruction *instr, struct ir3_instruction *src,
unsigned flags)
{
struct ir3_register *reg;
if (src->dsts[0]->flags & IR3_REG_HALF)
flags |= IR3_REG_HALF;
reg = ir3_src_create(instr, INVALID_REG, IR3_REG_SSA | flags);
reg->def = src->dsts[0];
reg->wrmask = src->dsts[0]->wrmask;
return reg;
}
static inline struct ir3_register *
__ssa_dst(struct ir3_instruction *instr)
{
struct ir3_register *reg = ir3_dst_create(instr, INVALID_REG, IR3_REG_SSA);
reg->instr = instr;
return reg;
}
static inline struct ir3_instruction *
create_immed_typed(struct ir3_block *block, uint32_t val, type_t type)
{
struct ir3_instruction *mov;
unsigned flags = (type_size(type) < 32) ? IR3_REG_HALF : 0;
mov = ir3_instr_create(block, OPC_MOV, 1, 1);
mov->cat1.src_type = type;
mov->cat1.dst_type = type;
__ssa_dst(mov)->flags |= flags;
ir3_src_create(mov, 0, IR3_REG_IMMED | flags)->uim_val = val;
return mov;
}
static inline struct ir3_instruction *
create_immed(struct ir3_block *block, uint32_t val)
{
return create_immed_typed(block, val, TYPE_U32);
}
static inline struct ir3_instruction *
create_uniform_typed(struct ir3_block *block, unsigned n, type_t type)
{
struct ir3_instruction *mov;
unsigned flags = (type_size(type) < 32) ? IR3_REG_HALF : 0;
mov = ir3_instr_create(block, OPC_MOV, 1, 1);
mov->cat1.src_type = type;
mov->cat1.dst_type = type;
__ssa_dst(mov)->flags |= flags;
ir3_src_create(mov, n, IR3_REG_CONST | flags);
return mov;
}
static inline struct ir3_instruction *
create_uniform(struct ir3_block *block, unsigned n)
{
return create_uniform_typed(block, n, TYPE_F32);
}
static inline struct ir3_instruction *
create_uniform_indirect(struct ir3_block *block, int n, type_t type,
struct ir3_instruction *address)
{
struct ir3_instruction *mov;
mov = ir3_instr_create(block, OPC_MOV, 1, 1);
mov->cat1.src_type = type;
mov->cat1.dst_type = type;
__ssa_dst(mov);
ir3_src_create(mov, 0, IR3_REG_CONST | IR3_REG_RELATIV)->array.offset = n;
ir3_instr_set_address(mov, address);
return mov;
}
static inline struct ir3_instruction *
ir3_MOV(struct ir3_block *block, struct ir3_instruction *src, type_t type)
{
struct ir3_instruction *instr = ir3_instr_create(block, OPC_MOV, 1, 1);
unsigned flags = (type_size(type) < 32) ? IR3_REG_HALF : 0;
__ssa_dst(instr)->flags |= flags;
if (src->dsts[0]->flags & IR3_REG_ARRAY) {
struct ir3_register *src_reg = __ssa_src(instr, src, IR3_REG_ARRAY);
src_reg->array = src->dsts[0]->array;
} else {
__ssa_src(instr, src, src->dsts[0]->flags & IR3_REG_SHARED);
}
debug_assert(!(src->dsts[0]->flags & IR3_REG_RELATIV));
instr->cat1.src_type = type;
instr->cat1.dst_type = type;
return instr;
}
static inline struct ir3_instruction *
ir3_COV(struct ir3_block *block, struct ir3_instruction *src, type_t src_type,
type_t dst_type)
{
struct ir3_instruction *instr = ir3_instr_create(block, OPC_MOV, 1, 1);
unsigned dst_flags = (type_size(dst_type) < 32) ? IR3_REG_HALF : 0;
unsigned src_flags = (type_size(src_type) < 32) ? IR3_REG_HALF : 0;
debug_assert((src->dsts[0]->flags & IR3_REG_HALF) == src_flags);
__ssa_dst(instr)->flags |= dst_flags;
__ssa_src(instr, src, 0);
instr->cat1.src_type = src_type;
instr->cat1.dst_type = dst_type;
debug_assert(!(src->dsts[0]->flags & IR3_REG_ARRAY));
return instr;
}
static inline struct ir3_instruction *
ir3_MOVMSK(struct ir3_block *block, unsigned components)
{
struct ir3_instruction *instr = ir3_instr_create(block, OPC_MOVMSK, 1, 0);
struct ir3_register *dst = __ssa_dst(instr);
dst->flags |= IR3_REG_SHARED;
dst->wrmask = (1 << components) - 1;
instr->repeat = components - 1;
return instr;
}
static inline struct ir3_instruction *
ir3_BALLOT_MACRO(struct ir3_block *block, struct ir3_instruction *src,
unsigned components)
{
struct ir3_instruction *instr =
ir3_instr_create(block, OPC_BALLOT_MACRO, 1, 1);
struct ir3_register *dst = __ssa_dst(instr);
dst->flags |= IR3_REG_SHARED;
dst->wrmask = (1 << components) - 1;
__ssa_src(instr, src, 0);
return instr;
}
static inline struct ir3_instruction *
ir3_NOP(struct ir3_block *block)
{
return ir3_instr_create(block, OPC_NOP, 0, 0);
}
#define IR3_INSTR_0 0
#define __INSTR0(flag, name, opc) \
static inline struct ir3_instruction *ir3_##name(struct ir3_block *block) \
{ \
struct ir3_instruction *instr = ir3_instr_create(block, opc, 1, 0); \
instr->flags |= flag; \
return instr; \
}
#define INSTR0F(f, name) __INSTR0(IR3_INSTR_##f, name##_##f, OPC_##name)
#define INSTR0(name) __INSTR0(0, name, OPC_##name)
#define __INSTR1(flag, dst_count, name, opc) \
static inline struct ir3_instruction *ir3_##name( \
struct ir3_block *block, struct ir3_instruction *a, unsigned aflags) \
{ \
struct ir3_instruction *instr = \
ir3_instr_create(block, opc, dst_count, 1); \
for (unsigned i = 0; i < dst_count; i++) \
__ssa_dst(instr); \
__ssa_src(instr, a, aflags); \
instr->flags |= flag; \
return instr; \
}
#define INSTR1F(f, name) __INSTR1(IR3_INSTR_##f, 1, name##_##f, OPC_##name)
#define INSTR1(name) __INSTR1(0, 1, name, OPC_##name)
#define INSTR1NODST(name) __INSTR1(0, 0, name, OPC_##name)
#define __INSTR2(flag, name, opc) \
static inline struct ir3_instruction *ir3_##name( \
struct ir3_block *block, struct ir3_instruction *a, unsigned aflags, \
struct ir3_instruction *b, unsigned bflags) \
{ \
struct ir3_instruction *instr = ir3_instr_create(block, opc, 1, 2); \
__ssa_dst(instr); \
__ssa_src(instr, a, aflags); \
__ssa_src(instr, b, bflags); \
instr->flags |= flag; \
return instr; \
}
#define INSTR2F(f, name) __INSTR2(IR3_INSTR_##f, name##_##f, OPC_##name)
#define INSTR2(name) __INSTR2(0, name, OPC_##name)
#define __INSTR3(flag, dst_count, name, opc) \
static inline struct ir3_instruction *ir3_##name( \
struct ir3_block *block, struct ir3_instruction *a, unsigned aflags, \
struct ir3_instruction *b, unsigned bflags, struct ir3_instruction *c, \
unsigned cflags) \
{ \
struct ir3_instruction *instr = \
ir3_instr_create(block, opc, dst_count, 3); \
for (unsigned i = 0; i < dst_count; i++) \
__ssa_dst(instr); \
__ssa_src(instr, a, aflags); \
__ssa_src(instr, b, bflags); \
__ssa_src(instr, c, cflags); \
instr->flags |= flag; \
return instr; \
}
#define INSTR3F(f, name) __INSTR3(IR3_INSTR_##f, 1, name##_##f, OPC_##name)
#define INSTR3(name) __INSTR3(0, 1, name, OPC_##name)
#define INSTR3NODST(name) __INSTR3(0, 0, name, OPC_##name)
#define __INSTR4(flag, dst_count, name, opc) \
static inline struct ir3_instruction *ir3_##name( \
struct ir3_block *block, struct ir3_instruction *a, unsigned aflags, \
struct ir3_instruction *b, unsigned bflags, struct ir3_instruction *c, \
unsigned cflags, struct ir3_instruction *d, unsigned dflags) \
{ \
struct ir3_instruction *instr = \
ir3_instr_create(block, opc, dst_count, 4); \
for (unsigned i = 0; i < dst_count; i++) \
__ssa_dst(instr); \
__ssa_src(instr, a, aflags); \
__ssa_src(instr, b, bflags); \
__ssa_src(instr, c, cflags); \
__ssa_src(instr, d, dflags); \
instr->flags |= flag; \
return instr; \
}
#define INSTR4F(f, name) __INSTR4(IR3_INSTR_##f, 1, name##_##f, OPC_##name)
#define INSTR4(name) __INSTR4(0, 1, name, OPC_##name)
#define INSTR4NODST(name) __INSTR4(0, 0, name, OPC_##name)
#define __INSTR5(flag, name, opc) \
static inline struct ir3_instruction *ir3_##name( \
struct ir3_block *block, struct ir3_instruction *a, unsigned aflags, \
struct ir3_instruction *b, unsigned bflags, struct ir3_instruction *c, \
unsigned cflags, struct ir3_instruction *d, unsigned dflags, \
struct ir3_instruction *e, unsigned eflags) \
{ \
struct ir3_instruction *instr = ir3_instr_create(block, opc, 1, 5); \
__ssa_dst(instr); \
__ssa_src(instr, a, aflags); \
__ssa_src(instr, b, bflags); \
__ssa_src(instr, c, cflags); \
__ssa_src(instr, d, dflags); \
__ssa_src(instr, e, eflags); \
instr->flags |= flag; \
return instr; \
}
#define INSTR5F(f, name) __INSTR5(IR3_INSTR_##f, name##_##f, OPC_##name)
#define INSTR5(name) __INSTR5(0, name, OPC_##name)
#define __INSTR6(flag, dst_count, name, opc) \
static inline struct ir3_instruction *ir3_##name( \
struct ir3_block *block, struct ir3_instruction *a, unsigned aflags, \
struct ir3_instruction *b, unsigned bflags, struct ir3_instruction *c, \
unsigned cflags, struct ir3_instruction *d, unsigned dflags, \
struct ir3_instruction *e, unsigned eflags, struct ir3_instruction *f, \
unsigned fflags) \
{ \
struct ir3_instruction *instr = ir3_instr_create(block, opc, 1, 6); \
for (unsigned i = 0; i < dst_count; i++) \
__ssa_dst(instr); \
__ssa_src(instr, a, aflags); \
__ssa_src(instr, b, bflags); \
__ssa_src(instr, c, cflags); \
__ssa_src(instr, d, dflags); \
__ssa_src(instr, e, eflags); \
__ssa_src(instr, f, fflags); \
instr->flags |= flag; \
return instr; \
}
#define INSTR6F(f, name) __INSTR6(IR3_INSTR_##f, 1, name##_##f, OPC_##name)
#define INSTR6(name) __INSTR6(0, 1, name, OPC_##name)
#define INSTR6NODST(name) __INSTR6(0, 0, name, OPC_##name)
INSTR1NODST(B)
INSTR0(JUMP)
INSTR1NODST(KILL)
INSTR1NODST(DEMOTE)
INSTR0(END)
INSTR0(CHSH)
INSTR0(CHMASK)
INSTR1NODST(PREDT)
INSTR0(PREDF)
INSTR0(PREDE)
INSTR0(GETONE)
INSTR1(ANY_MACRO)
INSTR1(ALL_MACRO)
INSTR1(READ_FIRST_MACRO)
INSTR2(READ_COND_MACRO)
static inline struct ir3_instruction *
ir3_ELECT_MACRO(struct ir3_block *block)
{
struct ir3_instruction *instr =
ir3_instr_create(block, OPC_ELECT_MACRO, 1, 0);
__ssa_dst(instr);
return instr;
}
INSTR2(ADD_F)
INSTR2(MIN_F)
INSTR2(MAX_F)
INSTR2(MUL_F)
INSTR1(SIGN_F)
INSTR2(CMPS_F)
INSTR1(ABSNEG_F)
INSTR2(CMPV_F)
INSTR1(FLOOR_F)
INSTR1(CEIL_F)
INSTR1(RNDNE_F)
INSTR1(RNDAZ_F)
INSTR1(TRUNC_F)
INSTR2(ADD_U)
INSTR2(ADD_S)
INSTR2(SUB_U)
INSTR2(SUB_S)
INSTR2(CMPS_U)
INSTR2(CMPS_S)
INSTR2(MIN_U)
INSTR2(MIN_S)
INSTR2(MAX_U)
INSTR2(MAX_S)
INSTR1(ABSNEG_S)
INSTR2(AND_B)
INSTR2(OR_B)
INSTR1(NOT_B)
INSTR2(XOR_B)
INSTR2(CMPV_U)
INSTR2(CMPV_S)
INSTR2(MUL_U24)
INSTR2(MUL_S24)
INSTR2(MULL_U)
INSTR1(BFREV_B)
INSTR1(CLZ_S)
INSTR1(CLZ_B)
INSTR2(SHL_B)
INSTR2(SHR_B)
INSTR2(ASHR_B)
INSTR2(BARY_F)
INSTR2(MGEN_B)
INSTR2(GETBIT_B)
INSTR1(SETRM)
INSTR1(CBITS_B)
INSTR2(SHB)
INSTR2(MSAD)
INSTR3(MAD_U16)
INSTR3(MADSH_U16)
INSTR3(MAD_S16)
INSTR3(MADSH_M16)
INSTR3(MAD_U24)
INSTR3(MAD_S24)
INSTR3(MAD_F16)
INSTR3(MAD_F32)
INSTR3(SEL_B16)
INSTR3(SEL_B32)
INSTR3(SEL_S16)
INSTR3(SEL_S32)
INSTR3(SEL_F16)
INSTR3(SEL_F32)
INSTR3(SAD_S16)
INSTR3(SAD_S32)
INSTR1(RCP)
INSTR1(RSQ)
INSTR1(HRSQ)
INSTR1(LOG2)
INSTR1(HLOG2)
INSTR1(EXP2)
INSTR1(HEXP2)
INSTR1(SIN)
INSTR1(COS)
INSTR1(SQRT)
INSTR1(DSX)
INSTR1(DSXPP_MACRO)
INSTR1(DSY)
INSTR1(DSYPP_MACRO)
INSTR1F(3D, DSX)
INSTR1F(3D, DSY)
INSTR1(RGETPOS)
static inline struct ir3_instruction *
ir3_SAM(struct ir3_block *block, opc_t opc, type_t type, unsigned wrmask,
unsigned flags, struct ir3_instruction *samp_tex,
struct ir3_instruction *src0, struct ir3_instruction *src1)
{
struct ir3_instruction *sam;
unsigned nreg = 0;
if (flags & IR3_INSTR_S2EN) {
nreg++;
}
if (src0) {
nreg++;
}
if (src1) {
nreg++;
}
sam = ir3_instr_create(block, opc, 1, nreg);
sam->flags |= flags;
__ssa_dst(sam)->wrmask = wrmask;
if (flags & IR3_INSTR_S2EN) {
__ssa_src(sam, samp_tex, (flags & IR3_INSTR_B) ? 0 : IR3_REG_HALF);
}
if (src0) {
__ssa_src(sam, src0, 0);
}
if (src1) {
__ssa_src(sam, src1, 0);
}
sam->cat5.type = type;
return sam;
}
INSTR2(LDLV)
INSTR3(LDG)
INSTR3(LDL)
INSTR3(LDLW)
INSTR3(LDP)
INSTR4NODST(STG)
INSTR3NODST(STL)
INSTR3NODST(STLW)
INSTR3NODST(STP)
INSTR1(RESINFO)
INSTR1(RESFMT)
INSTR2(ATOMIC_ADD)
INSTR2(ATOMIC_SUB)
INSTR2(ATOMIC_XCHG)
INSTR2(ATOMIC_INC)
INSTR2(ATOMIC_DEC)
INSTR2(ATOMIC_CMPXCHG)
INSTR2(ATOMIC_MIN)
INSTR2(ATOMIC_MAX)
INSTR2(ATOMIC_AND)
INSTR2(ATOMIC_OR)
INSTR2(ATOMIC_XOR)
INSTR2(LDC)
#if GPU >= 600
INSTR3NODST(STIB);
INSTR2(LDIB);
INSTR5(LDG_A);
INSTR6NODST(STG_A);
INSTR3F(G, ATOMIC_ADD)
INSTR3F(G, ATOMIC_SUB)
INSTR3F(G, ATOMIC_XCHG)
INSTR3F(G, ATOMIC_INC)
INSTR3F(G, ATOMIC_DEC)
INSTR3F(G, ATOMIC_CMPXCHG)
INSTR3F(G, ATOMIC_MIN)
INSTR3F(G, ATOMIC_MAX)
INSTR3F(G, ATOMIC_AND)
INSTR3F(G, ATOMIC_OR)
INSTR3F(G, ATOMIC_XOR)
#elif GPU >= 400
INSTR3(LDGB)
INSTR4NODST(STGB)
INSTR4NODST(STIB)
INSTR4F(G, ATOMIC_ADD)
INSTR4F(G, ATOMIC_SUB)
INSTR4F(G, ATOMIC_XCHG)
INSTR4F(G, ATOMIC_INC)
INSTR4F(G, ATOMIC_DEC)
INSTR4F(G, ATOMIC_CMPXCHG)
INSTR4F(G, ATOMIC_MIN)
INSTR4F(G, ATOMIC_MAX)
INSTR4F(G, ATOMIC_AND)
INSTR4F(G, ATOMIC_OR)
INSTR4F(G, ATOMIC_XOR)
#endif
INSTR0(BAR)
INSTR0(FENCE)
#include "regmask.h"
static inline void
regmask_set(regmask_t *regmask, struct ir3_register *reg)
{
bool half = reg->flags & IR3_REG_HALF;
if (reg->flags & IR3_REG_RELATIV) {
for (unsigned i = 0; i < reg->size; i++)
__regmask_set(regmask, half, reg->array.base + i);
} else {
for (unsigned mask = reg->wrmask, n = reg->num; mask; mask >>= 1, n++)
if (mask & 1)
__regmask_set(regmask, half, n);
}
}
static inline bool
regmask_get(regmask_t *regmask, struct ir3_register *reg)
{
bool half = reg->flags & IR3_REG_HALF;
if (reg->flags & IR3_REG_RELATIV) {
for (unsigned i = 0; i < reg->size; i++)
if (__regmask_get(regmask, half, reg->array.base + i))
return true;
} else {
for (unsigned mask = reg->wrmask, n = reg->num; mask; mask >>= 1, n++)
if (mask & 1)
if (__regmask_get(regmask, half, n))
return true;
}
return false;
}
#endif