P4C
The P4 Compiler
Loading...
Searching...
No Matches
bf-asm/tofino/phv.cpp
1
17
18#include "backends/tofino/bf-asm/tofino/phv.h"
19
20void Target::Tofino::Phv::init_regs(::Phv &phv) {
21 // Allocating Tofino registers so the uids map to register encodings
22 static const struct {
23 char code[4];
24 unsigned size, count;
25 } sizes[] = {{"W", 32, 64}, {"B", 8, 64}, {"H", 16, 96}, {"", 0, 32},
26 {"TW", 32, 32}, {"TB", 8, 32}, {"TH", 16, 48}};
27 unsigned uid = 0;
28 phv.regs.resize(NUM_PHV_REGS);
29 for (unsigned i = 0; i < sizeof sizes / sizeof *sizes; i++) {
30 for (unsigned j = 0; j < sizes[i].count; j++, uid++) {
31 auto reg = phv.regs[uid] = new Register;
32 memset(reg->name, 0, sizeof(reg->name));
33 reg->type = (uid >= FIRST_TPHV) ? Register::TAGALONG : Register::NORMAL;
34 reg->index = j;
35 reg->uid = uid;
36 reg->size = sizes[i].size;
37 if (sizes[i].size) {
38 char buf[8];
39 snprintf(buf, sizeof(buf), "R%d", uid);
40 phv.names[INGRESS][buf][0].slice = ::Phv::Slice(*reg, 0, sizes[i].size - 1);
41 phv.names[EGRESS][buf][0].slice = ::Phv::Slice(*reg, 0, sizes[i].size - 1);
42 snprintf(reg->name, sizeof(reg->name), "%.2s%d", sizes[i].code, j);
43 phv.names[INGRESS][reg->name][0].slice = ::Phv::Slice(*reg, 0, sizes[i].size - 1);
44 phv.names[EGRESS][reg->name][0].slice = ::Phv::Slice(*reg, 0, sizes[i].size - 1);
45 }
46 }
47 }
48 BUG_CHECK(uid == phv.regs.size(), "uid %u != %zu", uid, phv.regs.size());
49}
50
51static bitvec tagalong_group(int n) {
52 bitvec rv;
53 rv.setrange(
54 Target::Tofino::Phv::FIRST_8BIT_TPHV + n * (Target::Tofino::Phv::COUNT_8BIT_TPHV / 8),
55 Target::Tofino::Phv::COUNT_8BIT_TPHV / 8);
56 rv.setrange(
57 Target::Tofino::Phv::FIRST_16BIT_TPHV + n * (Target::Tofino::Phv::COUNT_16BIT_TPHV / 8),
58 Target::Tofino::Phv::COUNT_16BIT_TPHV / 8);
59 rv.setrange(
60 Target::Tofino::Phv::FIRST_32BIT_TPHV + n * (Target::Tofino::Phv::COUNT_32BIT_TPHV / 8),
61 Target::Tofino::Phv::COUNT_32BIT_TPHV / 8);
62 return rv;
63}
64const bitvec Target::Tofino::Phv::tagalong_groups[8] = {
65 tagalong_group(0), tagalong_group(1), tagalong_group(2), tagalong_group(3),
66 tagalong_group(4), tagalong_group(5), tagalong_group(6), tagalong_group(7)};
Definition bf-asm/phv.h:32