// CD4063B: 4-bit magnitude comparator, pin-compatible with the 7485.
//
// Ports in pin order, named as in the datasheet.  The power pins, VSS (8)
// and VDD (16), are left out.  Synthesizable.
//
// When the two words differ, A>B or A<B is 1.  When they are equal, the
// outputs copy the cascading inputs, which come from the next less
// significant comparator.  A single chip gets A<B = 0, A=B = 1, A>B = 0.

module cd4063
(
    input  logic b3,      // Pin 1
    input  logic lt_in,   // Pin 2:  cascading input A<B
    input  logic eq_in,   // Pin 3:  cascading input A=B
    input  logic gt_in,   // Pin 4:  cascading input A>B
    output logic gt_out,  // Pin 5:  A>B
    output logic eq_out,  // Pin 6:  A=B
    output logic lt_out,  // Pin 7:  A<B
                          // Pin 8:  VSS
    input  logic b0,      // Pin 9
    input  logic a0,      // Pin 10
    input  logic b1,      // Pin 11
    input  logic a1,      // Pin 12
    input  logic a2,      // Pin 13
    input  logic b2,      // Pin 14
    input  logic a3       // Pin 15
                          // Pin 16: VDD
);

    wire [3:0] a = { a3, a2, a1, a0 };
    wire [3:0] b = { b3, b2, b1, b0 };

    assign gt_out = a > b | a == b & gt_in;
    assign lt_out = a < b | a == b & lt_in;
    assign eq_out =         a == b & eq_in;

endmodule
