panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "compiler.h"
|
|
|
|
#include "midgard_ops.h"
|
|
|
|
|
|
|
|
/* Midgard IR only knows vector ALU types, but we sometimes need to actually
|
|
|
|
* use scalar ALU instructions, for functional or performance reasons. To do
|
|
|
|
* this, we just demote vector ALU payloads to scalar. */
|
|
|
|
|
|
|
|
static int
|
2019-07-02 02:51:48 +01:00
|
|
|
component_from_mask(unsigned mask)
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
{
|
2019-07-02 02:35:28 +01:00
|
|
|
for (int c = 0; c < 8; ++c) {
|
|
|
|
if (mask & (1 << c))
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned
|
2019-07-26 14:30:16 +01:00
|
|
|
vector_to_scalar_source(unsigned u, bool is_int, bool is_full,
|
2019-10-26 19:06:17 +01:00
|
|
|
unsigned component)
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
{
|
|
|
|
midgard_vector_alu_src v;
|
|
|
|
memcpy(&v, &u, sizeof(v));
|
|
|
|
|
|
|
|
/* TODO: Integers */
|
|
|
|
|
2019-07-02 02:35:28 +01:00
|
|
|
midgard_scalar_alu_src s = { 0 };
|
|
|
|
|
|
|
|
if (is_full) {
|
|
|
|
/* For a 32-bit op, just check the source half flag */
|
|
|
|
s.full = !v.half;
|
|
|
|
} else if (!v.half) {
|
|
|
|
/* For a 16-bit op that's not subdivided, never full */
|
|
|
|
s.full = false;
|
|
|
|
} else {
|
|
|
|
/* We can't do 8-bit scalar, abort! */
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Component indexing takes size into account */
|
|
|
|
|
|
|
|
if (s.full)
|
|
|
|
s.component = component << 1;
|
2019-10-26 19:06:17 +01:00
|
|
|
else
|
|
|
|
s.component = component;
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
|
|
|
|
if (is_int) {
|
|
|
|
/* TODO */
|
|
|
|
} else {
|
|
|
|
s.abs = v.mod & MIDGARD_FLOAT_MOD_ABS;
|
|
|
|
s.negate = v.mod & MIDGARD_FLOAT_MOD_NEG;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned o;
|
|
|
|
memcpy(&o, &s, sizeof(s));
|
|
|
|
|
|
|
|
return o & ((1 << 6) - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static midgard_scalar_alu
|
|
|
|
vector_to_scalar_alu(midgard_vector_alu v, midgard_instruction *ins)
|
|
|
|
{
|
|
|
|
bool is_int = midgard_is_integer_op(v.op);
|
2019-07-02 02:35:28 +01:00
|
|
|
bool is_full = v.reg_mode == midgard_reg_mode_32;
|
2019-08-26 19:58:27 +01:00
|
|
|
bool is_inline_constant = ins->has_inline_constant;
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
|
2019-07-26 14:30:16 +01:00
|
|
|
unsigned comp = component_from_mask(ins->mask);
|
|
|
|
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
/* The output component is from the mask */
|
|
|
|
midgard_scalar_alu s = {
|
|
|
|
.op = v.op,
|
2019-10-26 19:06:17 +01:00
|
|
|
.src1 = vector_to_scalar_source(v.src1, is_int, is_full, ins->swizzle[0][comp]),
|
|
|
|
.src2 = !is_inline_constant ? vector_to_scalar_source(v.src2, is_int, is_full, ins->swizzle[1][comp]) : 0,
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
.unknown = 0,
|
|
|
|
.outmod = v.outmod,
|
2019-07-02 02:35:28 +01:00
|
|
|
.output_full = is_full,
|
2019-07-26 14:30:16 +01:00
|
|
|
.output_component = comp
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
};
|
|
|
|
|
2019-07-02 02:51:48 +01:00
|
|
|
/* Full components are physically spaced out */
|
|
|
|
if (is_full) {
|
|
|
|
assert(s.output_component < 4);
|
|
|
|
s.output_component <<= 1;
|
|
|
|
}
|
|
|
|
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
/* Inline constant is passed along rather than trying to extract it
|
|
|
|
* from v */
|
|
|
|
|
2019-08-26 19:58:27 +01:00
|
|
|
if (ins->has_inline_constant) {
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
uint16_t imm = 0;
|
|
|
|
int lower_11 = ins->inline_constant & ((1 << 12) - 1);
|
|
|
|
imm |= (lower_11 >> 9) & 3;
|
|
|
|
imm |= (lower_11 >> 6) & 4;
|
|
|
|
imm |= (lower_11 >> 2) & 0x38;
|
|
|
|
imm |= (lower_11 & 63) << 6;
|
|
|
|
|
|
|
|
s.src2 = imm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-10-26 19:06:17 +01:00
|
|
|
static void
|
|
|
|
mir_pack_swizzle_alu(midgard_instruction *ins)
|
|
|
|
{
|
|
|
|
midgard_vector_alu_src src[] = {
|
|
|
|
vector_alu_from_unsigned(ins->alu.src1),
|
|
|
|
vector_alu_from_unsigned(ins->alu.src2)
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < 2; ++i) {
|
|
|
|
unsigned packed = 0;
|
|
|
|
|
2019-10-31 18:56:45 +00:00
|
|
|
/* For 32-bit, swizzle packing is stupid-simple. For 16-bit,
|
|
|
|
* the strategy is to check whether the nibble we're on is
|
|
|
|
* upper or lower. We need all components to be on the same
|
|
|
|
* "side"; that much is enforced by the ISA and should have
|
|
|
|
* been lowered. TODO: 8-bit/64-bit packing. TODO: vec8 */
|
|
|
|
|
|
|
|
unsigned first = ins->mask ? ffs(ins->mask) - 1 : 0;
|
|
|
|
bool upper = ins->swizzle[i][first] > 3;
|
|
|
|
|
|
|
|
if (upper && ins->mask)
|
|
|
|
assert(mir_srcsize(ins, i) <= midgard_reg_mode_16);
|
|
|
|
|
2019-10-26 19:06:17 +01:00
|
|
|
for (unsigned c = 0; c < 4; ++c) {
|
|
|
|
unsigned v = ins->swizzle[i][c];
|
|
|
|
|
2019-10-31 18:56:45 +00:00
|
|
|
bool t_upper = v > 3;
|
|
|
|
|
|
|
|
/* Ensure we're doing something sane */
|
|
|
|
|
|
|
|
if (ins->mask & (1 << c)) {
|
|
|
|
assert(t_upper == upper);
|
|
|
|
assert(v <= 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the non upper part */
|
|
|
|
v &= 0x3;
|
2019-10-26 19:06:17 +01:00
|
|
|
|
|
|
|
packed |= v << (2 * c);
|
|
|
|
}
|
|
|
|
|
|
|
|
src[i].swizzle = packed;
|
2019-10-31 18:56:45 +00:00
|
|
|
src[i].rep_high = upper;
|
2019-10-26 19:06:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ins->alu.src1 = vector_alu_srco_unsigned(src[0]);
|
|
|
|
|
|
|
|
if (!ins->has_inline_constant)
|
|
|
|
ins->alu.src2 = vector_alu_srco_unsigned(src[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mir_pack_swizzle_ldst(midgard_instruction *ins)
|
|
|
|
{
|
|
|
|
/* TODO: non-32-bit, non-vec4 */
|
|
|
|
for (unsigned c = 0; c < 4; ++c) {
|
|
|
|
unsigned v = ins->swizzle[0][c];
|
|
|
|
|
|
|
|
/* Check vec4 */
|
|
|
|
assert(v <= 3);
|
|
|
|
|
|
|
|
ins->load_store.swizzle |= v << (2 * c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: arg_1/2 */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mir_pack_swizzle_tex(midgard_instruction *ins)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < 2; ++i) {
|
|
|
|
unsigned packed = 0;
|
|
|
|
|
|
|
|
for (unsigned c = 0; c < 4; ++c) {
|
|
|
|
unsigned v = ins->swizzle[i][c];
|
|
|
|
|
|
|
|
/* Check vec4 */
|
|
|
|
assert(v <= 3);
|
|
|
|
|
|
|
|
packed |= v << (2 * c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
ins->texture.swizzle = packed;
|
|
|
|
else
|
|
|
|
ins->texture.in_reg_swizzle = packed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: bias component */
|
|
|
|
}
|
|
|
|
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
static void
|
|
|
|
emit_alu_bundle(compiler_context *ctx,
|
|
|
|
midgard_bundle *bundle,
|
|
|
|
struct util_dynarray *emission,
|
|
|
|
unsigned lookahead)
|
|
|
|
{
|
|
|
|
/* Emit the control word */
|
|
|
|
util_dynarray_append(emission, uint32_t, bundle->control | lookahead);
|
|
|
|
|
|
|
|
/* Next up, emit register words */
|
|
|
|
for (unsigned i = 0; i < bundle->instruction_count; ++i) {
|
|
|
|
midgard_instruction *ins = bundle->instructions[i];
|
|
|
|
|
|
|
|
/* Check if this instruction has registers */
|
|
|
|
if (ins->compact_branch || ins->prepacked_branch) continue;
|
|
|
|
|
|
|
|
/* Otherwise, just emit the registers */
|
|
|
|
uint16_t reg_word = 0;
|
|
|
|
memcpy(®_word, &ins->registers, sizeof(uint16_t));
|
|
|
|
util_dynarray_append(emission, uint16_t, reg_word);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now, we emit the body itself */
|
|
|
|
for (unsigned i = 0; i < bundle->instruction_count; ++i) {
|
|
|
|
midgard_instruction *ins = bundle->instructions[i];
|
|
|
|
|
|
|
|
/* Where is this body */
|
|
|
|
unsigned size = 0;
|
|
|
|
void *source = NULL;
|
|
|
|
|
|
|
|
/* In case we demote to a scalar */
|
|
|
|
midgard_scalar_alu scalarized;
|
|
|
|
|
|
|
|
if (ins->unit & UNITS_ANY_VECTOR) {
|
2019-07-02 02:51:48 +01:00
|
|
|
if (ins->alu.reg_mode == midgard_reg_mode_32)
|
|
|
|
ins->alu.mask = expand_writemask_32(ins->mask);
|
|
|
|
else
|
|
|
|
ins->alu.mask = ins->mask;
|
|
|
|
|
2019-10-26 19:06:17 +01:00
|
|
|
mir_pack_swizzle_alu(ins);
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
size = sizeof(midgard_vector_alu);
|
|
|
|
source = &ins->alu;
|
|
|
|
} else if (ins->unit == ALU_ENAB_BR_COMPACT) {
|
|
|
|
size = sizeof(midgard_branch_cond);
|
|
|
|
source = &ins->br_compact;
|
|
|
|
} else if (ins->compact_branch) { /* misnomer */
|
|
|
|
size = sizeof(midgard_branch_extended);
|
|
|
|
source = &ins->branch_extended;
|
|
|
|
} else {
|
|
|
|
size = sizeof(midgard_scalar_alu);
|
|
|
|
scalarized = vector_to_scalar_alu(ins->alu, ins);
|
|
|
|
source = &scalarized;
|
|
|
|
}
|
|
|
|
|
u_dynarray: turn util_dynarray_{grow, resize} into element-oriented macros
The main motivation for this change is API ergonomics: most operations
on dynarrays are really on elements, not on bytes, so it's weird to have
grow and resize as the odd operations out.
The secondary motivation is memory safety. Users of the old byte-oriented
functions would often multiply a number of elements with the element size,
which could overflow, and checking for overflow is tedious.
With this change, we only need to implement the overflow checks once.
The checks are cheap: since eltsize is a compile-time constant and the
functions should be inlined, they only add a single comparison and an
unlikely branch.
v2:
- ensure operations are no-op when allocation fails
- in util_dynarray_clone, call resize_bytes with a compile-time constant element size
v3:
- fix iris, lima, panfrost
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2019-05-13 15:58:08 +01:00
|
|
|
memcpy(util_dynarray_grow_bytes(emission, 1, size), source, size);
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit padding (all zero) */
|
u_dynarray: turn util_dynarray_{grow, resize} into element-oriented macros
The main motivation for this change is API ergonomics: most operations
on dynarrays are really on elements, not on bytes, so it's weird to have
grow and resize as the odd operations out.
The secondary motivation is memory safety. Users of the old byte-oriented
functions would often multiply a number of elements with the element size,
which could overflow, and checking for overflow is tedious.
With this change, we only need to implement the overflow checks once.
The checks are cheap: since eltsize is a compile-time constant and the
functions should be inlined, they only add a single comparison and an
unlikely branch.
v2:
- ensure operations are no-op when allocation fails
- in util_dynarray_clone, call resize_bytes with a compile-time constant element size
v3:
- fix iris, lima, panfrost
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2019-05-13 15:58:08 +01:00
|
|
|
memset(util_dynarray_grow_bytes(emission, 1, bundle->padding), 0, bundle->padding);
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
|
|
|
|
/* Tack on constants */
|
|
|
|
|
|
|
|
if (bundle->has_embedded_constants) {
|
|
|
|
util_dynarray_append(emission, float, bundle->constants[0]);
|
|
|
|
util_dynarray_append(emission, float, bundle->constants[1]);
|
|
|
|
util_dynarray_append(emission, float, bundle->constants[2]);
|
|
|
|
util_dynarray_append(emission, float, bundle->constants[3]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* After everything is scheduled, emit whole bundles at a time */
|
|
|
|
|
|
|
|
void
|
|
|
|
emit_binary_bundle(compiler_context *ctx,
|
2019-07-10 18:00:50 +01:00
|
|
|
midgard_bundle *bundle,
|
|
|
|
struct util_dynarray *emission,
|
|
|
|
int next_tag)
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
{
|
|
|
|
int lookahead = next_tag << 4;
|
|
|
|
|
|
|
|
switch (bundle->tag) {
|
|
|
|
case TAG_ALU_4:
|
|
|
|
case TAG_ALU_8:
|
|
|
|
case TAG_ALU_12:
|
|
|
|
case TAG_ALU_16:
|
|
|
|
emit_alu_bundle(ctx, bundle, emission, lookahead);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG_LOAD_STORE_4: {
|
|
|
|
/* One or two composing instructions */
|
|
|
|
|
|
|
|
uint64_t current64, next64 = LDST_NOP;
|
|
|
|
|
2019-07-02 02:51:48 +01:00
|
|
|
/* Copy masks */
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < bundle->instruction_count; ++i) {
|
|
|
|
bundle->instructions[i]->load_store.mask =
|
|
|
|
bundle->instructions[i]->mask;
|
2019-10-26 19:06:17 +01:00
|
|
|
|
|
|
|
mir_pack_swizzle_ldst(bundle->instructions[i]);
|
2019-07-02 02:51:48 +01:00
|
|
|
}
|
|
|
|
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
memcpy(¤t64, &bundle->instructions[0]->load_store, sizeof(current64));
|
|
|
|
|
|
|
|
if (bundle->instruction_count == 2)
|
|
|
|
memcpy(&next64, &bundle->instructions[1]->load_store, sizeof(next64));
|
|
|
|
|
|
|
|
midgard_load_store instruction = {
|
|
|
|
.type = bundle->tag,
|
|
|
|
.next_type = next_tag,
|
|
|
|
.word1 = current64,
|
|
|
|
.word2 = next64
|
|
|
|
};
|
|
|
|
|
|
|
|
util_dynarray_append(emission, midgard_load_store, instruction);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-11 18:24:57 +01:00
|
|
|
case TAG_TEXTURE_4:
|
|
|
|
case TAG_TEXTURE_4_VTX: {
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
/* Texture instructions are easy, since there is no pipelining
|
2019-06-11 18:24:57 +01:00
|
|
|
* nor VLIW to worry about. We may need to set .cont/.last
|
|
|
|
* flags. */
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
|
|
|
|
midgard_instruction *ins = bundle->instructions[0];
|
|
|
|
|
2019-06-11 18:24:57 +01:00
|
|
|
ins->texture.type = bundle->tag;
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
ins->texture.next_type = next_tag;
|
2019-07-02 02:51:48 +01:00
|
|
|
ins->texture.mask = ins->mask;
|
2019-10-26 19:06:17 +01:00
|
|
|
mir_pack_swizzle_tex(ins);
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
|
|
|
|
ctx->texture_op_count--;
|
|
|
|
|
2019-07-29 23:11:12 +01:00
|
|
|
if (mir_op_computes_derivatives(ins->texture.op)) {
|
2019-06-11 17:43:08 +01:00
|
|
|
bool continues = ctx->texture_op_count > 0;
|
2019-07-30 00:55:15 +01:00
|
|
|
|
|
|
|
/* Control flow complicates helper invocation
|
|
|
|
* lifespans, so for now just keep helper threads
|
|
|
|
* around indefinitely with loops. TODO: Proper
|
|
|
|
* analysis */
|
|
|
|
continues |= ctx->loop_count > 0;
|
|
|
|
|
2019-06-11 17:43:08 +01:00
|
|
|
ins->texture.cont = continues;
|
|
|
|
ins->texture.last = !continues;
|
|
|
|
} else {
|
|
|
|
ins->texture.cont = ins->texture.last = 1;
|
panfrost/midgard: Refactor schedule/emit pipeline
First, this moves the scheduler and emitter out of midgard_compile.c
into their own dedicated files.
More interestingly, this slims down midgard_bundle to be essentially an
array of _pointers_ to midgard_instructions (plus some bundling
metadata), rather than the instructions and packing themselves. The
difference is critical, as it means that (within reason, i.e. as long as
it doesn't affect the schedule) midgard_instrucitons can now be modified
_after_ scheduling while having changes updated in the final binary.
On a more philosophical level, this removes an IR. Previously, the IR
before scheduling (MIR) was separate from the IR after scheduling
(post-schedule MIR), requiring a separate set of utilities to traverse,
using different idioms. There was no good reason for this, and it
restricts our flexibility with the RA. So unify all the things!
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Ryan Houdek <Sonicadvance1@gmail.com>
2019-05-22 05:33:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
util_dynarray_append(emission, midgard_texture_word, ins->texture);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
unreachable("Unknown midgard instruction type\n");
|
|
|
|
}
|
|
|
|
}
|