| 1 |
# Copyright © 2025 Collabora Ltd. |
| 2 |
# SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
TEMPLATE = """ |
| 5 |
#include "bi_swizzles.h" |
| 6 |
|
| 7 |
uint32_t bi_op_swizzles[BI_NUM_OPCODES][BI_MAX_SRCS] = { |
| 8 |
% for opcode, src_swizzles in op_swizzles.items(): |
| 9 |
[BI_OPCODE_${opcode.replace('.', '_').upper()}] = { |
| 10 |
% for src in src_swizzles: |
| 11 |
% for swizzle in src: |
| 12 |
(1 << BI_SWIZZLE_${swizzle.upper()}) | |
| 13 |
% endfor |
| 14 |
0, |
| 15 |
% endfor |
| 16 |
}, |
| 17 |
% endfor |
| 18 |
}; |
| 19 |
""" |
| 20 |
|
| 21 |
import sys |
| 22 |
from bifrost_isa import * |
| 23 |
from mako.template import Template |
| 24 |
|
| 25 |
instructions = {} |
| 26 |
for arg in sys.argv[1:]: |
| 27 |
new_instructions = parse_instructions(arg, include_pseudo = True) |
| 28 |
instructions.update(new_instructions) |
| 29 |
|
| 30 |
ir_instructions = partition_mnemonics(instructions) |
| 31 |
|
| 32 |
op_swizzles = {} |
| 33 |
|
| 34 |
for name, op in ir_instructions.items(): |
| 35 |
src_swizzles = [None] * op['srcs'] |
| 36 |
SWIZZLE_MODS = ["lane", "lanes", "replicate", "swz", "widen", "swap"] |
| 37 |
|
| 38 |
for mod, opts in op['modifiers'].items(): |
| 39 |
raw, arg = (mod[0:-1], int(mod[-1])) if mod[-1] in "0123" else (mod, 0) |
| 40 |
if raw in SWIZZLE_MODS: |
| 41 |
assert(src_swizzles[arg] is None) |
| 42 |
src_swizzles[arg] = set(opts) |
| 43 |
|
| 44 |
src_swizzles[arg].discard('reserved') |
| 45 |
if 'none' in src_swizzles[arg]: |
| 46 |
src_swizzles[arg].remove('none') |
| 47 |
src_swizzles[arg].add('h01') |
| 48 |
|
| 49 |
# Anything that doesn't have swizzle mods only supports identity |
| 50 |
src_swizzles = [swizzle or ['h01'] for swizzle in src_swizzles] |
| 51 |
|
| 52 |
op_swizzles[name] = src_swizzles |
| 53 |
|
| 54 |
print(Template(COPYRIGHT + TEMPLATE).render(op_swizzles = op_swizzles)) |