2 * Copyright (C) 2020 Collabora, Ltd.
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:
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
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
26 /* This file contains the final passes of the compiler. Running after
27 * scheduling and RA, the IR is now finalized, so we need to emit it to actual
28 * bits on the wire (as well as fixup branches) */
31 bi_pack_header(bi_clause
*clause
, bi_clause
*next
)
33 struct bifrost_header header
= {
35 .no_end_of_shader
= (next
!= NULL
),
39 memcpy(&u
, &header
, sizeof(header
));
44 bi_pack_registers(bi_clause
*clause
, bi_bundle bundle
)
51 bi_pack_fma(bi_clause
*clause
, bi_bundle bundle
)
54 return BIFROST_FMA_NOP
;
58 bi_pack_add(bi_clause
*clause
, bi_bundle bundle
)
61 return BIFROST_ADD_NOP
;
64 struct bi_packed_bundle
{
69 static struct bi_packed_bundle
70 bi_pack_bundle(bi_clause
*clause
, bi_bundle bundle
)
72 unsigned reg
= bi_pack_registers(clause
, bundle
);
73 uint64_t fma
= bi_pack_fma(clause
, bundle
);
74 uint64_t add
= bi_pack_add(clause
, bundle
);
76 struct bi_packed_bundle packed
= {
77 .lo
= reg
| (fma
<< 35) | ((add
& 0b111111) << 58),
85 bi_pack_clause(bi_context
*ctx
, bi_clause
*clause
, bi_clause
*next
,
86 struct util_dynarray
*emission
)
88 struct bi_packed_bundle ins_1
= bi_pack_bundle(clause
, clause
->bundles
[0]);
89 assert(clause
->bundle_count
== 1);
91 struct bifrost_fmt1 quad_1
= {
92 .tag
= BIFROST_FMT1_FINAL
,
93 .header
= bi_pack_header(clause
, next
),
95 .ins_2
= ins_1
.hi
& ((1 << 11) - 1),
96 .ins_0
= (ins_1
.hi
>> 11) & 0b111,
99 util_dynarray_append(emission
, struct bifrost_fmt1
, quad_1
);
103 bi_next_clause(bi_context
*ctx
, pan_block
*block
, bi_clause
*clause
)
105 /* Try the next clause in this block */
106 if (clause
->link
.next
!= &((bi_block
*) block
)->clauses
)
107 return list_first_entry(&(clause
->link
), bi_clause
, link
);
109 /* Try the next block, or the one after that if it's empty, etc .*/
110 pan_block
*next_block
= pan_next_block(block
);
112 bi_foreach_block_from(ctx
, next_block
, block
) {
113 bi_block
*blk
= (bi_block
*) block
;
115 if (!list_is_empty(&blk
->clauses
))
116 return list_first_entry(&(blk
->clauses
), bi_clause
, link
);
123 bi_pack(bi_context
*ctx
, struct util_dynarray
*emission
)
125 util_dynarray_init(emission
, NULL
);
127 bi_foreach_block(ctx
, _block
) {
128 bi_block
*block
= (bi_block
*) _block
;
130 bi_foreach_clause_in_block(block
, clause
) {
131 bi_clause
*next
= bi_next_clause(ctx
, _block
, clause
);
132 bi_pack_clause(ctx
, clause
, next
, emission
);