1 |
2 |
habicht |
--/**************************************************************************************************************
|
2 |
|
|
--*
|
3 |
|
|
--* L Z R W 1 E N C O D E R C O R E
|
4 |
|
|
--*
|
5 |
|
|
--* A high throughput loss less data compression core.
|
6 |
|
|
--*
|
7 |
|
|
--* Copyright 2012-2013 Lukas Schrittwieser (LS)
|
8 |
|
|
--*
|
9 |
|
|
--* This program is free software: you can redistribute it and/or modify
|
10 |
|
|
--* it under the terms of the GNU General Public License as published by
|
11 |
|
|
--* the Free Software Foundation, either version 2 of the License, or
|
12 |
|
|
--* (at your option) any later version.
|
13 |
|
|
--*
|
14 |
|
|
--* This program is distributed in the hope that it will be useful,
|
15 |
|
|
--* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
--* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
--* GNU General Public License for more details.
|
18 |
|
|
--*
|
19 |
|
|
--* You should have received a copy of the GNU General Public License
|
20 |
|
|
--* along with this program; if not, write to the Free Software
|
21 |
|
|
--* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
22 |
|
|
--* Or see <http://www.gnu.org/licenses/>
|
23 |
|
|
--*
|
24 |
|
|
--***************************************************************************************************************
|
25 |
|
|
--*
|
26 |
|
|
--* Change Log:
|
27 |
|
|
--*
|
28 |
|
|
--* Version 1.0 - 2012/6/17 - LS
|
29 |
|
|
--* started file
|
30 |
|
|
--*
|
31 |
|
|
--* Version 1.0 - 2013/04/05 - LS
|
32 |
|
|
--* release
|
33 |
|
|
--*
|
34 |
|
|
--***************************************************************************************************************
|
35 |
|
|
--*
|
36 |
|
|
--* Naming convention: http://dz.ee.ethz.ch/en/information/hdl-help/vhdl-naming-conventions.html
|
37 |
|
|
--*
|
38 |
|
|
--***************************************************************************************************************
|
39 |
|
|
--*
|
40 |
|
|
--* Implements a hash table. The number of entries is fixed to 2048. The entries length is configurable
|
41 |
|
|
--* (up to 18 bits)
|
42 |
|
|
--*
|
43 |
|
|
--***************************************************************************************************************
|
44 |
|
|
library IEEE;
|
45 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
46 |
|
|
use IEEE.numeric_std.all;
|
47 |
|
|
|
48 |
|
|
library UNISIM;
|
49 |
|
|
use UNISIM.VComponents.all;
|
50 |
|
|
|
51 |
|
|
entity HashTable is
|
52 |
|
|
generic (
|
53 |
|
|
entryBitWidth : integer := 12);
|
54 |
|
|
port (
|
55 |
|
|
ClkxCI : in std_logic;
|
56 |
|
|
RstxRI : in std_logic;
|
57 |
|
|
NewEntryxDI : in std_logic_vector(entryBitWidth-1 downto 0); -- new entry
|
58 |
|
|
-- to be stored in the table
|
59 |
|
|
EnWrxSI : in std_logic; -- initiate a write access to hash table
|
60 |
|
|
-- the three bytes that serve as a key
|
61 |
|
|
Key0xDI : in std_logic_vector(7 downto 0);
|
62 |
|
|
Key1xDI : in std_logic_vector(7 downto 0);
|
63 |
|
|
Key2xDI : in std_logic_vector(7 downto 0);
|
64 |
|
|
-- the old entry which was stored under the given keys hash
|
65 |
|
|
OldEntryxDO : out std_logic_vector(entryBitWidth-1 downto 0));
|
66 |
|
|
end HashTable;
|
67 |
|
|
|
68 |
|
|
architecture Behavioral of HashTable is
|
69 |
|
|
|
70 |
|
|
constant HASH_BIT_LEN : integer := 11; -- number of address bits of the hash table
|
71 |
|
|
|
72 |
|
|
constant SEED : integer := 40543; -- seed value for hash algorithm as specified by Ross Williamson
|
73 |
|
|
|
74 |
|
|
constant ZERO : std_logic_vector(17 downto 0) := (others => '0');
|
75 |
|
|
|
76 |
|
|
signal Stage0xS : std_logic_vector(11 downto 0);
|
77 |
|
|
signal Stage1xS : std_logic_vector(15 downto 0);
|
78 |
|
|
|
79 |
|
|
signal ProductxS : integer;
|
80 |
|
|
signal RawHashxS : std_logic_vector(31 downto 0); -- This is the full output which is then truncated
|
81 |
|
|
|
82 |
|
|
signal BRamAddrxD : std_logic_vector(13 downto 0);
|
83 |
|
|
signal TblInxD, TblOutxD : std_logic_vector(17 downto 0); -- data input and out of table memory
|
84 |
|
|
signal BRamWexS : std_logic_vector(3 downto 0);
|
85 |
|
|
signal BRamLDInxD, BRamHDInxD : std_logic_vector(31 downto 0);
|
86 |
|
|
signal BRamLPInxD, BRamHPInxD : std_logic_vector(3 downto 0);
|
87 |
|
|
signal BRamLDOutxD, BRamHDOutxD : std_logic_vector(31 downto 0);
|
88 |
|
|
signal BRamLPOutxD, BRamHPOutxD : std_logic_vector(3 downto 0);
|
89 |
|
|
|
90 |
|
|
begin
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
-- first stage is: ((k0<<4)^k1)
|
94 |
|
|
Stage0xS <= Key0xDI(7 downto 4) & (Key0xDI(3 downto 0) xor Key1xDI(7 downto 4)) & Key1xDI(3 downto 0);
|
95 |
|
|
|
96 |
|
|
-- second stage: (stage0<<4) ^ k2
|
97 |
|
|
Stage1xS <= Stage0xS(11 downto 4) & (Stage0xS(3 downto 0) xor Key2xDI(7 downto 4)) & Key2xDI(3 downto 0);
|
98 |
|
|
|
99 |
|
|
ProductxS <= SEED * to_integer(unsigned(Stage1xS));
|
100 |
|
|
RawHashxS <= std_logic_vector(to_unsigned(ProductxS, 32));
|
101 |
|
|
|
102 |
|
|
-- note: The hash algorithm used by Ross Williamson does not use the last 4
|
103 |
|
|
-- bits, I don't know why. However we keep this
|
104 |
|
|
--HashxD <= RawHashxS(HASH_BIT_LEN+4-1 downto 4);
|
105 |
|
|
BRamAddrxD <= RawHashxS(HASH_BIT_LEN+4-1 downto 4) & ZERO(13-HASH_BIT_LEN downto 0);
|
106 |
|
|
|
107 |
|
|
-- reformat signals to adapt buswidth for memory blocks
|
108 |
|
|
BRamWexS <= EnWrxSI & EnWrxSI & EnWrxSI & EnWrxSI;
|
109 |
|
|
TblInxD <= ZERO(17 downto entryBitWidth) & NewEntryxDI;
|
110 |
|
|
BRamLDInxD <= x"000000" & TblInxD(7 downto 0);
|
111 |
|
|
BRamHDInxD <= x"000000" & TblInxD(16 downto 9);
|
112 |
|
|
BRamLPInxD <= "000" & TblInxD(8);
|
113 |
|
|
BRamHPInxD <= "000" & TblInxD(17);
|
114 |
|
|
|
115 |
|
|
TblOutxD <= BRamHPOutxD(0) & BRamHDOutxD(7 downto 0) & BRamLPOutxD(0) & BRamLDOutxD(7 downto 0);
|
116 |
|
|
OldEntryxDO <= TblOutxD(entryBitWidth-1 downto 0);
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
-- lower byte of hash table. Only port A is used
|
120 |
|
|
hashTableMemLowInst : RAMB16BWER
|
121 |
|
|
generic map (
|
122 |
|
|
-- DATA_WIDTH_A/DATA_WIDTH_B: 0, 1, 2, 4, 9, 18, or 36
|
123 |
|
|
DATA_WIDTH_A => 9,
|
124 |
|
|
DATA_WIDTH_B => 9,
|
125 |
|
|
-- DOA_REG/DOB_REG: Optional output register (0 or 1)
|
126 |
|
|
DOA_REG => 0,
|
127 |
|
|
DOB_REG => 0,
|
128 |
|
|
-- EN_RSTRAM_A/EN_RSTRAM_B: Enable/disable RST
|
129 |
|
|
EN_RSTRAM_A => true,
|
130 |
|
|
EN_RSTRAM_B => true,
|
131 |
|
|
-- INIT_A/INIT_B: Initial values on output port
|
132 |
|
|
INIT_A => X"000000000",
|
133 |
|
|
INIT_B => X"000000000",
|
134 |
|
|
-- INIT_FILE: Optional file used to specify initial RAM contents
|
135 |
|
|
INIT_FILE => "NONE",
|
136 |
|
|
-- RSTTYPE: "SYNC" or "ASYNC"
|
137 |
|
|
RSTTYPE => "SYNC",
|
138 |
|
|
-- RST_PRIORITY_A/RST_PRIORITY_B: "CE" or "SR"
|
139 |
|
|
RST_PRIORITY_A => "CE",
|
140 |
|
|
RST_PRIORITY_B => "CE",
|
141 |
|
|
-- SIM_COLLISION_CHECK: Collision check enable "ALL", "WARNING_ONLY", "GENERATE_X_ONLY" or "NONE"
|
142 |
|
|
SIM_COLLISION_CHECK => "ALL",
|
143 |
|
|
-- SIM_DEVICE: Must be set to "SPARTAN6" for proper simulation behavior
|
144 |
|
|
SIM_DEVICE => "SPARTAN6",
|
145 |
|
|
-- SRVAL_A/SRVAL_B: Set/Reset value for RAM output
|
146 |
|
|
SRVAL_A => X"000000000",
|
147 |
|
|
SRVAL_B => X"000000000",
|
148 |
|
|
-- WRITE_MODE_A/WRITE_MODE_B: "WRITE_FIRST", "READ_FIRST", or "NO_CHANGE"
|
149 |
|
|
WRITE_MODE_A => "WRITE_FIRST",
|
150 |
|
|
WRITE_MODE_B => "WRITE_FIRST"
|
151 |
|
|
)
|
152 |
|
|
port map (
|
153 |
|
|
-- Port A Data: 32-bit (each) Port A data
|
154 |
|
|
DOA => BRamLDOutxD, -- 8-bit A port data output
|
155 |
|
|
DOPA => BRamLPOutxD, -- 1-bit A port parity output
|
156 |
|
|
-- Port B Data: 32-bit (each) Port B data
|
157 |
|
|
DOB => open,
|
158 |
|
|
DOPB => open,
|
159 |
|
|
-- Port A Address/Control Signals: 14-bit (each) Port A address and control signals
|
160 |
|
|
ADDRA => BRamAddrxD, -- 11-bit A port address input
|
161 |
|
|
CLKA => ClkxCI, -- 1-bit A port clock input
|
162 |
|
|
ENA => '1', -- 1-bit A port enable input
|
163 |
|
|
REGCEA => '1', -- 1-bit A port register clock enable input
|
164 |
|
|
RSTA => '0', -- 1-bit A port register set/reset input
|
165 |
|
|
WEA => BRamWexS, -- 4-bit Port A byte-wide write enable input
|
166 |
|
|
-- Port A Data: 32-bit (each) Port A data
|
167 |
|
|
DIA => BRamLDInxD, -- 32-bit A port data input
|
168 |
|
|
DIPA => BRamLPInxD, -- 4-bit A port parity input
|
169 |
|
|
-- Port B Address/Control Signals: 14-bit (each) Port B address and control signals
|
170 |
|
|
ADDRB => "00000000000000", -- 14-bit B port address input
|
171 |
|
|
CLKB => '0', -- 1-bit B port clock input
|
172 |
|
|
ENB => '0', -- 1-bit B port enable input
|
173 |
|
|
REGCEB => '0', -- 1-bit B port register clock enable input
|
174 |
|
|
RSTB => '0', -- 1-bit B port register set/reset input
|
175 |
|
|
WEB => x"0", -- 4-bit Port B byte-wide write enable input
|
176 |
|
|
-- Port B Data: 32-bit (each) Port B data
|
177 |
|
|
DIB => x"00000000", -- 32-bit B port data input
|
178 |
|
|
DIPB => x"0" -- 4-bit B port parity input
|
179 |
|
|
);
|
180 |
|
|
|
181 |
|
|
-- higher byte of hash table. Only port A is used
|
182 |
|
|
hashTableMemHighInst : RAMB16BWER
|
183 |
|
|
generic map (
|
184 |
|
|
-- DATA_WIDTH_A/DATA_WIDTH_B: 0, 1, 2, 4, 9, 18, or 36
|
185 |
|
|
DATA_WIDTH_A => 9,
|
186 |
|
|
DATA_WIDTH_B => 9,
|
187 |
|
|
-- DOA_REG/DOB_REG: Optional output register (0 or 1)
|
188 |
|
|
DOA_REG => 0,
|
189 |
|
|
DOB_REG => 0,
|
190 |
|
|
-- EN_RSTRAM_A/EN_RSTRAM_B: Enable/disable RST
|
191 |
|
|
EN_RSTRAM_A => true,
|
192 |
|
|
EN_RSTRAM_B => true,
|
193 |
|
|
-- INIT_A/INIT_B: Initial values on output port
|
194 |
|
|
INIT_A => X"000000000",
|
195 |
|
|
INIT_B => X"000000000",
|
196 |
|
|
-- INIT_FILE: Optional file used to specify initial RAM contents
|
197 |
|
|
INIT_FILE => "NONE",
|
198 |
|
|
-- RSTTYPE: "SYNC" or "ASYNC"
|
199 |
|
|
RSTTYPE => "SYNC",
|
200 |
|
|
-- RST_PRIORITY_A/RST_PRIORITY_B: "CE" or "SR"
|
201 |
|
|
RST_PRIORITY_A => "CE",
|
202 |
|
|
RST_PRIORITY_B => "CE",
|
203 |
|
|
-- SIM_COLLISION_CHECK: Collision check enable "ALL", "WARNING_ONLY", "GENERATE_X_ONLY" or "NONE"
|
204 |
|
|
SIM_COLLISION_CHECK => "ALL",
|
205 |
|
|
-- SIM_DEVICE: Must be set to "SPARTAN6" for proper simulation behavior
|
206 |
|
|
SIM_DEVICE => "SPARTAN6",
|
207 |
|
|
-- SRVAL_A/SRVAL_B: Set/Reset value for RAM output
|
208 |
|
|
SRVAL_A => X"000000000",
|
209 |
|
|
SRVAL_B => X"000000000",
|
210 |
|
|
-- WRITE_MODE_A/WRITE_MODE_B: "WRITE_FIRST", "READ_FIRST", or "NO_CHANGE"
|
211 |
|
|
WRITE_MODE_A => "WRITE_FIRST",
|
212 |
|
|
WRITE_MODE_B => "WRITE_FIRST"
|
213 |
|
|
)
|
214 |
|
|
port map (
|
215 |
|
|
-- Port A Data: 32-bit (each) Port A data
|
216 |
|
|
DOA => BRamHDOutxD, -- 8-bit A port data output
|
217 |
|
|
DOPA => BRamHPOutxD, -- 1-bit A port parity output
|
218 |
|
|
-- Port B Data: 32-bit (each) Port B data
|
219 |
|
|
DOB => open,
|
220 |
|
|
DOPB => open,
|
221 |
|
|
-- Port A Address/Control Signals: 14-bit (each) Port A address and control signals
|
222 |
|
|
ADDRA => BRamAddrxD, -- 11-bit A port address input
|
223 |
|
|
CLKA => ClkxCI, -- 1-bit A port clock input
|
224 |
|
|
ENA => '1', -- 1-bit A port enable input
|
225 |
|
|
REGCEA => '1', -- 1-bit A port register clock enable input
|
226 |
|
|
RSTA => '0', -- 1-bit A port register set/reset input
|
227 |
|
|
WEA => BRamWexS, -- 4-bit Port A byte-wide write enable input
|
228 |
|
|
-- Port A Data: 32-bit (each) Port A data
|
229 |
|
|
DIA => BRamHDInxD, -- 32-bit A port data input
|
230 |
|
|
DIPA => BRamHPInxD, -- 4-bit A port parity input
|
231 |
|
|
-- Port B Address/Control Signals: 14-bit (each) Port B address and control signals
|
232 |
|
|
ADDRB => "00000000000000", -- 14-bit B port address input
|
233 |
|
|
CLKB => '0', -- 1-bit B port clock input
|
234 |
|
|
ENB => '0', -- 1-bit B port enable input
|
235 |
|
|
REGCEB => '0', -- 1-bit B port register clock enable input
|
236 |
|
|
RSTB => '0', -- 1-bit B port register set/reset input
|
237 |
|
|
WEB => x"0", -- 4-bit Port B byte-wide write enable input
|
238 |
|
|
-- Port B Data: 32-bit (each) Port B data
|
239 |
|
|
DIB => x"00000000", -- 32-bit B port data input
|
240 |
|
|
DIPB => x"0" -- 4-bit B port parity input
|
241 |
|
|
);
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
end Behavioral;
|
245 |
|
|
|