xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/etnaviv/etnaviv_asm.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (c) 2012-2015 Etnaviv Project
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sub license,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the
12  * next paragraph) shall be included in all copies or substantial portions
13  * of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Wladimir J. van der Laan <[email protected]>
25  */
26 
27 #ifndef H_ETNAVIV_ASM
28 #define H_ETNAVIV_ASM
29 
30 #include <stdint.h>
31 #include <stdbool.h>
32 #include "util/u_math.h"
33 
34 #include <etnaviv/isa/asm.h>
35 
36 /* Size of an instruction in 32-bit words */
37 #define ETNA_INST_SIZE (4)
38 
39 /* Compose two swizzles (computes swz1.swz2) */
inst_swiz_compose(uint32_t swz1,uint32_t swz2)40 static inline uint32_t inst_swiz_compose(uint32_t swz1, uint32_t swz2)
41 {
42    return SWIZ_X((swz1 >> (((swz2 >> 0)&3)*2))&3) |
43           SWIZ_Y((swz1 >> (((swz2 >> 2)&3)*2))&3) |
44           SWIZ_Z((swz1 >> (((swz2 >> 4)&3)*2))&3) |
45           SWIZ_W((swz1 >> (((swz2 >> 6)&3)*2))&3);
46 };
47 
48 /* Compose two write_masks (computes wm1.wm2) */
inst_write_mask_compose(uint32_t wm1,uint32_t wm2)49 static inline uint32_t inst_write_mask_compose(uint32_t wm1, uint32_t wm2)
50 {
51    unsigned wm = 0;
52    for (unsigned i = 0, j = 0; i < 4; i++) {
53       if (wm2 & (1 << i)) {
54          if (wm1 & (1 << j))
55             wm |= (1 << i);
56          j++;
57       }
58    }
59    return wm;
60 };
61 
62 /* Return whether the rgroup is one of the uniforms */
63 static inline int
etna_rgroup_is_uniform(enum isa_reg_group rgroup)64 etna_rgroup_is_uniform(enum isa_reg_group rgroup)
65 {
66    return rgroup == ISA_REG_GROUP_UNIFORM_0 ||
67           rgroup == ISA_REG_GROUP_UNIFORM_1;
68 }
69 
70 static inline struct etna_inst_src
etna_immediate_src(unsigned type,uint32_t bits)71 etna_immediate_src(unsigned type, uint32_t bits)
72 {
73    return (struct etna_inst_src) {
74       .use = 1,
75       .rgroup = ISA_REG_GROUP_IMMED,
76       .imm_val = bits,
77       .imm_type = type
78    };
79 }
80 
81 static inline struct etna_inst_src
etna_immediate_float(float x)82 etna_immediate_float(float x)
83 {
84 	uint32_t bits = fui(x);
85 	assert((bits & 0xfff) == 0); /* 12 lsb cut off */
86 	return etna_immediate_src(0, bits >> 12);
87 }
88 
89 static inline struct etna_inst_src
etna_immediate_int(int x)90 etna_immediate_int(int x)
91 {
92     assert(x >= -0x80000 && x < 0x80000); /* 20-bit signed int */
93 	return etna_immediate_src(1, x);
94 }
95 
96 /**
97  * Build vivante instruction from structure with
98  *  opcode, cond, sat, dst_use, dst_amode,
99  *  dst_reg, dst_comps, tex_id, tex_amode, tex_swiz,
100  *  src[0-2]_reg, use, swiz, neg, abs, amode, rgroup,
101  *  imm
102  *
103  * Return 0 if successful, and a non-zero
104  * value otherwise.
105  */
106 int
107 etna_assemble(uint32_t *out, const struct etna_inst *inst, bool has_no_oneconst_limit);
108 
109 #endif
110