2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2018 Miodrag Milanovic <miodrag@symbioticeda.com>
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.
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.
20 #include "kernel/yosys.h"
21 #include "kernel/sigtools.h"
24 PRIVATE_NAMESPACE_BEGIN
26 struct AnlogicEqnPass
: public Pass
{
27 AnlogicEqnPass() : Pass("anlogic_eqn", "Anlogic: Calculate equations for luts") { }
28 void help() YS_OVERRIDE
31 log(" anlogic_eqn [selection]\n");
33 log("Calculate equations for luts since bitstream generator depends on it.\n");
37 Const
init2eqn(Const init
, int inputs
)
39 std::string init_bits
= init
.as_string();
40 const char* names
[] = { "A" , "B", "C", "D", "E", "F" };
43 int width
= (int)pow(2,inputs
);
44 for(int i
=0;i
<width
;i
++)
46 if (init_bits
[width
-1-i
]=='1')
49 for(int j
=0;j
<inputs
;j
++)
54 eqn
+= std::string("~") + names
[j
];
56 if (j
!=(inputs
-1)) eqn
+= "*";
61 if (eqn
.empty()) return Const("0");
62 eqn
= eqn
.substr(0, eqn
.length()-1);
66 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
68 log_header(design
, "Executing ANLOGIC_EQN pass (calculate equations for luts).\n");
70 extra_args(args
, args
.size(), design
);
73 for (auto module
: design
->selected_modules())
75 for (auto cell
: module
->selected_cells())
77 if (cell
->type
== ID(AL_MAP_LUT1
))
79 cell
->setParam(ID(EQN
), init2eqn(cell
->getParam(ID::INIT
),1));
82 if (cell
->type
== ID(AL_MAP_LUT2
))
84 cell
->setParam(ID(EQN
), init2eqn(cell
->getParam(ID::INIT
),2));
87 if (cell
->type
== ID(AL_MAP_LUT3
))
89 cell
->setParam(ID(EQN
), init2eqn(cell
->getParam(ID::INIT
),3));
92 if (cell
->type
== ID(AL_MAP_LUT4
))
94 cell
->setParam(ID(EQN
), init2eqn(cell
->getParam(ID::INIT
),4));
97 if (cell
->type
== ID(AL_MAP_LUT5
))
99 cell
->setParam(ID(EQN
), init2eqn(cell
->getParam(ID::INIT
),5));
102 if (cell
->type
== ID(AL_MAP_LUT6
))
104 cell
->setParam(ID(EQN
), init2eqn(cell
->getParam(ID::INIT
),6));
109 log_header(design
, "Updated %d of AL_MAP_LUT* elements with equation.\n", cnt
);
113 PRIVATE_NAMESPACE_END