📄 huffman_en_full.vhd
字号:
-- barrel shifter.
-- Every time there are 16 bits in the barrel shifter, the contends of the shifter is
-- enabled out as the huffman_out signal. Each run length value is read in and the corresponding
-- vlc code is found out (vlcode_dc or vlcode_ac1). For each code, the codelength is also
-- stored in a ROM. The codelengths are added up (cl_sum) and when it reaches 16 or 32,
-- the code is sent out.
-- The maximum value for cl_sum happens when a 15 bit code is followed by a 24 bit
-- code. So the max. value for cl_sum is 15 + 24 = 39. The barrel shifter has 39 valid
-- registers. For ease of coding, 48 (3 * 16) registers are used. These registers are
-- divided into upper_reg, middle_reg and lower_reg. Each time upper_reg if full (ie.,
-- 16 or more bits in barrel shifter), the contends are sent out. The remaining bits
-- , if any, in the middle_reg are moved up to the upper_reg. If the barrel shifter
-- has 32 or more valid data, the upper and middle registers are full and the upper
-- reg data is sent out followed by the middle reg data. The remaining bits, if any
-- in the lower register is moved up to the upper register.
--***************************************************************************
-- calculate sum of codelength. set half flag and full flag . Half flags indicates
-- calculate sum of codelength. set half flag and full flag . Half flags indicates
-- that the upper_reg is full and full flag indicates that the lower register is full.
-- cl_sum_prev gives the sum of the codelengths which is used to set the flags. cl_sum
-- is used to find out the number of shifts to be done in the barrel shifts.
PROCESS (CLK, RST)
BEGIN
IF (RST = '1') THEN
cl_sum <= "100111";
cl_sum_prev <= "000000";
half_flag1 <= '0';
full_flag1 <= '0';
ELSIF (CLK'EVENT AND CLK = '1') THEN
IF (cl_sum_rdy = '1') THEN
IF (cl_sum_prev < "010000") THEN
cl_sum_prev <= "0" & codelength1 + cl_sum_prev;
cl_sum <= "100111" - cl_sum_prev;
half_flag1 <= '0';
full_flag1 <= '0';
ELSE
IF (cl_sum_prev<="100000" AND cl_sum_prev >= "010000")
THEN
cl_sum_prev <= "0" & codelength1 + (cl_sum_prev -
"010000");
cl_sum <= "100111" - cl_sum_prev;
half_flag1 <= '1';
full_flag1 <= '0';
ELSE
IF (cl_sum_prev >= "100000") THEN
cl_sum_prev <= "0" & codelength1 + (cl_sum_prev -
"100000");
cl_sum <= "100111" - cl_sum_prev;
half_flag1 <= '1';
full_flag1 <= '1';
END IF;
END IF;
END IF;
END IF;
END IF;
END PROCESS;
--***************************************************************************
-- barrel shifting done using multiplier. Barrel shifting coefficients are
-- barrel shifting done using multiplier. Barrel shifting coefficients are
-- stored in a ROM and selected depending on the value of cl_sum
PROCESS (CLK)
BEGIN
IF (CLK'EVENT AND CLK = '1') THEN
IF (RST = '1') THEN
cl_sum_shift <= "000000000000000000000000000000000000000";
ELSE
CASE cl_sum IS
WHEN "000000" =>
cl_sum_shift <= "000000000000000000000000000000000000000";
WHEN "000001" =>
cl_sum_shift <= "000000000000000000000000000000000000010";
WHEN "000010" =>
cl_sum_shift <= "000000000000000000000000000000000000100";
WHEN "000011" =>
cl_sum_shift <= "000000000000000000000000000000000001000";
WHEN "000100" =>
cl_sum_shift <= "000000000000000000000000000000000010000";
WHEN "000101" =>
cl_sum_shift <= "000000000000000000000000000000000100000";
WHEN "000110" =>
cl_sum_shift <= "000000000000000000000000000000001000000";
WHEN "000111" =>
cl_sum_shift <= "000000000000000000000000000000010000000";
WHEN "001000" =>
cl_sum_shift <= "000000000000000000000000000000100000000";
WHEN "001001" =>
cl_sum_shift <= "000000000000000000000000000001000000000";
WHEN "001010" =>
cl_sum_shift <= "000000000000000000000000000010000000000";
WHEN "001011" =>
cl_sum_shift <= "000000000000000000000000000100000000000";
WHEN "001100" =>
cl_sum_shift <= "000000000000000000000000001000000000000";
WHEN "001101" =>
cl_sum_shift <= "000000000000000000000000010000000000000";
WHEN "001110" =>
cl_sum_shift <= "000000000000000000000000100000000000000";
WHEN "001111" =>
cl_sum_shift <= "000000000000000000000001000000000000000";
WHEN "010000" =>
cl_sum_shift <= "000000000000000000000010000000000000000";
WHEN "010001" =>
cl_sum_shift <= "000000000000000000000100000000000000000";
WHEN "010010" =>
cl_sum_shift <= "000000000000000000001000000000000000000";
WHEN "010011" =>
cl_sum_shift <= "000000000000000000010000000000000000000";
WHEN "010100" =>
cl_sum_shift <= "000000000000000000100000000000000000000";
WHEN "010101" =>
cl_sum_shift <= "000000000000000001000000000000000000000";
WHEN "010110" =>
cl_sum_shift <= "000000000000000010000000000000000000000";
WHEN "010111" =>
cl_sum_shift <= "000000000000000100000000000000000000000";
WHEN "011000" =>
cl_sum_shift <= "000000000000001000000000000000000000000";
WHEN "011001" =>
cl_sum_shift <= "000000000000010000000000000000000000000";
WHEN "011010" =>
cl_sum_shift <= "000000000000100000000000000000000000000";
WHEN "011011" =>
cl_sum_shift <= "000000000001000000000000000000000000000";
WHEN "011100" =>
cl_sum_shift <= "000000000010000000000000000000000000000";
WHEN "011101" =>
cl_sum_shift <= "000000000100000000000000000000000000000";
WHEN "011110" =>
cl_sum_shift <= "000000001000000000000000000000000000000";
WHEN "011111" =>
cl_sum_shift <= "000000010000000000000000000000000000000";
WHEN "100000" =>
cl_sum_shift <= "000000100000000000000000000000000000000";
WHEN "100001" =>
cl_sum_shift <= "000001000000000000000000000000000000000";
WHEN "100010" =>
cl_sum_shift <= "000010000000000000000000000000000000000";
WHEN "100011" =>
cl_sum_shift <= "000100000000000000000000000000000000000";
WHEN "100100" =>
cl_sum_shift <= "001000000000000000000000000000000000000";
WHEN "100101" =>
cl_sum_shift <= "010000000000000000000000000000000000000";
WHEN "100110" =>
cl_sum_shift <= "100000000000000000000000000000000000000";
WHEN OTHERS =>
cl_sum_shift <= "000000000000000000000000000000000000000";
END CASE;
END IF;
END IF;
END PROCESS;
--***************************************************************************
-- multiplier used to do barrel shifting of codeword. flags pipeleined to match
-- multiplier used to do barrel shifting of codeword. flags pipeleined to match
-- the pipe line stages of upper, middle and lower registers.
PROCESS (CLK, RST)
BEGIN
IF (RST = '1') THEN
mult_out_int <= (OTHERS => '0');
full_flag2 <= '0';
half_flag2 <= '0';
full_flag3 <= '0';
half_flag3 <= '0';
full_flag4 <= '0';
half_flag4 <= '0';
full_flag5 <= '0';
half_flag5 <= '0';
full_flag6 <= '0';
ELSIF (CLK'EVENT AND CLK = '1') THEN
IF (rdy_in = '1') THEN
mult_out_int <= vlcode4 * cl_sum_shift;
full_flag2 <= full_flag1;
half_flag2 <= half_flag1;
full_flag3 <= full_flag2;
half_flag3 <= half_flag2;
full_flag4 <= full_flag3;
half_flag4 <= half_flag3;
full_flag5 <= full_flag4;
half_flag5 <= half_flag4;
full_flag6 <= full_flag5;
END IF;
END IF;
END PROCESS;
mult_out <= mult_out_int (38 downto 0);
--***************************************************************************
PROCESS (CLK, RST)
BEGIN
IF (RST = '1') THEN
upper_reg1 <= "0000000000000000";
middle_reg1 <= "0000000000000000";
lower_reg1 <= "0000000000000000";
ELSIF (CLK'EVENT AND CLK = '1') THEN
IF (rdy_in = '1') THEN
CASE temp11 IS
WHEN "00" =>
upper_reg1(16 DOWNTO 1) <= mult_out(38 DOWNTO 23)
OR upper_reg1(16 DOWNTO 1);
middle_reg1 <= mult_out(22 DOWNTO 7);
lower_reg1 <= mult_out(6 DOWNTO 0) &
"000000000";
WHEN "01" =>
upper_reg1(16 DOWNTO 1) <= mult_out(38 DOWNTO 23)
OR middle_reg1(16 DOWNTO 1);
middle_reg1 <= mult_out(22 DOWNTO 7);
lower_reg1 <= mult_out(6 DOWNTO 0) &
"000000000";
WHEN "11" =>
upper_reg1 <= mult_out(38 DOWNTO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -