-- <File header>
|
-- <File header>
|
-- Project
|
-- Project
|
-- pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
|
-- pAVR (pipelined AVR) is an 8 bit RISC controller, compatible with Atmel's
|
-- AVR core, but about 3x faster in terms of both clock frequency and MIPS.
|
-- AVR core, but about 3x faster in terms of both clock frequency and MIPS.
|
-- The increase in speed comes from a relatively deep pipeline. The original
|
-- The increase in speed comes from a relatively deep pipeline. The original
|
-- AVR core has only two pipeline stages (fetch and execute), while pAVR has
|
-- AVR core has only two pipeline stages (fetch and execute), while pAVR has
|
-- 6 pipeline stages:
|
-- 6 pipeline stages:
|
-- 1. PM (read Program Memory)
|
-- 1. PM (read Program Memory)
|
-- 2. INSTR (load Instruction)
|
-- 2. INSTR (load Instruction)
|
-- 3. RFRD (decode Instruction and read Register File)
|
-- 3. RFRD (decode Instruction and read Register File)
|
-- 4. OPS (load Operands)
|
-- 4. OPS (load Operands)
|
-- 5. ALU (execute ALU opcode or access Unified Memory)
|
-- 5. ALU (execute ALU opcode or access Unified Memory)
|
-- 6. RFWR (write Register File)
|
-- 6. RFWR (write Register File)
|
-- Version
|
-- Version
|
-- 0.32
|
-- 0.32
|
-- Date
|
-- Date
|
-- 2002 August 07
|
-- 2002 August 07
|
-- Author
|
-- Author
|
-- Doru Cuturela, doruu@yahoo.com
|
-- Doru Cuturela, doruu@yahoo.com
|
-- License
|
-- License
|
-- This program is free software; you can redistribute it and/or modify
|
-- This program is free software; you can redistribute it and/or modify
|
-- it under the terms of the GNU General Public License as published by
|
-- it under the terms of the GNU General Public License as published by
|
-- the Free Software Foundation; either version 2 of the License, or
|
-- the Free Software Foundation; either version 2 of the License, or
|
-- (at your option) any later version.
|
-- (at your option) any later version.
|
-- This program is distributed in the hope that it will be useful,
|
-- This program is distributed in the hope that it will be useful,
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
-- GNU General Public License for more details.
|
-- GNU General Public License for more details.
|
-- You should have received a copy of the GNU General Public License
|
-- You should have received a copy of the GNU General Public License
|
-- along with this program; if not, write to the Free Software
|
-- along with this program; if not, write to the Free Software
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
-- </File header>
|
-- </File header>
|
|
|
|
|
|
|
-- <File info>
|
-- <File info>
|
-- This tests the utilities defined in `std_util.vhd':
|
-- This tests the utilities defined in `std_util.vhd':
|
-- - cmp_std_logic_vector (asynchronous function)
|
-- - cmp_std_logic_vector (asynchronous function)
|
-- - sign_extend (asynchronous function)
|
-- - sign_extend (asynchronous function)
|
-- - zero_extend (asynchronous function)
|
-- - zero_extend (asynchronous function)
|
-- </File info>
|
-- </File info>
|
|
|
|
|
|
|
-- <File body>
|
-- <File body>
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
library work;
|
library work;
|
use work.std_util.all;
|
use work.std_util.all;
|
|
|
|
|
entity test_std_util is
|
entity test_std_util is
|
end;
|
end;
|
|
|
|
|
architecture arch_test_std_util of test_std_util is
|
architecture arch_test_std_util of test_std_util is
|
signal clk: std_logic;
|
signal clk: std_logic;
|
-- Comparision output
|
-- Comparision output
|
signal flag1: std_logic;
|
signal flag1: std_logic;
|
-- Candidates to sign/zero extension and comparision
|
-- Candidates to sign/zero extension and comparision
|
signal v2_1, v2_2, v2_3: std_logic_vector( 1 downto 0);
|
signal v2_1, v2_2, v2_3: std_logic_vector( 1 downto 0);
|
signal v50_1, v50_2, v50_3: std_logic_vector(49 downto 0);
|
signal v50_1, v50_2, v50_3: std_logic_vector(49 downto 0);
|
begin
|
begin
|
|
|
generate_clock:
|
generate_clock:
|
process
|
process
|
begin
|
begin
|
clk <= '1';
|
clk <= '1';
|
wait for 50 ns;
|
wait for 50 ns;
|
clk <= '0';
|
clk <= '0';
|
wait for 50 ns;
|
wait for 50 ns;
|
end process generate_clock;
|
end process generate_clock;
|
|
|
|
|
test_main:
|
test_main:
|
process
|
process
|
begin
|
begin
|
-- Set up default inputs.
|
-- Set up default inputs.
|
v2_1 <= "10";
|
v2_1 <= "10";
|
v2_2 <= "01";
|
v2_2 <= "01";
|
for i in 0 to 49 loop
|
for i in 0 to 49 loop
|
v50_1(i) <= '0';
|
v50_1(i) <= '0';
|
v50_2(i) <= '0';
|
v50_2(i) <= '0';
|
end loop;
|
end loop;
|
v50_1(49) <= '1';
|
v50_1(49) <= '1';
|
v50_1(3 downto 0) <= "1001";
|
v50_1(3 downto 0) <= "1001";
|
v50_2(3 downto 0) <= "1010";
|
v50_2(3 downto 0) <= "1010";
|
wait for 110 ns;
|
wait for 110 ns;
|
|
|
-- TEST 1
|
-- TEST 1
|
-- Test function `cmp_std_logic_vector'
|
-- Test function `cmp_std_logic_vector'
|
-- Try to compare 2 vectors with different lengths; this should assert the dedicated error.
|
-- Try to compare 2 vectors with different lengths; this should assert the dedicated error.
|
--flag1 <= cmp_std_logic_vector(v2_1, v50_1);
|
--flag1 <= cmp_std_logic_vector(v2_1, v50_1);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
-- Typical situations
|
-- Typical situations
|
-- Shouldn't match
|
-- Shouldn't match
|
flag1 <= cmp_std_logic_vector(v50_1, v50_2);
|
flag1 <= cmp_std_logic_vector(v50_1, v50_2);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Should match
|
-- Should match
|
flag1 <= cmp_std_logic_vector(v50_1, v50_1);
|
flag1 <= cmp_std_logic_vector(v50_1, v50_1);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Shouldn't match
|
-- Shouldn't match
|
flag1 <= cmp_std_logic_vector(sign_extend(v2_1, v50_1'length), zero_extend(v2_1, v50_1'length));
|
flag1 <= cmp_std_logic_vector(sign_extend(v2_1, v50_1'length), zero_extend(v2_1, v50_1'length));
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Should match
|
-- Should match
|
flag1 <= cmp_std_logic_vector(sign_extend(v2_2, v50_1'length), zero_extend(v2_2, v50_1'length));
|
flag1 <= cmp_std_logic_vector(sign_extend(v2_2, v50_1'length), zero_extend(v2_2, v50_1'length));
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
|
|
-- TEST 2
|
-- TEST 2
|
-- Test function `sign_extend' and `zero_extend', negative input.
|
-- Test function `sign_extend' and `zero_extend', negative input.
|
-- Extremal case that should work. For length 2, typical case = extremal case.
|
-- Extremal case that should work. For length 2, typical case = extremal case.
|
v2_3 <= sign_extend(v2_1, v2_3'length);
|
v2_3 <= sign_extend(v2_1, v2_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
v2_3 <= zero_extend(v2_1, v2_3'length);
|
v2_3 <= zero_extend(v2_1, v2_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Some stupid length that should generate an error
|
-- Some stupid length that should generate an error
|
--v2_3 <= sign_extend(v2_1, 7);
|
--v2_3 <= sign_extend(v2_1, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
--v2_3 <= zero_extend(v2_1, 7);
|
--v2_3 <= zero_extend(v2_1, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
-- The same with width 50
|
-- The same with width 50
|
-- Typical case
|
-- Typical case
|
v50_3 <= sign_extend(v2_1, v50_3'length);
|
v50_3 <= sign_extend(v2_1, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
v50_3 <= zero_extend(v2_1, v50_3'length);
|
v50_3 <= zero_extend(v2_1, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Extremal case that should work
|
-- Extremal case that should work
|
v50_3 <= sign_extend(v50_1, v50_3'length);
|
v50_3 <= sign_extend(v50_1, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
v50_3 <= zero_extend(v50_1, v50_3'length);
|
v50_3 <= zero_extend(v50_1, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Some stupid length that should generate an error
|
-- Some stupid length that should generate an error
|
--v50_3 <= sign_extend(v50_1, 7);
|
--v50_3 <= sign_extend(v50_1, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
--v50_3 <= zero_extend(v50_1, 7);
|
--v50_3 <= zero_extend(v50_1, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
|
|
-- TEST 1
|
-- TEST 1
|
-- Test function `sign_extend' and `zero_extend', positive input.
|
-- Test function `sign_extend' and `zero_extend', positive input.
|
-- Extremal case that should work. For length 2, typical case = extremal case.
|
-- Extremal case that should work. For length 2, typical case = extremal case.
|
v2_3 <= sign_extend(v2_2, v2_3'length);
|
v2_3 <= sign_extend(v2_2, v2_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
v2_3 <= zero_extend(v2_2, v2_3'length);
|
v2_3 <= zero_extend(v2_2, v2_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Some stupid length that should generate an error
|
-- Some stupid length that should generate an error
|
--v2_3 <= sign_extend(v2_2, 7);
|
--v2_3 <= sign_extend(v2_2, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
--v2_3 <= zero_extend(v2_2, 7);
|
--v2_3 <= zero_extend(v2_2, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
-- The same with width 50
|
-- The same with width 50
|
-- Typical case
|
-- Typical case
|
v50_3 <= sign_extend(v2_2, v50_3'length);
|
v50_3 <= sign_extend(v2_2, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
v50_3 <= zero_extend(v2_2, v50_3'length);
|
v50_3 <= zero_extend(v2_2, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Extremal case that should work
|
-- Extremal case that should work
|
v50_3 <= sign_extend(v50_2, v50_3'length);
|
v50_3 <= sign_extend(v50_2, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
v50_3 <= zero_extend(v50_2, v50_3'length);
|
v50_3 <= zero_extend(v50_2, v50_3'length);
|
wait until clk'event and clk='1';
|
wait until clk'event and clk='1';
|
-- Some stupid length that should generate an error
|
-- Some stupid length that should generate an error
|
--v50_3 <= sign_extend(v50_2, 7);
|
--v50_3 <= sign_extend(v50_2, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
--v50_3 <= zero_extend(v50_2, 7);
|
--v50_3 <= zero_extend(v50_2, 7);
|
--wait until clk'event and clk='1';
|
--wait until clk'event and clk='1';
|
end process test_main;
|
end process test_main;
|
|
|
end;
|
end;
|
-- </File body>
|
-- </File body>
|
|
|