OpenCores
URL https://opencores.org/ocsvn/lzrw1-compressor-core/lzrw1-compressor-core/trunk

Subversion Repositories lzrw1-compressor-core

[/] [lzrw1-compressor-core/] [trunk/] [hw/] [HDL/] [comparator.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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/30 - 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
--* Compares a the look ahead buffer to a candidate and returns the number of bytes before the first
41
--* non-matching pair. The counting starts at the least significant end of the look ahead and the candidate
42
--*
43
--***************************************************************************************************************
44
 
45
library IEEE;
46
use IEEE.STD_LOGIC_1164.all;
47
use IEEE.NUMERIC_STD.all;
48
 
49
library UNISIM;
50
use UNISIM.VComponents.all;
51
 
52
entity comparator is
53
 
54
  port (
55
    -- ClkxCI          : in  std_logic;
56
    -- RstxRI          : in  std_logic;
57
    -- EnxSI           : in  std_logic;
58
    LookAheadxDI    : in  std_logic_vector(16*8-1 downto 0);
59
    LookAheadLenxDI : in  integer range 0 to 16;  -- how many bytes of LookAheadxDI are valid 
60
    CandidatexDI    : in  std_logic_vector(16*8-1 downto 0);
61
    CandidateLenxDI : in  integer range 0 to 16;  -- how many bytes of CandidatexDI are valid
62
    MatchLenxDO     : out integer range 0 to 16);  -- length of the match in bytes
63
 
64
end comparator;
65
 
66
 
67
 
68
architecture Behavioral of comparator is
69
 
70
  signal MatchVectorxS : std_logic_vector(15 downto 0);  -- match signals for the individual bytes
71
  signal RawMatchLenxD : integer range 0 to 16;  -- number of matching bytes (before further processing)
72
  signal MaxLengthxD   : integer range 0 to 16;  -- smaller of the two input signal length;
73
begin
74
 
75
  -- implement 16 byte wide comparators
76
  genByteComps : for i in 0 to 15 generate
77
    MatchVectorxS(i) <= '1' when CandidatexDI((i+1)*8-1 downto i*8) = LookAheadxDI((i+1)*8-1 downto i*8) else '0';
78
  end generate genByteComps;
79
 
80
  -- count the number of leading bytes to determine the match length
81
  process (MatchVectorxS)
82
    variable cnt : integer range 0 to 16 := 0;
83
  begin  -- process
84
    cnt := 0;
85
    cntLoop : for i in 0 to 15 loop
86
      if MatchVectorxS(i) = '1' then
87
        cnt := cnt + 1;
88
      else
89
        exit cntLoop;
90
      end if;
91
    end loop;  -- i
92
    RawMatchLenxD <= cnt;
93
  end process;
94
 
95
 
96
-- the match length can not be longer than the shorter of the two data inputs
97
  MaxLengthxD <= CandidateLenxDI when CandidateLenxDI < LookAheadLenxDI else LookAheadLenxDI;
98
 
99
-- make sure the match length is not bigger than the max length
100
  MatchLenxDO <= RawMatchLenxD when RawMatchLenxD <= MaxLengthxD else MaxLengthxD;
101
 
102
end Behavioral;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.