abc9: generate $abc9_holes design instead of <name>$holes
[yosys.git] / techlibs / anlogic / anlogic_eqn.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 *
18 */
19
20 #include "kernel/yosys.h"
21 #include "kernel/sigtools.h"
22
23 USING_YOSYS_NAMESPACE
24 PRIVATE_NAMESPACE_BEGIN
25
26 struct AnlogicEqnPass : public Pass {
27 AnlogicEqnPass() : Pass("anlogic_eqn", "Anlogic: Calculate equations for luts") { }
28 void help() YS_OVERRIDE
29 {
30 log("\n");
31 log(" anlogic_eqn [selection]\n");
32 log("\n");
33 log("Calculate equations for luts since bitstream generator depends on it.\n");
34 log("\n");
35 }
36
37 Const init2eqn(Const init, int inputs)
38 {
39 std::string init_bits = init.as_string();
40 const char* names[] = { "A" , "B", "C", "D", "E", "F" };
41
42 std::string eqn;
43 int width = (int)pow(2,inputs);
44 for(int i=0;i<width;i++)
45 {
46 if (init_bits[width-1-i]=='1')
47 {
48 eqn += "(";
49 for(int j=0;j<inputs;j++)
50 {
51 if (i & (1<<j))
52 eqn += names[j];
53 else
54 eqn += std::string("~") + names[j];
55
56 if (j!=(inputs-1)) eqn += "*";
57 }
58 eqn += ")+";
59 }
60 }
61 if (eqn.empty()) return Const("0");
62 eqn = eqn.substr(0, eqn.length()-1);
63 return Const(eqn);
64 }
65
66 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
67 {
68 log_header(design, "Executing ANLOGIC_EQN pass (calculate equations for luts).\n");
69
70 extra_args(args, args.size(), design);
71
72 int cnt = 0;
73 for (auto module : design->selected_modules())
74 {
75 for (auto cell : module->selected_cells())
76 {
77 if (cell->type == ID(AL_MAP_LUT1))
78 {
79 cell->setParam(ID(EQN), init2eqn(cell->getParam(ID::INIT),1));
80 cnt++;
81 }
82 if (cell->type == ID(AL_MAP_LUT2))
83 {
84 cell->setParam(ID(EQN), init2eqn(cell->getParam(ID::INIT),2));
85 cnt++;
86 }
87 if (cell->type == ID(AL_MAP_LUT3))
88 {
89 cell->setParam(ID(EQN), init2eqn(cell->getParam(ID::INIT),3));
90 cnt++;
91 }
92 if (cell->type == ID(AL_MAP_LUT4))
93 {
94 cell->setParam(ID(EQN), init2eqn(cell->getParam(ID::INIT),4));
95 cnt++;
96 }
97 if (cell->type == ID(AL_MAP_LUT5))
98 {
99 cell->setParam(ID(EQN), init2eqn(cell->getParam(ID::INIT),5));
100 cnt++;
101 }
102 if (cell->type == ID(AL_MAP_LUT6))
103 {
104 cell->setParam(ID(EQN), init2eqn(cell->getParam(ID::INIT),6));
105 cnt++;
106 }
107 }
108 }
109 log_header(design, "Updated %d of AL_MAP_LUT* elements with equation.\n", cnt);
110 }
111 } AnlogicEqnPass;
112
113 PRIVATE_NAMESPACE_END