xref: /aosp_15_r20/external/mesa3d/src/panfrost/compiler/valhall/va_lower_split_64bit.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (C) 2021 Collabora Ltd.
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, sublicense,
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 next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * 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 NONINFRINGEMENT.  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 FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #include "bi_builder.h"
25 #include "va_compiler.h"
26 
27 /*
28  * Bifrost uses split 64-bit addresses, specified as two consecutive sources.
29  * Valhall uses contiguous 64-bit addresses, specified as a single source with
30  * an aligned register pair. This simple pass inserts moves to lower split
31  * 64-bit sources into a collect, ensuring the register constraints will be
32  * respected by RA. This could be optimized, but this is deferred for now.
33  */
34 static void
lower_split_src(bi_context * ctx,bi_instr * I,unsigned s)35 lower_split_src(bi_context *ctx, bi_instr *I, unsigned s)
36 {
37    /* Skip sources that are already split properly */
38    bi_index offset_fau = I->src[s];
39    offset_fau.offset++;
40 
41    if (I->src[s].type == BI_INDEX_FAU && I->src[s].offset == 0 &&
42        bi_is_value_equiv(offset_fau, I->src[s + 1])) {
43       return;
44    }
45 
46    /* Allocate temporary before the instruction */
47    bi_builder b = bi_init_builder(ctx, bi_before_instr(I));
48    bi_index vec = bi_temp(ctx);
49    bi_instr *collect = bi_collect_i32_to(&b, vec, 2);
50    bi_instr *split = bi_split_i32_to(&b, 2, vec);
51 
52    /* Emit collect */
53    for (unsigned w = 0; w < 2; ++w) {
54       collect->src[w] = I->src[s + w];
55 
56       split->dest[w] = bi_temp(ctx);
57       I->src[s + w] = split->dest[w];
58    }
59 }
60 
61 void
va_lower_split_64bit(bi_context * ctx)62 va_lower_split_64bit(bi_context *ctx)
63 {
64    bi_foreach_instr_global(ctx, I) {
65       bi_foreach_src(I, s) {
66          if (bi_is_null(I->src[s]) || s >= 4)
67             continue;
68 
69          struct va_src_info info = va_src_info(I->op, s);
70 
71          if (info.size == VA_SIZE_64)
72             lower_split_src(ctx, I, s);
73       }
74    }
75 }
76