[Tex/LaTex] Drawing custom logic gates with circuitikz or circuits.logic library

circuitikzcircuitstikz-circuit-libtikz-pgf

Is it possible to draw custom logic gates like the following one using circuitikz?

this

Alternatively, is it possible to draw them easily with the circuits.logic library in tikz?

Best Answer

Here you have a possible solution. It uses a trapezium shape as reference to draw the ALU.

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning, calc}

\begin{document}
\begin{tikzpicture}[%
    alu/.style={trapezium,
            trapezium angle=30,
            shape border rotate=180,
            minimum width=4cm,
            minimum height=3cm,
            trapezium stretches=true,
            append after command={%
                    \pgfextra
                        \draw (\tikzlastnode.top left corner) --
                           (\tikzlastnode.top right corner) -- 
                           (\tikzlastnode.bottom right corner) -- 
                           ($(\tikzlastnode.bottom right corner)!.666!(\tikzlastnode.bottom side)$)--
                           ([yshift=-8mm]\tikzlastnode.bottom side)--
                           ($(\tikzlastnode.bottom side)!.334!(\tikzlastnode.bottom left corner)$)--
                           (\tikzlastnode.bottom left corner)--
                           (\tikzlastnode.top left corner);
                    \endpgfextra}},
            ]

\node[alu] (alu) {ADDER($n$)};
\draw (alu.south) -- ++(-90:5mm) node [below] (out) {$S[n-1:0]$};
\draw (alu.20) -- ++(0:5mm) node [right] {$C[0]$};
\draw (alu.50) -- ++(90:5mm) node [above] {$B[n-1:0]$};
\draw (alu.130) -- ++(90:5mm) node [above] {$A[n-1:0]$};
\draw (alu.130) -- ++(90:5mm) node [above] {$A[n-1:0]$};
\node[left=8mm of out] (carry) {$C[n]$};
\draw (carry) |- (alu.200);
\end{tikzpicture}
\end{document}

enter image description here