forked from steveicarus/iverilog
/
draw_mux.c
200 lines (170 loc) · 5.61 KB
/
draw_mux.c
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Copyright (c) 2002 Stephen Williams (steve@icarus.com)
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: draw_mux.c,v 1.6 2003/02/25 03:40:45 steve Exp $"
#endif
# include "vvp_priv.h"
# include <assert.h>
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
# include <stdlib.h>
# include <string.h>
/*
* This draws a general mux, a slice at a time. Use MUXX so that
* unknows lead to unknown output.
*/
static void draw_lpm_mux_bitslice(ivl_lpm_t net, unsigned slice)
{
unsigned sel = ivl_lpm_selects(net);
unsigned size = ivl_lpm_size(net);
unsigned sel_from_size;
unsigned seldx, idx;
ivl_nexus_t s;
sel_from_size = 0;
seldx = size - 1;
while (seldx > 0) {
seldx >>= 1;
sel_from_size += 1;
}
if (sel_from_size > sel) {
fprintf(stderr, "internal error: MUX size=%u, selects=%u\n",
size, sel);
}
assert(sel_from_size <= sel);
s = ivl_lpm_select(net, 0);
/* Draw the leaf mux devices that take inputs from the
net. These also use up the least significant bit of the
select vector. */
for (idx = 0 ; idx < size ; idx += 2) {
fprintf(vvp_out, "L_%s.%s/%u/%u/%u .functor MUXX, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)), slice, sel, idx);
{
ivl_nexus_t a = ivl_lpm_data2(net, idx+0, slice);
draw_input_from_net(a);
fprintf(vvp_out, ", ");
}
if ((idx+1) < size) {
ivl_nexus_t b = ivl_lpm_data2(net, idx+1, slice);
draw_input_from_net(b);
fprintf(vvp_out, ", ");
} else {
fprintf(vvp_out, "C<x>, ");
}
draw_input_from_net(s);
fprintf(vvp_out, ", C<1>;\n");
}
/* Draw the tree of MUXX devices to connect the inner tree
nodes. */
for (seldx = 1 ; seldx < (sel-1) ; seldx += 1) {
unsigned level = sel - seldx;
unsigned span = 2 << seldx;
s = ivl_lpm_select(net, seldx);
for (idx = 0 ; idx < size ; idx += span) {
fprintf(vvp_out, "L_%s.%s/%u/%u/%u .functor MUXX, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)),
slice, level, idx);
fprintf(vvp_out, "L_%s.%s/%u/%u/%u, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)),
slice, level+1, idx);
if ((idx + span/2) < size) {
fprintf(vvp_out, "L_%s.%s/%u/%u/%u, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)),
slice, level+1, idx+span/2);
} else {
fprintf(vvp_out, "C<x>, ");
}
draw_input_from_net(s);
fprintf(vvp_out, ", C<1>;\n");
}
}
s = ivl_lpm_select(net, sel-1);
fprintf(vvp_out, "L_%s.%s/%u .functor MUXX, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)), slice);
fprintf(vvp_out, "L_%s.%s/%u/2/0, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)), slice);
if ((2 << (sel-1))/2 < size) {
fprintf(vvp_out, "L_%s.%s/%u/2/%u, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)),
slice, (2 << (sel-1))/2);
} else {
fprintf(vvp_out, "C<x>, ");
}
draw_input_from_net(s);
fprintf(vvp_out, ", C<1>;\n");
}
/*
* This draws a simple A/B mux. The mux can have any width, enough
* MUXZ nodes are created to support the vector.
*/
static void draw_lpm_mux_ab(ivl_lpm_t net)
{
ivl_nexus_t s;
unsigned idx, width;
/* Only support A-B muxes at this oint. */
assert(ivl_lpm_size(net) == 2);
assert(ivl_lpm_selects(net) == 1);
width = ivl_lpm_width(net);
s = ivl_lpm_select(net, 0);
for (idx = 0 ; idx < width ; idx += 1) {
ivl_nexus_t a = ivl_lpm_data2(net, 0, idx);
ivl_nexus_t b = ivl_lpm_data2(net, 1, idx);
fprintf(vvp_out, "L_%s.%s/%u .functor MUXZ, ",
vvp_mangle_id(ivl_scope_name(ivl_lpm_scope(net))),
vvp_mangle_id(ivl_lpm_basename(net)), idx);
draw_input_from_net(a);
fprintf(vvp_out, ", ");
draw_input_from_net(b);
fprintf(vvp_out, ", ");
draw_input_from_net(s);
fprintf(vvp_out, ", C<1>;\n");
}
}
void draw_lpm_mux(ivl_lpm_t net)
{
unsigned idx;
if ((ivl_lpm_size(net) == 2) && (ivl_lpm_selects(net) == 1)) {
draw_lpm_mux_ab(net);
return;
}
for (idx = 0 ; idx < ivl_lpm_width(net) ; idx += 1)
draw_lpm_mux_bitslice(net, idx);
}
/*
* $Log: draw_mux.c,v $
* Revision 1.6 2003/02/25 03:40:45 steve
* Eliminate use of ivl_lpm_name function.
*
* Revision 1.5 2002/08/29 03:04:01 steve
* Generate x out for x select on wide muxes.
*
* Revision 1.4 2002/08/12 01:35:03 steve
* conditional ident string using autoconfig.
*
* Revision 1.3 2002/08/11 23:47:04 steve
* Add missing Log and Ident strings.
*
*/