1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2022 Imagination Technologies Ltd.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
5bf215546Sopenharmony_ci * of this software and associated documentation files (the "Software"), to deal
6bf215546Sopenharmony_ci * in the Software without restriction, including without limitation the rights
7bf215546Sopenharmony_ci * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8bf215546Sopenharmony_ci * copies of the Software, and to permit persons to whom the Software is
9bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18bf215546Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#ifndef ROGUE_OPERAND_H
25bf215546Sopenharmony_ci#define ROGUE_OPERAND_H
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci#include <stddef.h>
28bf215546Sopenharmony_ci#include <stdint.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "rogue_util.h"
31bf215546Sopenharmony_ci#include "util/macros.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/* Register-related defines. */
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci/* Total max number of registers per class
36bf215546Sopenharmony_ci * (instances > ROGUE_MAX_REG_INDEX addressable via indexing only).
37bf215546Sopenharmony_ci */
38bf215546Sopenharmony_ci#define ROGUE_MAX_REG_TEMP 248
39bf215546Sopenharmony_ci#define ROGUE_MAX_REG_COEFF 4096
40bf215546Sopenharmony_ci#define ROGUE_MAX_REG_CONST 240
41bf215546Sopenharmony_ci#define ROGUE_MAX_REG_SHARED 4096
42bf215546Sopenharmony_ci#define ROGUE_MAX_REG_PIXEL_OUT 8
43bf215546Sopenharmony_ci#define ROGUE_MAX_REG_VERTEX_IN 248
44bf215546Sopenharmony_ci#define ROGUE_MAX_REG_INTERNAL 8
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci/* Maximum register index via offset encoding. */
47bf215546Sopenharmony_ci#define ROGUE_MAX_REG_INDEX 256
48bf215546Sopenharmony_ci
49bf215546Sopenharmony_ci/* Pixel-out register offset. */
50bf215546Sopenharmony_ci#define ROGUE_PIXEL_OUT_REG_OFFSET 32
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci/* Internal register offset. */
53bf215546Sopenharmony_ci#define ROGUE_INTERNAL_REG_OFFSET 36
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci/* Coefficient registers are typically used in groups of 4. */
56bf215546Sopenharmony_ci#define ROGUE_COEFF_ALIGN 4
57bf215546Sopenharmony_ci
58bf215546Sopenharmony_ci/* Defines for other operand types. */
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_ci/* Available dependent read counters. */
61bf215546Sopenharmony_ci#define ROGUE_NUM_DRCS 2
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci/* Maximum number of vertex outputs. */
64bf215546Sopenharmony_ci#define ROGUE_MAX_VERTEX_OUTPUTS 256
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci/* All components of an emulated vec4 register group. */
67bf215546Sopenharmony_ci#define ROGUE_COMPONENT_ALL (~0)
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci/**
70bf215546Sopenharmony_ci * \brief Operand types.
71bf215546Sopenharmony_ci */
72bf215546Sopenharmony_cienum rogue_operand_type {
73bf215546Sopenharmony_ci   /* Register operands. */
74bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_TEMP = 0, /** Temporary register. */
75bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_COEFF, /** Coefficient register. */
76bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_CONST, /** Constant register. */
77bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_SHARED, /** Shared register. */
78bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_PIXEL_OUT, /** Pixel output register. */
79bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_VERTEX_IN, /** Vertex input register. */
80bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_INTERNAL, /** Internal register. */
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_REG_MAX = ROGUE_OPERAND_TYPE_REG_INTERNAL,
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_IMMEDIATE, /** Immediate value. */
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_DRC, /** Dependent read counter. */
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_VREG, /** Virtual register (pre-regalloc). */
89bf215546Sopenharmony_ci
90bf215546Sopenharmony_ci   ROGUE_OPERAND_TYPE_COUNT,
91bf215546Sopenharmony_ci};
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci/* clang-format off */
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci#define ROGUE_NUM_REG_TYPES (ROGUE_OPERAND_TYPE_REG_MAX + 1)
96bf215546Sopenharmony_ci
97bf215546Sopenharmony_ci/**
98bf215546Sopenharmony_ci * \brief A bitmask for any register operand type.
99bf215546Sopenharmony_ci */
100bf215546Sopenharmony_ci#define ROGUE_MASK_ANY_REG                 \
101bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_TEMP) |      \
102bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_COEFF) |     \
103bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_CONST) |     \
104bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_PIXEL_OUT) | \
105bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_VERTEX_IN) | \
106bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_SHARED) |    \
107bf215546Sopenharmony_ci   ROH(ROGUE_OPERAND_TYPE_REG_INTERNAL)
108bf215546Sopenharmony_ci
109bf215546Sopenharmony_ci/* clang-format on */
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci/**
112bf215546Sopenharmony_ci * \brief Operand description.
113bf215546Sopenharmony_ci */
114bf215546Sopenharmony_cistruct rogue_operand {
115bf215546Sopenharmony_ci   enum rogue_operand_type type;
116bf215546Sopenharmony_ci
117bf215546Sopenharmony_ci   union {
118bf215546Sopenharmony_ci      struct {
119bf215546Sopenharmony_ci         uint64_t value;
120bf215546Sopenharmony_ci      } immediate;
121bf215546Sopenharmony_ci
122bf215546Sopenharmony_ci      struct {
123bf215546Sopenharmony_ci         size_t number;
124bf215546Sopenharmony_ci      } drc;
125bf215546Sopenharmony_ci
126bf215546Sopenharmony_ci      struct {
127bf215546Sopenharmony_ci         size_t number;
128bf215546Sopenharmony_ci      } reg;
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ci      struct {
131bf215546Sopenharmony_ci         size_t number;
132bf215546Sopenharmony_ci         bool is_vector;
133bf215546Sopenharmony_ci         size_t component;
134bf215546Sopenharmony_ci      } vreg;
135bf215546Sopenharmony_ci   };
136bf215546Sopenharmony_ci};
137bf215546Sopenharmony_ci
138bf215546Sopenharmony_ci/**
139bf215546Sopenharmony_ci * \brief Register access flags.
140bf215546Sopenharmony_ci */
141bf215546Sopenharmony_cienum rogue_register_access {
142bf215546Sopenharmony_ci   ROGUE_REG_ACCESS_READ = BITFIELD_BIT(0U), /** Read-only. */
143bf215546Sopenharmony_ci   ROGUE_REG_ACCESS_WRITE = BITFIELD_BIT(1U), /* Write-only. */
144bf215546Sopenharmony_ci   ROGUE_REG_ACCESS_RW = ROGUE_REG_ACCESS_READ |
145bf215546Sopenharmony_ci                         ROGUE_REG_ACCESS_WRITE, /** Read/write. */
146bf215546Sopenharmony_ci};
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci/**
149bf215546Sopenharmony_ci * \brief Register modifier flags.
150bf215546Sopenharmony_ci */
151bf215546Sopenharmony_cienum rogue_register_modifier {
152bf215546Sopenharmony_ci   ROGUE_REG_MOD_NONE = 0U,
153bf215546Sopenharmony_ci   ROGUE_REG_MOD_IDX = BITFIELD_BIT(0U), /** Index modifier. */
154bf215546Sopenharmony_ci   ROGUE_REG_MOD_DIM = BITFIELD_BIT(1U), /** Dimension modifier. */
155bf215546Sopenharmony_ci   ROGUE_REG_MOD_ALL = ROGUE_REG_MOD_IDX | ROGUE_REG_MOD_DIM,
156bf215546Sopenharmony_ci};
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci#endif /* ROGUE_OPERAND_H */
159