Browse Source

StackP is now a package with generics for type & max depth

T. Meissner 2 years ago
parent
commit
cab2370216
3 changed files with 64 additions and 54 deletions
  1. 41
    26
      sim/StackP.vhd
  2. 23
    15
      test/StackT.vhd
  3. 0
    13
      test/get_vhdl_2008.sh

+ 41
- 26
sim/StackP.vhd View File

@@ -1,24 +1,25 @@
1 1
 library ieee;
2 2
   use ieee.std_logic_1164.all;
3 3
 
4
---+ including vhdl 2008 libraries
5
---+ These lines can be commented out when using
6
---+ a simulator with built-in VHDL 2008 support
7
---library ieee_proposed;
8 4
 
9 5
 
10 6
 package StackP is
11 7
 
12 8
 
9
+  generic (
10
+    type     STACK_TYPE;
11
+    MAX_LEN : natural := 64;
12
+    function to_string(d : in STACK_TYPE) return string
13
+  );
14
+
13 15
   -- linked list stack interface
14 16
   type t_stack is protected
15 17
 
16
-    procedure push (data : in  std_logic_vector);
17
-    procedure pop  (data : inout std_logic_vector);
18
+    procedure push (data : in  STACK_TYPE);
19
+    procedure pop  (data : inout STACK_TYPE);
18 20
     procedure init (logging : in boolean := false);
19 21
     impure function is_empty return boolean;
22
+    impure function is_full return boolean;
20 23
     impure function fillstate return natural;
21 24
 
22 25
   end protected t_stack;
@@ -37,7 +38,7 @@ package body StackP is
37 38
     type t_entry;
38 39
     type t_entry_ptr is access t_entry;
39 40
 
40
-    type t_data_ptr is access std_logic_vector;
41
+    type t_data_ptr is access STACK_TYPE;
41 42
 
42 43
     type t_entry is record
43 44
       data       : t_data_ptr;
@@ -52,32 +53,38 @@ package body StackP is
52 53
 
53 54
     -- write one entry into queue by
54 55
     -- creating new entry at head of list
55
-    procedure push (data : in  std_logic_vector) is
56
+    procedure push (data : in  STACK_TYPE) is
56 57
       variable v_entry : t_entry_ptr;
57 58
     begin
58
-      if (v_count /= 0) then
59
-        v_entry            := new t_entry;
60
-        v_entry.data       := new std_logic_vector'(data);
61
-        v_entry.last_entry := v_head;
62
-        v_entry.next_entry := null;
63
-        v_head             := v_entry;
64
-        v_head.last_entry.next_entry := v_head;
59
+      if (not(is_full)) then
60
+        if (v_count /= 0) then
61
+          v_entry            := new t_entry;
62
+          v_entry.data       := new STACK_TYPE'(data);
63
+          v_entry.last_entry := v_head;
64
+          v_entry.next_entry := null;
65
+          v_head             := v_entry;
66
+          v_head.last_entry.next_entry := v_head;
67
+        else
68
+          v_head            := new t_entry;
69
+          v_head.data       := new STACK_TYPE'(data);
70
+          v_head.last_entry := null;
71
+          v_head.next_entry := null;
72
+          v_tail            := v_head;
73
+        end if;
74
+        v_count := v_count + 1;
75
+        if v_logging then
76
+          report t_stack'instance_name & " pushed 0x" & to_string(data) & " on stack";
77
+        end if;
65 78
       else
66
-        v_head            := new t_entry;
67
-        v_head.data       := new std_logic_vector'(data);
68
-        v_head.last_entry := null;
69
-        v_head.next_entry := null;
70
-        v_tail            := v_head;
71
-      end if;
72
-      v_count := v_count + 1;
73
-      if v_logging then
74
-        report t_stack'instance_name & " pushed 0x" & to_hstring(data) & " on stack";
79
+        assert false
80
+        report t_stack'instance_name & " push to full stack -> discared"
81
+        severity warning;
75 82
       end if;
76 83
     end procedure push;
77 84
 
78 85
     -- read one entry from queue at tail of list and
79 86
     -- delete that entry from list after read
80
-    procedure pop  (data : inout std_logic_vector) is
87
+    procedure pop  (data : inout STACK_TYPE) is
81 88
       variable v_entry : t_entry_ptr := v_head;
82 89
     begin
83 90
       assert not(is_empty)
@@ -89,7 +96,7 @@ package body StackP is
89 96
       deallocate(v_entry);
90 97
       v_count := v_count - 1;
91 98
       if v_logging then
92
-        report t_stack'instance_name & " popped 0x" & to_hstring(data) & " from stack";
99
+        report t_stack'instance_name & " popped 0x" & to_string(data) & " from stack";
93 100
       end if;
