🡄 Previous

Next 🡆

Contents > Functions

Equals

The equals function operates on a 3-byte array:

f( [ A, B, X ] ) = [ A, B, E ]

E is 1 if A equals B; otherwise, E is 0. Either way, A and B pass through unchanged, while X is discarded.

E is defined by the following expression, where Ai and Bi are the ith bits of A and B, respectively.

E = (A7 = B7)(A6 = B6)(A5 = B5)(A4 = B4)(A3 = B3)(A2 = B2)(A1 = B1)(A0 = B0)

= A7 ⊕ B7 A6 ⊕ B6 A5 ⊕ B5 A4 ⊕ B4 A3 ⊕ B3 A2 ⊕ B2 A1 ⊕ B1 A0 ⊕ B0

That suggests the following circuit.

E = (A == B)

In the Tetris version below, a constant bit function seeds the AND chain with 1 (see lower-right).

E = (A == B)

Since the evaluation order is established by the sequence in which components are built, each input propagates upward as it advances from left-to-right. The diamond arrangement of swap circuits is a consequence of nearly-parallel, diagonally-upward lines that terminate on the vertical AND chain.

There is a variation of the equals function where the parameters are rearranged:

f( [ X, A, B ] ) = [ E, A, B ]

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

E = (A == B)

Here is the Tetris realization:

E = (A == B)

There is a another variation that uses all three input bytes:

f( [ A, B, V ] ) = [ A, B, E ], where V,E ∈ { 0, 1 }

E is 1 iff A equals B and V is 1:

E = (A = B)V

= (A7 = B7)(A6 = B6)(A5 = B5)(A4 = B4)(A3 = B3)(A2 = B2)(A1 = B1)(A0 = B0)V0

= A7 ⊕ B7 A6 ⊕ B6 A5 ⊕ B5 A4 ⊕ B4 A3 ⊕ B3 A2 ⊕ B2 A1 ⊕ B1 A0 ⊕ B0 V0

It provides a way to compare multiple bytes:

V = (T = U)

V′ = (R = S)V = (R = S)(T = U)

V″ = (P = Q)V′ = (P = Q)(R = S)(T = U)

And so on.

The variation can be realized by using the lowest bit of V as the seed of the AND chain. Instead, in an effort to reuse wherever possible, an AND gate was added to the top of the existing circuit:

E = (A == B) V

The Tetris implementation follows.

E = (A == B) V

The horizontal-reflection of this variation was not implemented.

🡄 Previous

Next 🡆