LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
entity sort4mm is
generic(Nbits : Natural := 8;
Nidx : Natural := 2;
ipipe : Boolean := false;
mpipe : Boolean := false;
opipe : Boolean := false);
port(
clk : in std_logic;
dat0i : in std_logic_vector(Nbits+Nidx-1 downto 0);
dat1i : in std_logic_vector(Nbits+Nidx-1 downto 0);
dat2i : in std_logic_vector(Nbits+Nidx-1 downto 0);
dat3i : in std_logic_vector(Nbits+Nidx-1 downto 0);
dat0o : out std_logic_vector(Nbits+Nidx-1 downto 0);
dat1o : out std_logic_vector(Nbits+Nidx-1 downto 0);
dat2o : out std_logic_vector(Nbits+Nidx-1 downto 0);
dat3o : out std_logic_vector(Nbits+Nidx-1 downto 0));
end sort4mm;
architecture struct of sort4mm is
component dff_array is
generic (N : Natural := 4);
port (
clk : in std_logic;
d : in std_logic_vector(N-1 downto 0);
q : out std_logic_vector(N-1 downto 0) );
end component;
component sort2 is
generic(Nbits : Natural := 8;
Nidx : Natural := 4);
port(
dat0i : in std_logic_vector(Nbits+Nidx-1 downto 0);
dat1i : in std_logic_vector(Nbits+Nidx-1 downto 0);
dat0o : out std_logic_vector(Nbits+Nidx-1 downto 0);
dat1o : out std_logic_vector(Nbits+Nidx-1 downto 0));
end component;
signal dat0s , dat1s , dat2s , dat3s : std_logic_vector(Nbits+Nidx-1 downto 0);
signal dat0o1, dat1o1, dat2o1, dat3o1 : std_logic_vector(Nbits+Nidx-1 downto 0);
signal dat0m , dat1m , dat2m , dat3m : std_logic_vector(Nbits+Nidx-1 downto 0);
signal dat0o2, dat1o2, dat2o2, dat3o2 : std_logic_vector(Nbits+Nidx-1 downto 0);
signal dat1o3, dat2o3 : std_logic_vector(Nbits+Nidx-1 downto 0);
begin
ip1: if ipipe generate
ir0: dff_array
generic map(N => dat0i'length)
port map(
clk => clk,
d => dat0i,
q => dat0s);
ir1: dff_array
generic map(N => dat1i'length)
port map(
clk => clk,
d => dat1i,
q => dat1s);
ir2: dff_array
generic map(N => dat2i'length)
port map(
clk => clk,
d => dat2i,
q => dat2s);
ir3: dff_array
generic map(N => dat3i'length)
port map(
clk => clk,
d => dat3i,
q => dat3s);
end generate;
nip1: if not ipipe generate
dat0s <= dat0i;
dat1s <= dat1i;
dat2s <= dat2i;
dat3s <= dat3i;
end generate;
u1u : sort2
generic map(Nbits => Nbits,
Nidx => Nidx)
port map(
dat0i => dat0s,
dat1i => dat1s,
dat0o => dat0o1,
dat1o => dat1o1);
u1d : sort2
generic map(Nbits => Nbits,
Nidx => Nidx)
port map(
dat0i => dat2s,
dat1i => dat3s,
dat0o => dat2o1,
dat1o => dat3o1);
mp1: if mpipe generate
mr0: dff_array
generic map(N => dat0i'length)
port map(
clk => clk,
d => dat0o1,
q => dat0m);
mr1: dff_array
generic map(N => dat1i'length)
port map(
clk => clk,
d => dat1o1,
q => dat1m);
mr2: dff_array
generic map(N => dat2i'length)
port map(
clk => clk,
d => dat2o1,
q => dat2m);
mr3: dff_array
generic map(N => dat3i'length)
port map(
clk => clk,
d => dat3o1,
q => dat3m);
end generate;
nmp1: if not mpipe generate
dat0m <= dat0o1;
dat1m <= dat1o1;
dat2m <= dat2o1;
dat3m <= dat3o1;
end generate;
u2u : sort2
generic map(Nbits => Nbits,
Nidx => Nidx)
port map(
dat0i => dat0m,
dat1i => dat2m,
dat0o => dat0o2,
dat1o => dat1o2);
u2d : sort2
generic map(Nbits => Nbits,
Nidx => Nidx)
port map(
dat0i => dat1m,
dat1i => dat3m,
dat0o => dat2o2,
dat1o => dat3o2);
u3m : sort2
generic map(Nbits => Nbits,
Nidx => Nidx)
port map(
dat0i => dat1o2,
dat1i => dat2o2,
dat0o => dat1o3,
dat1o => dat2o3);
op1: if opipe generate
or0: dff_array
generic map(N => dat0o'length)
port map(
clk => clk,
d => dat0o2,
q => dat0o);
or1: dff_array
generic map(N => dat1o'length)
port map(
clk => clk,
d => dat1o3,
q => dat1o);
or2: dff_array
generic map(N => dat2o'length)
port map(
clk => clk,
d => dat2o3,
q => dat2o);
or3: dff_array
generic map(N => dat3o'length)
port map(
clk => clk,
d => dat3o2,
q => dat3o);
end generate;
nop1: if not opipe generate
dat0o <= dat0o2;
dat1o <= dat1o3;
dat2o <= dat2o3;
dat3o <= dat3o2;
end generate;
end;