## Byte Match

The byte match function operates on a 2-byte array:

f( [A, X] ) = [ A, M ]

A is compared against a bit pattern. If it matches, M is 1; otherwise, M is 0. In either case, A passes through unchanged, while X is discarded.

The bit pattern consists of zeros, ones, and don’t-cares. Meaning, each bit of A, Ai, is either compared against a constant or it is ignored. For example, the following expression checks if all Ai are 1:

M = A7 A6 A5 A4 A3 A2 A1 A0 = A7 + A6 + A5 + A4 + A3 + A2 + A1 + A0

That suggests the following circuit.

Each Ai column contains an inverter pair, which enables A to traverse unmodified. For an arbitrary constant, K, inverter pairs only exist in the columns where Ki is 1. For instance, the expression below checks if A is 0:

M = A7 A6 A5 A4 A3 A2 A1 A0 = A7 + A6 + A5 + A4 + A3 + A2 + A1 + A0

It requires no inverter pairs, as illustrated by the Tetris realization:

Horizontal J-tetrominoes operate as OR gates. Each feeds an input bit to both terminals of a swap circuit.

The following expression checks if A is binary value 00101111.

M = A7 A6 A5 A4 A3 A2 A1 A0 = A7 + A6 + A5 + A4 + A3 + A2 + A1 + A0

It is actualized by introducing inverter pairs corresponding to the 1 bits:

Don’t-care bits are omitted from the OR chain. For instance, the following expression tests if A is 000000**.

M = A7 A6 A5 A4 A3 A2 = A7 + A6 + A5 + A4 + A3 + A2

In the Tetris realization below, two of the horizontal J-tetrominoes are absent, enabling A1 and A0 to cross the OR chain without contributing to it.

There is a variation of the byte match function where the parameters are swapped:

f( [X, A] ) = [ M, A ]

Its circuit is nearly the horizontal-reflection of the one above:

In the Tetris version below, the inverter pairs are omitted, resulting in a zero detector.