A circuit containing multiplexer drawn using tikz (pgf)

Circuit drawn using tikz

[sourcecode language="text"]
documentclass{article}
usepackage{tikz,pgf}
usetikzlibrary{circuits.logic.US}
usetikzlibrary{arrows}
begin{document}
begin{figure}[h]
begin{tikzpicture}[circuit logic US]
%% draw[help lines, draw, very thin, step=0.5cm, color=gray!20] (0,-10) grid +(10,10);
defmux { — ++(0,-1) node [above right] {$1$} — ++(0.6,0.2) —
++(0,0.6) — ++(-0.6,0.2) — cycle};
defmuxr { — node [below left] {$1$} ++(1,0) — ++(-0.2,-0.6) —
++(-0.6,0) — ++(-0.2,0.6) — cycle};
% This node is data node.
node (data) [draw, dotted, minimum width=1.8cm, minimum height=4cm, rectangle] at (0,-1.5) {};
foreach x / id in {0/0, 1.5/k, 3/31}
{
% node represents one row.
node (pbid) [draw, rectangle] at (0,0-x) {PB[id]};
% node represents locationofNonZero element function.
node (lnzid) [draw, circle] at (2,0-x) {LNZ};
% node represent and gate.
node (andid) [and gate] at (3.5,0-x) {};
% node represents isZero function.
node (isZeroid) [draw, circle] at (5,0-x) {isZero};
% node represents mux.
node (muxid) [] at (7,-0.2-x) {};
draw[] ($(isZeroid)+(1.5,0.05)$)mux;
node (zeroid) [] at (6.0,-0.2-x) {$0$};
draw[->, style={->>}] (pbid.east) — node[above right] {$32$} (lnzid.west);
draw[->, style={->>}] ($(pbid.east)+(0.5,0)$) — ++(0,-0.7) — ++(5.45,0);
draw[->, style={->>}] (lnzid.east) — +(0.1,0) |- node[above right] {} (andid.input 1);
draw[->, style={->>}] (andid.output) node [above right] {$32$} — (isZeroid.west);
draw[->, style={->}] (isZeroid.east) — ++(0.3,0) — ++(0.0,0.2) -| ($(muxid.north)+(-0.2,0.0)$);
draw[->, style={->>}] (zeroid) — ($(muxid.west)+(-0.4,0)$);
};
node (e0) [rectangle] at (0,-0.5) {$vdots$};
node (e0) [rectangle] at (0,-2.0) {$vdots$};
node (xor) [minimum width=2cm, minimum height=4cm
, rectangle, draw ] at (9,-1.7) {XOR tree};
draw[->, style={->>}] ($(mux0.east)+(0,-0.2)$) — ++(right:3mm) |- ($(xor.west)+(0,1)$);
draw[->, style={->>}] ($(muxk.east)+(0,-0.2)$) — ++(right:3mm) |- ($(xor.west)+(0,0)$);
draw[->, style={->>}] ($(mux31.east)+(0,-0.2)$ — ++(0.5,0) |- ($(xor.west)+(0,-1)$);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% section two of image
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node (rcrb) [draw,rectangle] at (0, -4.8) {REDUCED_CR};
node (muxb) [rectangle, minimum height=1cm] at ($(rcrb.west)+(2.5,-1.5)$) {};
draw[] ($(rcrb.west)+(2.0,-1.0)$)muxr;
node (zerob) [ ] at ($(muxb)+(0.75,0.75)$) {0};
node (xorb) [draw, circle] at ($(muxb)+(0,-1)$) {$+$};
node (iszerob) [draw, circle] at ($(muxb)+(-2,0.2)$) {isZero};
node (andb) [and gate, rotate=90] at ($(iszerob)+(0,-1.5)$) {};
node (pbk) [draw, rectangle] at ($(xorb)+(1,-1)$) {PB[k]};
node (lnzb) [draw, circle] at ($(andb)+(-0.1,-1.5)$) {LNZ};
draw[->, style={->>}] (rcrb.south) — +(0,-0.5) -| node[below left]{32} ($(muxb.north)+(-.3,0)$);
draw[->, style={->>}] ($(zerob.west)+(0,0)$) ++(-0.1,0) -| ($(muxb.north)+(+.3,0)$);
draw[->, style={->>}] ($(muxb.south)+(-0,0.4)$) — (xorb.north);
draw[->, style={->>}] (xorb.east) — ++(0.5,0) -| (pbk.north);
draw[->, style={-}] (xorb.west) — ++(-0.5,0) |- (pbk.west);
draw[->, style={->}] (iszerob.east) — ($(muxb.west)+(-0.3,0.2)$);
draw[->, style={->>}] (lnzb.north) — node[above left] {32} (andb.input 1);
draw[->, style={->>}] (pbk.west) -| node [above right] {32} (andb.input 2);
draw[->, style={->>}] (andb.output) — (iszerob.south);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% section three of image
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
node (crc) [rectangle, minimum width=2cm, draw] at ($(rcrb)+(4,0)$) {CR};
node (xorc) [draw, circle] at ($(crc)+(.5,-1.5)$) {$+$};
node (rcrc) [draw, rectangle] at ($(xorc)+(0,-1)$) {REDUCED_CR};
node (iszeroc) [draw, circle] at ($(rcrc)+(0,-1.5)$) {isZero};
node (muxc) [ minimum height=1cm, rectangle] at ($(crc)+(3,-.5)$) {};
draw[] ($(crc)+(2.5,-1)$)mux;
node (muxc) [ minimum height=1cm, rectangle] at ($(crc)+(3,-.5)$) {};
node (pbc) [draw,rectangle] at ($(muxc)+(1.7,-1)$) {PB[count+1]};
node (zeroc) [] at ($(muxc)+(-.9,-0.75)$) {0};
draw[->, style={->>}] (crc.west) — ++(-0.2,0) |- (and0.input 2);
draw[->, style={->>}] (crc.west) — ++(-0.2,0) |- (and31.input 2);
draw[->, style={->>}] (crc.west) — ++(-0.2,0) |- (andk.input 2);
draw[->, style={->>}] (rcrc.south) +(-1.2,0) |- node[above, near end] {32} (lnzb.east);
draw[->, style={->>}] (crc.south) — +(0,-0.5) -| node[below right] {32} (xorc.north);
draw[->, style={->>}] (xorc.south) — (rcrc.north);
draw[->, style={->>}] (rcrc.east) — ++(0.2,0) |- ($(muxc.west)+(-0.4,-1.2)$);
draw[->, style={->>}] ($(muxc.east)+(0,-1)$) — ++(0.2,0) |- (pbc.west);
draw[->, style={->>}] (rcrc.south) — (iszeroc.north);
draw[->, style={->}] (iszeroc.east) -| ($(muxc.west)+(-0.1,-1.4)$);
draw[->, style={->>}] (zeroc.east) — ++(0.2,0);
draw[->, style={->>}] (xor.south) |- ++(-3.5,-1) |- node[below left] {32} ($(xorc.east)$);
end{tikzpicture}
end{figure}
end{document}
[/sourcecode]

Leave a Reply

Scroll to Top