2 * Copyright (c) 2002 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: draw_mux.c,v 1.14 2007/01/16 05:44:16 steve Exp $"
23 # include "vvp_priv.h"
33 * This draws a simple A/B mux. The mux can have any width, enough
34 * MUXZ nodes are created to support the vector.
36 static void draw_lpm_mux_ab(ivl_lpm_t net
, const char*muxz
)
38 unsigned width
= ivl_lpm_width(net
);
40 /* Only support A-B muxes in this function. */
41 assert(ivl_lpm_size(net
) == 2);
42 assert(ivl_lpm_selects(net
) == 1);
44 fprintf(vvp_out
, "L_%p .functor %s %u", net
, muxz
, width
);
45 fprintf(vvp_out
, ", %s", draw_input_from_net(ivl_lpm_data(net
,0)));
46 fprintf(vvp_out
, ", %s", draw_input_from_net(ivl_lpm_data(net
,1)));
47 fprintf(vvp_out
, ", %s", draw_input_from_net(ivl_lpm_select(net
)));
48 fprintf(vvp_out
, ", C4<>;\n");
51 static void draw_lpm_mux_nest(ivl_lpm_t net
, const char*muxz
)
54 unsigned width
= ivl_lpm_width(net
);
55 unsigned swidth
= ivl_lpm_selects(net
);
58 assert(ivl_lpm_size(net
) == (1 << swidth
));
60 select_input
= strdup(draw_net_input(ivl_lpm_select(net
)));
62 fprintf(vvp_out
, "L_%p/0s .part %s, 0, 1; Bit 0 of the select\n",
65 for (idx
= 0 ; idx
< ivl_lpm_size(net
) ; idx
+= 2) {
66 fprintf(vvp_out
, "L_%p/0/%d .functor %s %u",
67 net
, idx
/2, muxz
, width
);
68 fprintf(vvp_out
, ", %s", draw_net_input(ivl_lpm_data(net
,idx
+0)));
69 fprintf(vvp_out
, ", %s", draw_net_input(ivl_lpm_data(net
,idx
+1)));
70 fprintf(vvp_out
, ", L_%p/0s, C4<>;\n", net
);
73 for (level
= 1 ; level
< swidth
-1 ; level
+= 1) {
74 fprintf(vvp_out
, "L_%p/%ds .part %s, %d, 1;\n",
75 net
, level
, select_input
, level
);
77 for (idx
= 0 ; idx
< (ivl_lpm_size(net
) >> level
); idx
+= 2) {
78 fprintf(vvp_out
, "L_%p/%d/%d .functor %s %u",
79 net
, level
, idx
/2, muxz
, width
);
80 fprintf(vvp_out
, ", L_%p/%d/%d", net
, level
-1, idx
+0);
81 fprintf(vvp_out
, ", L_%p/%d/%d", net
, level
-1, idx
+1);
82 fprintf(vvp_out
, ", L_%p/%ds", net
, level
);
83 fprintf(vvp_out
, ", C4<>;\n");
89 fprintf(vvp_out
, "L_%p/%ds .part %s, %d, 1; Bit %d of the select\n",
90 net
, swidth
-1, select_input
, swidth
-1, swidth
-1);
93 fprintf(vvp_out
, "L_%p .functor %s %u", net
, muxz
, width
);
94 fprintf(vvp_out
, ", L_%p/%d/0", net
, swidth
-2);
95 fprintf(vvp_out
, ", L_%p/%d/1", net
, swidth
-2);
96 fprintf(vvp_out
, ", L_%p/%ds", net
, swidth
-1);
97 fprintf(vvp_out
, ", C4<>;\n");
102 void draw_lpm_mux(ivl_lpm_t net
)
104 const char*muxz
= "MUXZ";
106 /* The output of the mux defines the type of the mux. the
107 ivl_target should guarantee that all the inputs are the
108 same type as the output. */
109 switch (data_type_of_nexus(ivl_lpm_q(net
,0))) {
118 if ((ivl_lpm_size(net
) == 2) && (ivl_lpm_selects(net
) == 1)) {
119 draw_lpm_mux_ab(net
, muxz
);
123 /* Here we are at the worst case, we generate a tree of MUXZ
124 devices to handle the arbitrary size. */
125 draw_lpm_mux_nest(net
, muxz
);
129 * $Log: draw_mux.c,v $
130 * Revision 1.14 2007/01/16 05:44:16 steve
131 * Major rework of array handling. Memories are replaced with the
132 * more general concept of arrays. The NetMemory and NetEMemory
133 * classes are removed from the ivl core program, and the IVL_LPM_RAM
134 * lpm type is removed from the ivl_target API.
136 * Revision 1.13 2005/10/12 17:26:17 steve
137 * MUX nodes get inputs from nets, not from net inputs,
138 * Detect and draw alias nodes to reduce net size and
139 * handle force confusion.
141 * Revision 1.12 2005/09/01 04:11:37 steve
142 * Generate code to handle real valued muxes.
144 * Revision 1.11 2005/08/27 04:32:08 steve
145 * Handle synthesis of fully packed case statements.
147 * Revision 1.10 2005/06/17 03:46:52 steve
148 * Make functors know their own width.
150 * Revision 1.9 2005/04/06 05:29:09 steve
151 * Rework NetRamDq and IVL_LPM_RAM nodes.
153 * Revision 1.8 2005/02/12 22:54:29 steve
154 * Implement a-b muxes as vector devices
156 * Revision 1.7 2003/12/19 01:27:10 steve
157 * Fix various unsigned compare warnings.
159 * Revision 1.6 2003/02/25 03:40:45 steve
160 * Eliminate use of ivl_lpm_name function.
162 * Revision 1.5 2002/08/29 03:04:01 steve
163 * Generate x out for x select on wide muxes.
165 * Revision 1.4 2002/08/12 01:35:03 steve
166 * conditional ident string using autoconfig.
168 * Revision 1.3 2002/08/11 23:47:04 steve
169 * Add missing Log and Ident strings.