P4C
The P4 Compiler
Loading...
Searching...
No Matches
power_ctl.h
1
17
18#ifndef BACKENDS_TOFINO_BF_ASM_POWER_CTL_H_
19#define BACKENDS_TOFINO_BF_ASM_POWER_CTL_H_
20
21#include "lib/exceptions.h"
22#include "misc.h"
23
24/* power_ctl is weirdly encoded!
25 * As far as I can tell, it actually walks like this:
26 * -[1:0] dimension controls hi-lo for each 8/16/32b type. In other words,
27 * [0] = 8b[31~0], 16b[47~0], 32b[31~0] and [1] = 8b[63~32], 16b[95~48], 32[63~32].
28 * -Within the wider dimension, [13:0] = 112b vector, where [31:0] = control for
29 * 32b section (array slice 3~0), [63:32] = control for 8b section (array slice 7~4),
30 * [111:64] = control for 16b section (array slice 13~8)
31 *
32 * Yes, Jay's decription of how the [1~0][13~0] translates to 224b is correct.
33 * The [1~0] index discriminates phv words going to the left side alu's [0]
34 * vs the right side ones [1]. Within each container size, the bottom 32
35 * (or 48 for 16b) are on the left and the top half ones are on the right.
36 * Pat
37 *
38 * CSR DESCRIPTION IS WRONG!!!
39 */
40
41template <int I>
42void set_power_ctl_reg(checked_array<2, checked_array<16, ubits<I>>> &power_ctl, int reg) {
43 int side = 0;
44 switch (reg / (I * 8)) {
45 case 1: // 8 bit
46 reg -= I * 8;
47 side = reg / (I * 4);
48 reg = (reg % (I * 4)) + (I * 4);
49 break;
50 case 2:
51 case 3: // 16 bit
52 reg -= I * 16;
53 side = reg / (I * 6);
54 reg = (reg % (I * 6)) + (I * 8);
55 break;
56 case 0: // 32 bit
57 side = reg / (I * 4);
58 reg = (reg % (I * 4));
59 break;
60 default:
61 BUG("Invalid power control reg: %d", reg);
62 }
63 power_ctl[side][reg / I] |= 1U << reg % I;
64}
65
66#endif /* BACKENDS_TOFINO_BF_ASM_POWER_CTL_H_ */
Definition checked_array.h:50
Definition ubits.h:82