forked from steveicarus/iverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lpm_re_logic.cc
125 lines (108 loc) · 3.32 KB
/
lpm_re_logic.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright (c) 2013 Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "priv.h"
# include "nex_data.h"
# include <cassert>
static bool re_xor(unsigned val)
{
bool flag = false;
for (size_t idx = 0 ; idx < 8*sizeof(val) ; idx += 1) {
if (val&1) flag ^= true;
val >>= 1;
}
return flag;
}
int print_lpm_re_logic(FILE*fd, ivl_lpm_t net)
{
ivl_nexus_t nex_q = ivl_lpm_q(net);
blif_nex_data_t*ned_q = blif_nex_data_t::get_nex_data(nex_q);
ivl_nexus_t nex_d = ivl_lpm_data(net,0);
blif_nex_data_t*ned_d = blif_nex_data_t::get_nex_data(nex_d);
assert(ned_q->get_width() == 1);
fprintf(fd, ".names");
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1) {
fprintf(fd, " %s%s", ned_d->get_name(), ned_d->get_name_index(idx));
}
fprintf(fd, " %s%s\n", ned_q->get_name(), ned_q->get_name_index(0));
switch (ivl_lpm_type(net)) {
case IVL_LPM_RE_AND:
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1)
fputc('1', fd);
fprintf(fd, " 1\n");
break;
case IVL_LPM_RE_OR:
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1) {
for (size_t wid = 0 ; wid < ned_d->get_width() ; wid += 1) {
if (wid==idx)
fputc('1', fd);
else
fputc('-', fd);
}
fprintf(fd, " 1\n");
}
break;
case IVL_LPM_RE_XOR:
assert(ned_d->get_width() < 8*sizeof(unsigned));
for (unsigned val = 0; val < (1U<<ned_d->get_width()); val += 1) {
if (! re_xor(val))
continue;
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1) {
if (val & (1<<idx))
fputc('1', fd);
else
fputc('0', fd);
}
fprintf(fd, " 1\n");
}
break;
case IVL_LPM_RE_NAND:
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1) {
for (size_t wid = 0 ; wid < ned_d->get_width() ; wid += 1) {
if (wid==idx)
fputc('0', fd);
else
fputc('-', fd);
}
fprintf(fd, " 1\n");
}
break;
case IVL_LPM_RE_NOR:
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1)
fputc('0', fd);
fprintf(fd, " 1\n");
break;
case IVL_LPM_RE_XNOR:
assert(ned_d->get_width() < 8*sizeof(unsigned));
for (unsigned val = 0; val < (1U<<ned_d->get_width()); val += 1) {
if (re_xor(val))
continue;
for (size_t idx = 0 ; idx < ned_d->get_width() ; idx += 1) {
if (val & (1<<idx))
fputc('1', fd);
else
fputc('0', fd);
}
fprintf(fd, " 1\n");
}
break;
default:
assert(0);
}
return 0;
}