• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2020 Collabora, Ltd.
2#
3# Permission is hereby granted, free of charge, to any person obtaining a
4# copy of this software and associated documentation files (the "Software"),
5# to deal in the Software without restriction, including without limitation
6# the rights to use, copy, modify, merge, publish, distribute, sublicense,
7# and/or sell copies of the Software, and to permit persons to whom the
8# Software is furnished to do so, subject to the following conditions:
9#
10# The above copyright notice and this permission notice (including the next
11# paragraph) shall be included in all copies or substantial portions of the
12# Software.
13#
14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20# IN THE SOFTWARE.
21
22TEMPLATE = """
23#ifndef _BI_OPCODES_H_
24#define _BI_OPCODES_H_
25
26#include "bifrost.h"
27
28% for mod in sorted(modifiers):
29% if len(modifiers[mod]) > 2: # otherwise just boolean
30enum bi_${mod.lower()} {
31% for i, state in enumerate(modifiers[mod]):
32% if state != "reserved":
33    BI_${mod.upper()}_${state.upper()} = ${i},
34% endif
35% endfor
36};
37
38% endif
39% endfor
40enum bi_opcode {
41% for opcode in sorted(mnemonics):
42    BI_OPCODE_${opcode.replace('.', '_').upper()},
43% endfor
44    BI_NUM_OPCODES
45};
46
47/* Number of staging registers accessed, note this fits into 3-bits */
48
49enum bi_sr_count {
50    /* fixed counts */
51    BI_SR_COUNT_0 = 0,
52    BI_SR_COUNT_1 = 1,
53    BI_SR_COUNT_2 = 2,
54    BI_SR_COUNT_3 = 3,
55    BI_SR_COUNT_4 = 4,
56
57    /* derived from register_format and vecsize */
58    BI_SR_COUNT_FORMAT = 5,
59
60    /* equal to vecsize alone */
61    BI_SR_COUNT_VECSIZE = 6,
62
63    /* specified directly as the sr_count immediate */
64    BI_SR_COUNT_SR_COUNT = 7
65};
66
67enum bi_size {
68   BI_SIZE_8 = 0,
69   BI_SIZE_16,
70   BI_SIZE_24,
71   BI_SIZE_32,
72   BI_SIZE_48,
73   BI_SIZE_64,
74   BI_SIZE_96,
75   BI_SIZE_128,
76};
77
78/* Description of an opcode in the IR */
79struct bi_op_props {
80        const char *name;
81
82        enum bifrost_message_type message : 4;
83        enum bi_size size : 3;
84        enum bi_sr_count sr_count : 3;
85        bool sr_read : 1;
86        bool sr_write : 1;
87        bool last : 1;
88        bool branch : 1;
89        bool table : 1;
90        bool fma : 1;
91        bool add : 1;
92
93        /* Supported propagable modifiers */
94        bool clamp : 1;
95        bool not_result : 1;
96        unsigned abs : 3;
97        unsigned neg : 3;
98        bool not_mod : 1;
99};
100
101/* Generated in bi_opcodes.c.py */
102extern struct bi_op_props bi_opcode_props[BI_NUM_OPCODES];
103
104#endif
105"""
106
107import sys
108from bifrost_isa import *
109from mako.template import Template
110
111instructions = parse_instructions(sys.argv[1], include_pseudo = True)
112ir_instructions = partition_mnemonics(instructions)
113modifier_lists = order_modifiers(ir_instructions)
114
115# Generate sorted list of mnemonics without regard to unit
116mnemonics = set(x[1:] for x in instructions.keys())
117
118print(Template(COPYRIGHT + TEMPLATE).render(mnemonics = mnemonics, modifiers = modifier_lists))
119