P4C
The P4 Compiler
Loading...
Searching...
No Matches
bf-asm/jbay/phv.cpp
1
17
18#include "backends/tofino/bf-asm/jbay/phv.h"
19
20void Target::JBay::Phv::init_regs(::Phv &phv) {
21 // Allocating JBay regs so the uids map to mau register encodings
22 static const struct {
23 char code[2];
24 unsigned size, count;
25 } groups[] = {{"W", 32, 4}, {"B", 8, 4}, {"H", 16, 6}};
26 static const struct {
27 char code[2];
28 Register::type_t type;
29 unsigned count;
30 } types[] = {{"", Register::NORMAL, 12}, {"M", Register::MOCHA, 4}, {"D", Register::DARK, 4}};
31 unsigned uid = 0;
32 unsigned byte = 0;
33 unsigned deparser_id = 0;
34 phv.regs.resize(280);
35 for (unsigned i = 0; i < sizeof groups / sizeof *groups; i++) {
36 unsigned idx[sizeof types / sizeof *types] = {0};
37 for (unsigned j = 0; j < groups[i].count; j++) {
38 for (unsigned k = 0; k < sizeof types / sizeof *types; k++) {
39 for (unsigned l = 0; l < types[k].count; l++, idx[k]++, uid++) {
40 auto reg = new Register;
41 phv.regs[uid] = reg;
42 memset(reg->name, 0, sizeof(reg->name));
43 snprintf(reg->name, sizeof(reg->name), "%.2s%.2s%d", types[k].code,
44 groups[i].code, idx[k]);
45 reg->type = types[k].type;
46 reg->index = idx[k];
47 reg->uid = uid;
48 reg->size = groups[i].size;
49 if (reg->type == Register::DARK) {
50 reg->parser_id_ = reg->deparser_id_ = -1;
51 } else {
52 reg->parser_id_ = byte / 2U;
53 reg->deparser_id_ = deparser_id++;
54 byte += reg->size / 8U;
55 }
56 phv.names[INGRESS][reg->name][0].slice = ::Phv::Slice(*reg, 0, reg->size - 1);
57 phv.names[EGRESS][reg->name][0].slice = ::Phv::Slice(*reg, 0, reg->size - 1);
58 phv.names[GHOST][reg->name][0].slice = ::Phv::Slice(*reg, 0, reg->size - 1);
59 }
60 }
61 }
62 }
63 BUG_CHECK(uid == phv.regs.size(), "uid %u != %zu", uid, phv.regs.size());
64 BUG_CHECK(deparser_id == 224, "deparser_id %u != 224", deparser_id);
65 BUG_CHECK(byte == 512, "byte %u != 512", byte);
66}
Definition bf-asm/phv.h:32