xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/etnaviv/etnaviv_asm.c (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 #include "etnaviv_asm.h"
28 #include "etnaviv_debug.h"
29 #include "etnaviv_util.h"
30 
31 #include "etnaviv/isa/isa.h"
32 
33 /* An instruction can only read from one distinct uniform.
34  * This function verifies this property and returns true if the instruction
35  * is deemed correct and false otherwise.
36  */
37 static bool
check_uniforms(const struct etna_inst * inst)38 check_uniforms(const struct etna_inst *inst)
39 {
40    unsigned uni_rgroup = -1;
41    unsigned uni_reg = -1;
42    bool conflict = false;
43 
44    for (unsigned i = 0; i < ETNA_NUM_SRC; i++) {
45       const struct etna_inst_src *src = &inst->src[i];
46 
47       if (!etna_rgroup_is_uniform(src->rgroup))
48          continue;
49 
50       if (uni_reg == -1) { /* first uniform used */
51          uni_rgroup = src->rgroup;
52          uni_reg = src->reg;
53       } else { /* second or later; check that it is a re-use */
54          if (uni_rgroup != src->rgroup || uni_reg != src->reg) {
55             conflict = true;
56          }
57       }
58    }
59 
60    return !conflict;
61 }
62 
63 int
etna_assemble(uint32_t * out,const struct etna_inst * inst,bool has_no_oneconst_limit)64 etna_assemble(uint32_t *out, const struct etna_inst *inst, bool has_no_oneconst_limit)
65 {
66    /* cannot have both src2 and imm */
67    if (inst->imm && inst->src[2].use)
68       return 1;
69 
70    if (!has_no_oneconst_limit && !check_uniforms(inst))
71       BUG("error: generating instruction that accesses two different uniforms");
72 
73    assert(!(inst->opcode&~0x7f));
74 
75    isa_assemble_instruction(out, inst);
76 
77    return 0;
78 }
79