| 1 |
# Copyright © 2024 Imagination Technologies Ltd. |
| 2 |
# SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
from mako.template import Template, exceptions |
| 5 |
from pco_map import * |
| 6 |
|
| 7 |
template = """/* |
| 8 |
* Copyright © 2024 Imagination Technologies Ltd. |
| 9 |
* |
| 10 |
* SPDX-License-Identifier: MIT |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef PCO_MAP_H |
| 14 |
#define PCO_MAP_H |
| 15 |
|
| 16 |
/** |
| 17 |
* \\file pco_map.h |
| 18 |
* |
| 19 |
* \\brief PCO mapping definitions. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "pco_builder.h" |
| 23 |
#include "pco_common.h" |
| 24 |
#include "pco_internal.h" |
| 25 |
#include "pco_isa.h" |
| 26 |
#include "pco_ops.h" |
| 27 |
#include "util/macros.h" |
| 28 |
|
| 29 |
#include <stdbool.h> |
| 30 |
|
| 31 |
/* Enum mappings. */ |
| 32 |
% for enum_map in enum_maps.values(): |
| 33 |
static inline |
| 34 |
${enum_map.type_to} ${enum_map.name}(${enum_map.type_from} val) |
| 35 |
{ |
| 36 |
uint64_t to = 0; |
| 37 |
|
| 38 |
% if enum_map.pass_zero_val is not None: |
| 39 |
if (!val) |
| 40 |
return ${enum_map.pass_zero_val}; |
| 41 |
|
| 42 |
% endif |
| 43 |
% if enum_map.both_bitsets: |
| 44 |
u_foreach_bit64 (b, val) { |
| 45 |
switch (b) { |
| 46 |
% for elem_from, elem_to in enum_map.mappings: |
| 47 |
case ${elem_from}: |
| 48 |
to |= ${elem_to}; |
| 49 |
break; |
| 50 |
|
| 51 |
% endfor |
| 52 |
default: |
| 53 |
UNREACHABLE(""); |
| 54 |
} |
| 55 |
} |
| 56 |
% else: |
| 57 |
switch (val) { |
| 58 |
% for elem_from, elem_to in enum_map.mappings: |
| 59 |
case ${elem_from}: |
| 60 |
to = ${elem_to}; |
| 61 |
break; |
| 62 |
|
| 63 |
% endfor |
| 64 |
default: |
| 65 |
UNREACHABLE(""); |
| 66 |
} |
| 67 |
% endif |
| 68 |
|
| 69 |
return to; |
| 70 |
} |
| 71 |
|
| 72 |
% endfor |
| 73 |
static inline |
| 74 |
enum pco_regbank pco_map_reg_bank(pco_ref ref) |
| 75 |
{ |
| 76 |
if (pco_ref_is_idx_reg(ref)) { |
| 77 |
return PCO_REGBANK_IDX0 + ref.idx_reg.num; |
| 78 |
} |
| 79 |
|
| 80 |
return pco_map_reg_class_to_regbank(pco_ref_get_reg_class(ref)); |
| 81 |
} |
| 82 |
|
| 83 |
static inline |
| 84 |
unsigned pco_map_reg_bank_bits(pco_ref ref) |
| 85 |
{ |
| 86 |
return util_last_bit(pco_map_reg_bank(ref)); |
| 87 |
} |
| 88 |
|
| 89 |
static inline |
| 90 |
enum pco_idxbank pco_map_idx_bank(pco_ref ref) |
| 91 |
{ |
| 92 |
assert(pco_ref_is_idx_reg(ref)); |
| 93 |
return pco_map_reg_class_to_idxbank(ref.reg_class); |
| 94 |
} |
| 95 |
|
| 96 |
static inline unsigned pco_map_reg_index(pco_ref ref) |
| 97 |
{ |
| 98 |
if (pco_ref_is_reg(ref)) { |
| 99 |
switch (ref.reg_class) { |
| 100 |
case PCO_REG_CLASS_TEMP: |
| 101 |
case PCO_REG_CLASS_VTXIN: |
| 102 |
case PCO_REG_CLASS_COEFF: |
| 103 |
case PCO_REG_CLASS_SHARED: |
| 104 |
case PCO_REG_CLASS_SPEC: |
| 105 |
case PCO_REG_CLASS_CONST: |
| 106 |
return ref.val; |
| 107 |
|
| 108 |
case PCO_REG_CLASS_INTERN: |
| 109 |
return ref.val + PCO_SR_INTL0; |
| 110 |
|
| 111 |
case PCO_REG_CLASS_PIXOUT: |
| 112 |
if (ref.val >= 4) |
| 113 |
return ref.val + PCO_SR_PIXOUT4 - 4; |
| 114 |
else |
| 115 |
return ref.val + PCO_SR_PIXOUT0; |
| 116 |
|
| 117 |
case PCO_REG_CLASS_GLOBAL: |
| 118 |
return ref.val + PCO_SR_GLOBAL0; |
| 119 |
|
| 120 |
case PCO_REG_CLASS_SLOT: |
| 121 |
return (7 - ref.val) + PCO_SR_SLOT7; |
| 122 |
|
| 123 |
default: |
| 124 |
break; |
| 125 |
} |
| 126 |
} else if (pco_ref_is_idx_reg(ref)) { |
| 127 |
return pco_map_idx_bank(ref) | (ref.idx_reg.offset << 3); |
| 128 |
} |
| 129 |
|
| 130 |
UNREACHABLE(""); |
| 131 |
} |
| 132 |
|
| 133 |
static inline unsigned pco_map_reg_index_bits(pco_ref ref) |
| 134 |
{ |
| 135 |
if (pco_ref_is_reg(ref)) |
| 136 |
return util_last_bit(pco_map_reg_index(ref)); |
| 137 |
else if (pco_ref_is_idx_reg(ref)) |
| 138 |
return 11; |
| 139 |
|
| 140 |
UNREACHABLE(""); |
| 141 |
} |
| 142 |
|
| 143 |
static inline |
| 144 |
enum pco_igrp_hdr_variant pco_igrp_hdr_variant(pco_igrp *igrp) |
| 145 |
{ |
| 146 |
if (igrp->hdr.alutype == PCO_ALUTYPE_BITWISE) |
| 147 |
return PCO_IGRP_HDR_BITWISE; |
| 148 |
else if (igrp->hdr.alutype == PCO_ALUTYPE_CONTROL) |
| 149 |
return PCO_IGRP_HDR_CONTROL; |
| 150 |
else |
| 151 |
assert(igrp->hdr.alutype == PCO_ALUTYPE_MAIN); |
| 152 |
|
| 153 |
if (!igrp->hdr.end && !igrp->hdr.atom && !igrp->hdr.rpt && !igrp->hdr.cc) |
| 154 |
return PCO_IGRP_HDR_MAIN_BRIEF; |
| 155 |
|
| 156 |
return PCO_IGRP_HDR_MAIN; |
| 157 |
} |
| 158 |
|
| 159 |
static inline |
| 160 |
enum pco_src_variant pco_igrp_src_variant(const pco_igrp *igrp, |
| 161 |
bool is_upper) |
| 162 |
{ |
| 163 |
unsigned offset = is_upper ? ROGUE_ALU_INPUT_GROUP_SIZE : 0; |
| 164 |
|
| 165 |
pco_ref sA = igrp->srcs.s[0 + offset]; |
| 166 |
pco_ref sB = igrp->srcs.s[1 + offset]; |
| 167 |
pco_ref sC = igrp->srcs.s[2 + offset]; |
| 168 |
pco_ref mux = is_upper ? pco_ref_null() : igrp->iss.is[0]; |
| 169 |
|
| 170 |
bool sA_set = !pco_ref_is_null(sA); |
| 171 |
bool sB_set = !pco_ref_is_null(sB); |
| 172 |
bool sC_set = !pco_ref_is_null(sC); |
| 173 |
bool mux_set = !pco_ref_is_null(mux); |
| 174 |
|
| 175 |
int sbA_bits = sA_set ? pco_map_reg_bank_bits(sA) : -1; |
| 176 |
int sA_bits = sA_set ? pco_map_reg_index_bits(sA) : -1; |
| 177 |
|
| 178 |
int sbB_bits = sB_set ? pco_map_reg_bank_bits(sB) : -1; |
| 179 |
int sB_bits = sB_set ? pco_map_reg_index_bits(sB) : -1; |
| 180 |
|
| 181 |
int sbC_bits = sC_set ? pco_map_reg_bank_bits(sC) : -1; |
| 182 |
int sC_bits = sC_set ? pco_map_reg_index_bits(sC) : -1; |
| 183 |
|
| 184 |
int mux_bits = mux_set ? util_last_bit(pco_map_io_to_is0_sel(pco_ref_get_io(mux))) : -1; |
| 185 |
|
| 186 |
bool is_ctrl = igrp->hdr.alutype == PCO_ALUTYPE_CONTROL; |
| 187 |
bool no_srcs_set = !sA_set && !sB_set && !sC_set && !mux_set; |
| 188 |
if (is_ctrl && no_srcs_set) |
| 189 |
return PCO_SRC_NONE; |
| 190 |
|
| 191 |
% for variant, spec in [(bs.name.upper(), bs.data) for bs in I_SRC.bit_structs.values()]: |
| 192 |
${'else ' if not loop.first else ''}if (${'!' if not spec.is_upper else ''}is_upper && |
| 193 |
sbA_bits ${'==' if spec.sbA_bits == -1 else '<='} ${spec.sbA_bits} && sA_bits ${'==' if spec.sA_bits == -1 else '<='} ${spec.sA_bits} && |
| 194 |
sbB_bits ${'==' if spec.sbB_bits == -1 else '<='} ${spec.sbB_bits} && sB_bits ${'==' if spec.sB_bits == -1 else '<='} ${spec.sB_bits} && |
| 195 |
sbC_bits ${'==' if spec.sbC_bits == -1 else '<='} ${spec.sbC_bits} && sC_bits ${'==' if spec.sC_bits == -1 else '<='} ${spec.sC_bits} && |
| 196 |
mux_bits ${'==' if spec.mux_bits == -1 else '<='} ${spec.mux_bits}) { |
| 197 |
return ${variant}; |
| 198 |
} |
| 199 |
% endfor |
| 200 |
|
| 201 |
UNREACHABLE(""); |
| 202 |
} |
| 203 |
|
| 204 |
static inline |
| 205 |
enum pco_iss_variant pco_igrp_iss_variant(const pco_igrp *igrp) |
| 206 |
{ |
| 207 |
if (igrp->hdr.alutype == PCO_ALUTYPE_MAIN) |
| 208 |
return PCO_ISS_ISS; |
| 209 |
|
| 210 |
return PCO_ISS_NONE; |
| 211 |
} |
| 212 |
|
| 213 |
static inline |
| 214 |
enum pco_dst_variant pco_igrp_dest_variant(pco_igrp *igrp) |
| 215 |
{ |
| 216 |
pco_ref w0 = igrp->dests.w[0]; |
| 217 |
pco_ref w1 = igrp->dests.w[1]; |
| 218 |
|
| 219 |
bool w0_set = !pco_ref_is_null(w0); |
| 220 |
bool w1_set = !pco_ref_is_null(w1); |
| 221 |
|
| 222 |
bool no_dsts = !w0_set && !w1_set; |
| 223 |
bool one_dest = w0_set != w1_set; |
| 224 |
bool dual_dsts = w0_set && w1_set; |
| 225 |
|
| 226 |
if (no_dsts) |
| 227 |
return PCO_DST_NONE; |
| 228 |
|
| 229 |
int db0_bits = w0_set ? pco_map_reg_bank_bits(w0) : -1; |
| 230 |
int d0_bits = w0_set ? pco_map_reg_index_bits(w0) : -1; |
| 231 |
|
| 232 |
int db1_bits = w1_set ? pco_map_reg_bank_bits(w1) : -1; |
| 233 |
int d1_bits = w1_set ? pco_map_reg_index_bits(w1) : -1; |
| 234 |
|
| 235 |
int dbN_bits = w0_set ? db0_bits : db1_bits; |
| 236 |
int dN_bits = w0_set ? d0_bits : d1_bits; |
| 237 |
|
| 238 |
if (one_dest) { |
| 239 |
db0_bits = dbN_bits; |
| 240 |
d0_bits = dN_bits; |
| 241 |
|
| 242 |
db1_bits = -1; |
| 243 |
d1_bits = -1; |
| 244 |
} |
| 245 |
|
| 246 |
% for variant, spec in [(bs.name.upper(), bs.data) for bs in I_DST.bit_structs.values()]: |
| 247 |
${'else ' if not loop.first else ''}if (${'!' if not spec.dual_dsts else ''}dual_dsts && |
| 248 |
db0_bits ${'==' if spec.db0_bits == -1 else '<='} ${spec.db0_bits} && d0_bits ${'==' if spec.d0_bits == -1 else '<='} ${spec.d0_bits} && |
| 249 |
db1_bits ${'==' if spec.db1_bits == -1 else '<='} ${spec.db1_bits} && d1_bits ${'==' if spec.d1_bits == -1 else '<='} ${spec.d1_bits}) { |
| 250 |
return ${variant}; |
| 251 |
} |
| 252 |
% endfor |
| 253 |
|
| 254 |
UNREACHABLE(""); |
| 255 |
} |
| 256 |
|
| 257 |
% for encode_map in encode_maps.values(): |
| 258 |
static inline |
| 259 |
unsigned ${encode_map.name}_variant(pco_instr *instr) |
| 260 |
{ |
| 261 |
% if len(encode_map.variants) > 1: |
| 262 |
% for variant, _, conds in encode_map.variants[1:]: |
| 263 |
${conds.format('bin', 'instr', 'variant')} |
| 264 |
return ${variant}; |
| 265 |
% endfor |
| 266 |
|
| 267 |
% endif |
| 268 |
return ${encode_map.variants[0][0]}; |
| 269 |
} |
| 270 |
|
| 271 |
% endfor |
| 272 |
/* Instruction group mappings. */ |
| 273 |
% for group_map in group_maps.values(): |
| 274 |
static inline |
| 275 |
void ${group_map.name}_map_igrp(pco_igrp *igrp, pco_instr *instr) |
| 276 |
{ |
| 277 |
% for mapping_set in group_map.mapping_sets: |
| 278 |
% for mapping in mapping_set: |
| 279 |
${mapping.format('igrp', 'instr')} |
| 280 |
% endfor |
| 281 |
|
| 282 |
% endfor |
| 283 |
igrp->variant.hdr = pco_igrp_hdr_variant(igrp); |
| 284 |
igrp->variant.lower_src = pco_igrp_src_variant(igrp, false); |
| 285 |
igrp->variant.upper_src = pco_igrp_src_variant(igrp, true); |
| 286 |
igrp->variant.iss = pco_igrp_iss_variant(igrp); |
| 287 |
igrp->variant.dest = pco_igrp_dest_variant(igrp); |
| 288 |
} |
| 289 |
|
| 290 |
% endfor |
| 291 |
static inline |
| 292 |
void pco_map_igrp(pco_igrp *igrp, pco_instr *instr) |
| 293 |
{ |
| 294 |
switch (instr->op) { |
| 295 |
% for group_map in group_maps.values(): |
| 296 |
case ${group_map.cop_name}: |
| 297 |
return ${group_map.name}_map_igrp(igrp, instr); |
| 298 |
|
| 299 |
% endfor |
| 300 |
default: |
| 301 |
break; |
| 302 |
} |
| 303 |
|
| 304 |
const struct pco_op_info *info = &pco_op_info[instr->op]; |
| 305 |
printf("Instruction group mapping not defined for %s op '%s'.\\n", |
| 306 |
info->type == PCO_OP_TYPE_PSEUDO ? "pseudo" : "hardware", |
| 307 |
info->str); |
| 308 |
|
| 309 |
UNREACHABLE(""); |
| 310 |
} |
| 311 |
|
| 312 |
static inline unsigned pco_igrp_hdr_map_encode(uint8_t *bin, pco_igrp *igrp) |
| 313 |
{ |
| 314 |
switch (igrp->variant.hdr) { |
| 315 |
case PCO_IGRP_HDR_MAIN_BRIEF: |
| 316 |
return pco_igrp_hdr_main_brief_encode(bin, |
| 317 |
.da = igrp->hdr.da, |
| 318 |
.length = igrp->hdr.length, |
| 319 |
.oporg = igrp->hdr.oporg, |
| 320 |
.olchk = igrp->hdr.olchk, |
| 321 |
.w1p = igrp->hdr.w1p, |
| 322 |
.w0p = igrp->hdr.w0p, |
| 323 |
.cc = igrp->hdr.cc); |
| 324 |
|
| 325 |
case PCO_IGRP_HDR_MAIN: |
| 326 |
return pco_igrp_hdr_main_encode(bin, |
| 327 |
.da = igrp->hdr.da, |
| 328 |
.length = igrp->hdr.length, |
| 329 |
.oporg = igrp->hdr.oporg, |
| 330 |
.olchk = igrp->hdr.olchk, |
| 331 |
.w1p = igrp->hdr.w1p, |
| 332 |
.w0p = igrp->hdr.w0p, |
| 333 |
.cc = igrp->hdr.cc, |
| 334 |
.end = igrp->hdr.end, |
| 335 |
.atom = igrp->hdr.atom, |
| 336 |
.rpt = igrp->hdr.rpt); |
| 337 |
|
| 338 |
case PCO_IGRP_HDR_BITWISE: |
| 339 |
return pco_igrp_hdr_bitwise_encode(bin, |
| 340 |
.da = igrp->hdr.da, |
| 341 |
.length = igrp->hdr.length, |
| 342 |
.opcnt = igrp->hdr.opcnt, |
| 343 |
.olchk = igrp->hdr.olchk, |
| 344 |
.w1p = igrp->hdr.w1p, |
| 345 |
.w0p = igrp->hdr.w0p, |
| 346 |
.cc = igrp->hdr.cc, |
| 347 |
.end = igrp->hdr.end, |
| 348 |
.atom = igrp->hdr.atom, |
| 349 |
.rpt = igrp->hdr.rpt); |
| 350 |
|
| 351 |
case PCO_IGRP_HDR_CONTROL: |
| 352 |
return pco_igrp_hdr_control_encode(bin, |
| 353 |
.da = igrp->hdr.da, |
| 354 |
.length = igrp->hdr.length, |
| 355 |
.olchk = igrp->hdr.olchk, |
| 356 |
.w1p = igrp->hdr.w1p, |
| 357 |
.w0p = igrp->hdr.w0p, |
| 358 |
.cc = igrp->hdr.cc, |
| 359 |
.miscctl = igrp->hdr.miscctl, |
| 360 |
.ctrlop = igrp->hdr.ctrlop); |
| 361 |
|
| 362 |
default: |
| 363 |
break; |
| 364 |
} |
| 365 |
|
| 366 |
UNREACHABLE(""); |
| 367 |
} |
| 368 |
|
| 369 |
% for encode_map in encode_maps.values(): |
| 370 |
static inline |
| 371 |
% if len(encode_map.variants) > 1: |
| 372 |
unsigned ${encode_map.name}_map_encode(uint8_t *bin, pco_instr *instr, unsigned variant) |
| 373 |
{ |
| 374 |
switch (variant) { |
| 375 |
% for variant, mapping, _ in encode_map.variants: |
| 376 |
case ${variant}: |
| 377 |
return ${mapping.format('bin', 'instr', 'variant')}; |
| 378 |
|
| 379 |
% endfor |
| 380 |
default: |
| 381 |
break; |
| 382 |
} |
| 383 |
|
| 384 |
UNREACHABLE(""); |
| 385 |
} |
| 386 |
% else: |
| 387 |
unsigned ${encode_map.name}_map_encode(uint8_t *bin, pco_instr *instr) |
| 388 |
{ |
| 389 |
return ${encode_map.variants[0][1].format('bin', 'instr', 'variant')}; |
| 390 |
} |
| 391 |
% endif |
| 392 |
|
| 393 |
% endfor |
| 394 |
static inline |
| 395 |
unsigned pco_instr_map_encode(uint8_t *bin, pco_igrp *igrp, enum pco_op_phase phase) |
| 396 |
{ |
| 397 |
pco_instr *instr = igrp->instrs[phase]; |
| 398 |
switch (instr->op) { |
| 399 |
% for encode_map in encode_maps.values(): |
| 400 |
case ${encode_map.cop_name}: |
| 401 |
% if len(encode_map.variants) > 1: |
| 402 |
return ${encode_map.name}_map_encode(bin, instr, pco_igrp_variant(igrp, phase)); |
| 403 |
% else: |
| 404 |
return ${encode_map.name}_map_encode(bin, instr); |
| 405 |
% endif |
| 406 |
|
| 407 |
% endfor |
| 408 |
default: |
| 409 |
break; |
| 410 |
} |
| 411 |
|
| 412 |
UNREACHABLE(""); |
| 413 |
} |
| 414 |
|
| 415 |
static inline |
| 416 |
unsigned pco_srcs_map_encode(uint8_t *bin, pco_igrp *igrp, bool is_upper) |
| 417 |
{ |
| 418 |
unsigned offset = is_upper ? ROGUE_ALU_INPUT_GROUP_SIZE : 0; |
| 419 |
|
| 420 |
pco_ref _sA = igrp->srcs.s[0 + offset]; |
| 421 |
pco_ref _sB = igrp->srcs.s[1 + offset]; |
| 422 |
pco_ref _sC = igrp->srcs.s[2 + offset]; |
| 423 |
pco_ref _mux = is_upper ? pco_ref_null() : igrp->iss.is[0]; |
| 424 |
|
| 425 |
bool sA_set = !pco_ref_is_null(_sA); |
| 426 |
bool sB_set = !pco_ref_is_null(_sB); |
| 427 |
bool sC_set = !pco_ref_is_null(_sC); |
| 428 |
bool mux_set = !pco_ref_is_null(_mux); |
| 429 |
|
| 430 |
unsigned sbA = sA_set ? pco_map_reg_bank(_sA) : 0; |
| 431 |
unsigned sA = sA_set ? pco_map_reg_index(_sA) : 0; |
| 432 |
|
| 433 |
unsigned sbB = sB_set ? pco_map_reg_bank(_sB) : 0; |
| 434 |
unsigned sB = sB_set ? pco_map_reg_index(_sB) : 0; |
| 435 |
|
| 436 |
unsigned sbC = sC_set ? pco_map_reg_bank(_sC) : 0; |
| 437 |
unsigned sC = sC_set ? pco_map_reg_index(_sC) : 0; |
| 438 |
|
| 439 |
unsigned mux = mux_set ? pco_map_io_to_is0_sel(pco_ref_get_io(_mux)) : 0; |
| 440 |
|
| 441 |
enum pco_src_variant variant = is_upper ? igrp->variant.upper_src : igrp->variant.lower_src; |
| 442 |
switch (variant) { |
| 443 |
% for variant, encode_func, spec, offset in [(bs.name.upper(), f'{bs.name}_encode', bs.data, 3 if bs.data.is_upper else 0) for bs in I_SRC.bit_structs.values()]: |
| 444 |
case ${variant}: |
| 445 |
return ${encode_func}(bin, |
| 446 |
% if spec.sbA_bits != -1: |
| 447 |
.s${offset + 0} = sA, |
| 448 |
.sb${offset + 0} = sbA, |
| 449 |
% endif |
| 450 |
% if spec.sbB_bits != -1: |
| 451 |
.s${offset + 1} = sB, |
| 452 |
.sb${offset + 1} = sbB, |
| 453 |
% endif |
| 454 |
% if spec.sbC_bits != -1: |
| 455 |
.s${offset + 2} = sC, |
| 456 |
.sb${offset + 2} = sbC, |
| 457 |
% endif |
| 458 |
% if spec.mux_bits != -1: |
| 459 |
.is0 = mux, |
| 460 |
% endif |
| 461 |
); |
| 462 |
|
| 463 |
% endfor |
| 464 |
default: |
| 465 |
break; |
| 466 |
} |
| 467 |
|
| 468 |
UNREACHABLE(""); |
| 469 |
} |
| 470 |
|
| 471 |
static inline |
| 472 |
unsigned pco_iss_map_encode(uint8_t *bin, pco_igrp *igrp) |
| 473 |
{ |
| 474 |
bool is5_set = !pco_ref_is_null(igrp->iss.is[5]); |
| 475 |
bool is4_set = !pco_ref_is_null(igrp->iss.is[4]); |
| 476 |
bool is3_set = !pco_ref_is_null(igrp->iss.is[3]); |
| 477 |
bool is2_set = !pco_ref_is_null(igrp->iss.is[2]); |
| 478 |
bool is1_set = !pco_ref_is_null(igrp->iss.is[1]); |
| 479 |
|
| 480 |
unsigned is5 = is5_set ? pco_map_io_to_is5_sel(pco_ref_get_io(igrp->iss.is[5])) : 0; |
| 481 |
unsigned is4 = is4_set ? pco_map_io_to_is4_sel(pco_ref_get_io(igrp->iss.is[4])) : 0; |
| 482 |
unsigned is3 = is3_set ? pco_map_io_to_is3_sel(pco_ref_get_io(igrp->iss.is[3])) : 0; |
| 483 |
unsigned is2 = is2_set ? pco_map_io_to_is2_sel(pco_ref_get_io(igrp->iss.is[2])) : 0; |
| 484 |
unsigned is1 = is1_set ? pco_map_io_to_is1_sel(pco_ref_get_io(igrp->iss.is[1])) : 0; |
| 485 |
|
| 486 |
assert(igrp->variant.iss == PCO_ISS_ISS); |
| 487 |
return pco_iss_iss_encode(bin, .is5 = is5, .is4 = is4, .is3 = is3, .is2 = is2, .is1 = is1); |
| 488 |
} |
| 489 |
|
| 490 |
static inline |
| 491 |
unsigned pco_dests_map_encode(uint8_t *bin, pco_igrp *igrp) |
| 492 |
{ |
| 493 |
pco_ref w0 = igrp->dests.w[0]; |
| 494 |
pco_ref w1 = igrp->dests.w[1]; |
| 495 |
|
| 496 |
bool w0_set = !pco_ref_is_null(w0); |
| 497 |
bool w1_set = !pco_ref_is_null(w1); |
| 498 |
|
| 499 |
bool one_dest = w0_set != w1_set; |
| 500 |
|
| 501 |
int db0 = w0_set ? pco_map_reg_bank(w0) : 0; |
| 502 |
int d0 = w0_set ? pco_map_reg_index(w0) : 0; |
| 503 |
|
| 504 |
int db1 = w1_set ? pco_map_reg_bank(w1) : 0; |
| 505 |
int d1 = w1_set ? pco_map_reg_index(w1) : 0; |
| 506 |
|
| 507 |
int dbN = w0_set ? db0 : db1; |
| 508 |
int dN = w0_set ? d0 : d1; |
| 509 |
|
| 510 |
if (one_dest) { |
| 511 |
db0 = dbN; |
| 512 |
d0 = dN; |
| 513 |
|
| 514 |
db1 = 0; |
| 515 |
d1 = 0; |
| 516 |
} |
| 517 |
|
| 518 |
switch (igrp->variant.dest) { |
| 519 |
% for variant, encode_func, spec in [(bs.name.upper(), f'{bs.name}_encode', bs.data) for bs in I_DST.bit_structs.values()]: |
| 520 |
case ${variant}: |
| 521 |
return ${encode_func}(bin, |
| 522 |
% if spec.db0_bits != -1: |
| 523 |
% if spec.dual_dsts: |
| 524 |
.d0 = d0, |
| 525 |
.db0 = db0, |
| 526 |
% else: |
| 527 |
.dN = d0, |
| 528 |
.dbN = db0, |
| 529 |
% endif |
| 530 |
% endif |
| 531 |
% if spec.db1_bits != -1: |
| 532 |
.d1 = d1, |
| 533 |
.db1 = db1, |
| 534 |
% endif |
| 535 |
); |
| 536 |
|
| 537 |
% endfor |
| 538 |
default: |
| 539 |
break; |
| 540 |
} |
| 541 |
|
| 542 |
UNREACHABLE(""); |
| 543 |
} |
| 544 |
#endif /* PCO_MAP_H */""" |
| 545 |
|
| 546 |
def main(): |
| 547 |
try: |
| 548 |
print(Template(template).render(enum_maps=enum_maps, group_maps=group_maps, encode_maps=encode_maps, I_SRC=I_SRC, I_DST=I_DST)) |
| 549 |
except: |
| 550 |
raise Exception(exceptions.text_error_template().render()) |
| 551 |
|
| 552 |
if __name__ == '__main__': |
| 553 |
main() |