94 101
     end procedure pop;
95 102
 
@@ -104,6 +111,12 @@ package body StackP is
104 111
       return v_head = null;
105 112
     end function is_empty;
106 113
 
114
+    -- returns true if queue is full, false otherwise
115
+    impure function is_full return boolean is
116
+    begin
117
+      return v_count = MAX_LEN;
118
+    end function is_full;
119
+
107 120
     -- returns number of filled slots in queue
108 121
     impure function fillstate return natural is
109 122
     begin

+ 23
- 15
test/StackT.vhd View File

@@ -2,20 +2,11 @@ library ieee;
2 2
   use ieee.std_logic_1164.all;
3 3
   use ieee.numeric_std.all;
4 4
 
5
---+ including vhdl 2008 libraries
6
---+ These lines can be commented out when using
7
---+ a simulator with built-in VHDL 2008 support
8
---library ieee_proposed;
9
-
10 5
 library osvvm;
11 6
   use osvvm.RandomPkg.all;
12 7
 
13 8
 library libvhdl;
14 9
   use libvhdl.AssertP.all;
15
-  use libvhdl.StackP.all;
16 10
 
17 11
 
18 12
 
@@ -29,9 +20,14 @@ architecture sim of StackT is
29 20
 
30 21
   constant C_STACK_DEPTH : natural := 64;
31 22
 
32
-  type t_scoreboard is array (natural range <>) of std_logic_vector(7 downto 0);
23
+  package SlvStack is new libvhdl.StackP
24
+    generic map (
25
+      STACK_TYPE => std_logic_vector(63 downto 0),
26
+      MAX_LEN    => C_STACK_DEPTH,
27
+      to_string  => to_hstring
28
+    );
33 29
 
34
-  shared variable sv_stack : t_stack;
30
+  shared variable sv_stack : SlvStack.t_stack;
35 31
 
36 32
 
37 33
 begin
@@ -45,21 +41,30 @@ begin
45 41
 
46 42
 
47 43
   StackTestP : process is
48
-    variable v_data : std_logic_vector(7 downto 0);
44
+    variable v_data : std_logic_vector(63 downto 0);
45
+    variable v_random : RandomPType;
46
+    type t_scoreboard is array (natural range <>) of std_logic_vector(63 downto 0);
47
+    variable v_scoreboard : t_scoreboard(0 to C_STACK_DEPTH-1);
49 48
   begin
50
-    -- check initial emptiness
49
+    -- Check initial emptiness
51 50
     assert_true(sv_stack.is_empty, "Stack should be empty!");
51
+    -- Fill stack
52
+    v_random.InitSeed(v_random'instance_name);
52 53
     for i in 0 to C_STACK_DEPTH-1 loop
53
-      sv_stack.push(std_logic_vector(to_unsigned(i, 8)));
54
+      v_data := v_random.RandSlv(64);
55
+      v_scoreboard(i) := v_data;
56
+      sv_stack.push(v_data);
54 57
     end loop;
55
-    -- check that it's full
58
+    -- Check that it's full
59
+    assert_true(sv_stack.is_full, "Stack should be full!");
60
+    -- Check number of entries
56 61
     assert_equal(sv_stack.fillstate, C_STACK_DEPTH, "Stack should have" & integer'image(C_STACK_DEPTH) & "entries");
57
-    -- empty the queue
62
+    -- Empty the stack
58 63
     for i in C_STACK_DEPTH-1 downto 0 loop
59 64
       sv_stack.pop(v_data);
60
-      assert_equal(v_data, std_logic_vector(to_unsigned(i, 8)));
65
+      assert_equal(v_data, v_scoreboard(i));
61 66
     end loop;
62
-    -- check emptiness
67
+    -- Check emptiness
63 68
     assert_true(sv_stack.is_empty, "Stack should be empty!");
64 69
     report "INFO: t_stack test finished successfully";
65 70
     wait;

+ 0
- 13
test/get_vhdl_2008.sh View File

@@ -1,13 +0,0 @@
1
-#!/bin/bash
2
-
3
-rm -rf vhdl_2008/*.vhdl
4
-cd vhdl_2008
5
-
6
-wget http://www.eda.org/fphdl/standard_additions_c.vhdl 
7
-wget http://www.eda.org/fphdl/env_c.vhdl 
8
-wget http://www.eda.org/fphdl/standard_textio_additions_c.vhdl 
9
-wget http://www.eda.org/fphdl/std_logic_1164_additions.vhdl 
10
-wget http://www.eda.org/fphdl/numeric_std_additions.vhdl
11
-wget http://www.eda.org/fphdl/numeric_std_unsigned_c.vhdl 
12
-
13
-patch < env_c.vhdl.patch