Path: blob/21.2-virgl/src/gallium/drivers/etnaviv/etnaviv_asm.h
4570 views
/*1* Copyright (c) 2012-2015 Etnaviv Project2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sub license,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the11* next paragraph) shall be included in all copies or substantial portions12* of the Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER20* DEALINGS IN THE SOFTWARE.21*22* Authors:23* Wladimir J. van der Laan <[email protected]>24*/2526#ifndef H_ETNAVIV_ASM27#define H_ETNAVIV_ASM2829#include <stdint.h>30#include <stdbool.h>31#include "util/u_math.h"32#include "hw/isa.xml.h"3334/* Size of an instruction in 32-bit words */35#define ETNA_INST_SIZE (4)36/* Number of source operands per instruction */37#define ETNA_NUM_SRC (3)3839/* Broadcast swizzle to all four components */40#define INST_SWIZ_BROADCAST(x) \41(INST_SWIZ_X(x) | INST_SWIZ_Y(x) | INST_SWIZ_Z(x) | INST_SWIZ_W(x))42/* Identity (NOP) swizzle */43#define INST_SWIZ_IDENTITY \44(INST_SWIZ_X(0) | INST_SWIZ_Y(1) | INST_SWIZ_Z(2) | INST_SWIZ_W(3))45/* Fully specified swizzle */46#define INST_SWIZ(x,y,z,w) \47(INST_SWIZ_X(x) | INST_SWIZ_Y(y) | INST_SWIZ_Z(z) | INST_SWIZ_W(w))48#define SWIZZLE(c0,c1,c2,c3) \49INST_SWIZ(INST_SWIZ_COMP_##c0, \50INST_SWIZ_COMP_##c1, \51INST_SWIZ_COMP_##c2, \52INST_SWIZ_COMP_##c3)5354/*** operands ***/5556/* destination operand */57struct etna_inst_dst {58unsigned use:1; /* 0: not in use, 1: in use */59unsigned amode:3; /* INST_AMODE_* */60unsigned reg:7; /* register number 0..127 */61unsigned write_mask:4; /* INST_COMPS_* */62};6364/* texture operand */65struct etna_inst_tex {66unsigned id:5; /* sampler id */67unsigned amode:3; /* INST_AMODE_* */68unsigned swiz:8; /* INST_SWIZ */69};7071/* source operand */72struct etna_inst_src {73unsigned use:1; /* 0: not in use, 1: in use */74unsigned rgroup:3; /* INST_RGROUP_* */75union {76struct __attribute__((__packed__)) {77unsigned reg:9; /* register or uniform number 0..511 */78unsigned swiz:8; /* INST_SWIZ */79unsigned neg:1; /* negate (flip sign) if set */80unsigned abs:1; /* absolute (remove sign) if set */81unsigned amode:3; /* INST_AMODE_* */82};83struct __attribute__((__packed__)) {84unsigned imm_val : 20;85unsigned imm_type : 2;86};87};88};8990/*** instruction ***/91struct etna_inst {92uint8_t opcode; /* INST_OPCODE_* */93uint8_t type; /* INST_TYPE_* */94unsigned cond:5; /* INST_CONDITION_* */95unsigned sat:1; /* saturate result between 0..1 */96unsigned sel_bit0:1; /* select low half mediump */97unsigned sel_bit1:1; /* select high half mediump */98unsigned dst_full:1; /* write to highp register */99unsigned halti5:1; /* allow multiple different uniform sources */100struct etna_inst_dst dst; /* destination operand */101struct etna_inst_tex tex; /* texture operand */102struct etna_inst_src src[ETNA_NUM_SRC]; /* source operand */103unsigned imm; /* takes place of src[2] for BRANCH/CALL */104};105106/* Compose two swizzles (computes swz1.swz2) */107static inline uint32_t inst_swiz_compose(uint32_t swz1, uint32_t swz2)108{109return INST_SWIZ_X((swz1 >> (((swz2 >> 0)&3)*2))&3) |110INST_SWIZ_Y((swz1 >> (((swz2 >> 2)&3)*2))&3) |111INST_SWIZ_Z((swz1 >> (((swz2 >> 4)&3)*2))&3) |112INST_SWIZ_W((swz1 >> (((swz2 >> 6)&3)*2))&3);113};114115/* Compose two write_masks (computes wm1.wm2) */116static inline uint32_t inst_write_mask_compose(uint32_t wm1, uint32_t wm2)117{118unsigned wm = 0;119for (unsigned i = 0, j = 0; i < 4; i++) {120if (wm2 & (1 << i)) {121if (wm1 & (1 << j))122wm |= (1 << i);123j++;124}125}126return wm;127};128129/* Return whether the rgroup is one of the uniforms */130static inline int131etna_rgroup_is_uniform(unsigned rgroup)132{133return rgroup == INST_RGROUP_UNIFORM_0 ||134rgroup == INST_RGROUP_UNIFORM_1;135}136137static inline struct etna_inst_src138etna_immediate_src(unsigned type, uint32_t bits)139{140return (struct etna_inst_src) {141.use = 1,142.rgroup = INST_RGROUP_IMMEDIATE,143.imm_val = bits,144.imm_type = type145};146}147148static inline struct etna_inst_src149etna_immediate_float(float x)150{151uint32_t bits = fui(x);152assert((bits & 0xfff) == 0); /* 12 lsb cut off */153return etna_immediate_src(0, bits >> 12);154}155156static inline struct etna_inst_src157etna_immediate_int(int x)158{159assert(x >= -0x80000 && x < 0x80000); /* 20-bit signed int */160return etna_immediate_src(1, x);161}162163/**164* Build vivante instruction from structure with165* opcode, cond, sat, dst_use, dst_amode,166* dst_reg, dst_comps, tex_id, tex_amode, tex_swiz,167* src[0-2]_reg, use, swiz, neg, abs, amode, rgroup,168* imm169*170* Return 0 if successful, and a non-zero171* value otherwise.172*/173int174etna_assemble(uint32_t *out, const struct etna_inst *inst);175176/**177* Set field imm of already-assembled instruction.178* This is used for filling in jump destinations in a separate pass.179*/180static inline void181etna_assemble_set_imm(uint32_t *out, uint32_t imm)182{183out[3] |= VIV_ISA_WORD_3_SRC2_IMM(imm);184}185186#endif187188189