/home/runner/work/LabNeura/LabNeura/src/labneura/eda/mapping/fpga/fpga_library.cpp
Line | Count | Source |
1 | | #include "labneura/eda/netlist.h" |
2 | | |
3 | | #include <string> |
4 | | #include <utility> |
5 | | #include <vector> |
6 | | |
7 | | namespace labneura::eda { |
8 | | namespace { |
9 | | |
10 | | // Illustrative architecture model, not a vendor characterisation: area is in |
11 | | // configuration-bit equivalents, delays in ns, capacitances in pF, and routing |
12 | | // delay is not modelled. Load a Liberty file to substitute real numbers. |
13 | | constexpr double kPinCapacitance = 0.002; |
14 | | constexpr double kClockToQ = 0.35; |
15 | | constexpr double kSetup = 0.10; |
16 | | |
17 | 64 | LookupTable scalar(double value) { |
18 | 64 | return LookupTable("scalar", {0.0}, {0.0}, {{value}}); |
19 | 64 | } |
20 | | |
21 | 23 | TimingArc combinational_arc(const std::string& from, double delay) { |
22 | 23 | return TimingArc(from, "combinational", "non_unate", scalar(delay), scalar(delay), |
23 | 23 | std::nullopt, std::nullopt, std::nullopt, std::nullopt); |
24 | 23 | } |
25 | | |
26 | 4 | TimingArc clock_to_q_arc(const std::string& clock) { |
27 | 4 | return TimingArc(clock, "rising_edge", "non_unate", scalar(kClockToQ), |
28 | 4 | scalar(kClockToQ), std::nullopt, std::nullopt, std::nullopt, |
29 | 4 | std::nullopt); |
30 | 4 | } |
31 | | |
32 | 5 | TimingArc setup_arc(const std::string& clock) { |
33 | 5 | return TimingArc(clock, "setup_rising", "non_unate", std::nullopt, std::nullopt, |
34 | 5 | std::nullopt, std::nullopt, scalar(kSetup), scalar(kSetup)); |
35 | 5 | } |
36 | | |
37 | 37 | CellPin input_pin(const std::string& name, std::vector<TimingArc> arcs = {}) { |
38 | 37 | return CellPin(name, "input", "", kPinCapacitance, std::move(arcs)); |
39 | 37 | } |
40 | | |
41 | 14 | CellPin output_pin(const std::string& name, std::vector<TimingArc> arcs) { |
42 | 14 | return CellPin(name, "output", "", std::nullopt, std::move(arcs)); |
43 | 14 | } |
44 | | |
45 | 6 | StandardCell lut_cell(std::size_t inputs) { |
46 | 6 | const double delay = 0.12 + 0.06 * static_cast<double>(inputs > 2 ? inputs - 2 : 0); |
47 | 6 | std::vector<CellPin> pins; |
48 | 6 | std::vector<TimingArc> arcs; |
49 | 27 | for (std::size_t i = 0; i < inputs; ++i) { |
50 | 21 | pins.push_back(input_pin("I" + std::to_string(i))); |
51 | 21 | arcs.push_back(combinational_arc("I" + std::to_string(i), delay)); |
52 | 21 | } |
53 | 6 | pins.push_back(output_pin("O", std::move(arcs))); |
54 | 6 | return StandardCell("LUT" + std::to_string(inputs), |
55 | 6 | static_cast<double>(1U << inputs), std::move(pins)); |
56 | 6 | } |
57 | | |
58 | | StandardCell flop_cell(const std::string& name, double area, |
59 | 4 | const std::vector<std::string>& controls) { |
60 | 4 | std::vector<CellPin> pins = {input_pin("D", {setup_arc("CLK")}), |
61 | 4 | input_pin("CLK")}; |
62 | 4 | for (const auto& control : controls) pins.push_back(input_pin(control)); |
63 | 4 | pins.push_back(output_pin("Y", {clock_to_q_arc("CLK")})); |
64 | 4 | return StandardCell(name, area, std::move(pins)); |
65 | 4 | } |
66 | | |
67 | | } // namespace |
68 | | |
69 | 4 | const StandardCellLibrary& get_default_fpga_library() { |
70 | 4 | static const StandardCellLibrary library = [] { |
71 | 1 | std::vector<StandardCell> cells; |
72 | 7 | for (std::size_t inputs = 1; inputs <= 6; ++inputs) cells.push_back(lut_cell(inputs)); |
73 | 1 | cells.push_back(flop_cell("DFF", 16.0, {})); |
74 | 1 | cells.push_back(flop_cell("DFFR", 18.0, {"RESET_B"})); |
75 | 1 | cells.push_back(flop_cell("DFFS", 18.0, {"SET_B"})); |
76 | 1 | cells.push_back(flop_cell("DFFSR", 20.0, {"RESET_B", "SET_B"})); |
77 | 1 | cells.push_back(StandardCell( |
78 | 1 | "LATCH", 12.0, |
79 | 1 | {input_pin("D", {setup_arc("GATE")}), input_pin("GATE"), |
80 | 1 | output_pin("Y", {combinational_arc("D", 0.2)})})); |
81 | 1 | cells.push_back(StandardCell( |
82 | 1 | "TRIBUF", 4.0, |
83 | 1 | {input_pin("A"), input_pin("TE_B"), |
84 | 1 | output_pin("Y", {combinational_arc("A", 0.15)})})); |
85 | 1 | cells.push_back(StandardCell("TIEHI", 0.0, {output_pin("Y", {})})); |
86 | 1 | cells.push_back(StandardCell("TIELO", 0.0, {output_pin("Y", {})})); |
87 | 1 | return StandardCellLibrary("labneura_generic_fpga", "1ns", "1pf", std::move(cells)); |
88 | 1 | }(); |
89 | 4 | return library; |
90 | 4 | } |
91 | | |
92 | | } // namespace labneura::eda |