Pre lab 9
1.
module bit_sorter(
input a,
input b,
output reg x,
output reg y
);
always @(*) begin
if (a <= b) begin
x = a;
y = b;
end else begin
x = b;
y = a;
end
end
endmodule
2.
module bitonic_sorter(
input [3:0] A, B, C, D,
output [3:0] U, V, W, X
);
wire [1:0] P0, P1, P2, P3, P4, P5;
bit_sorter bs0(A[0], B[0], P0[0], P0[1]);
bit_sorter bs1(A[1], B[1], P1[0], P1[1]);
bit_sorter bs2(A[2], B[2], P2[0], P2[1]);
bit_sorter bs3(A[3], B[3], P3[0], P3[1]);
bit_sorter bs4(C[0], D[0], P4[0], P4[1]);
bit_sorter bs5(C[1], D[1], P5[0], P5[1]);
bit_sorter bs6(P0[0], P4[0], U[0], V[0]);
bit_sorter bs7(P1[0], P5[0], W[0], X[0]);
bit_sorter bs8(P0[1], P4[1], U[1], V[1]);
bit_sorter bs9(P1[1], P5[1], W[1], X[1]);
bit_sorter bs10(P2[0], P4[0], U[2], V[2]);
bit_sorter bs11(P3[0], P5[0], W[2], X[2]);
bit_sorter bs12(P2[1], P4[1], U[3], V[3]);
bit_sorter bs13(P3[1], P5[1], W[3], X[3]);
endmodule