GCC Code Coverage Report
Directory: generated/vunit_out/preprocessed/ Exec Total Coverage
File: generated/vunit_out/preprocessed/reg_file/reg_file_pkg.vhd Lines: 19 19 100.0 %
Date: 2021-06-12 04:12:08 Branches: 58 90 64.4 %

Line Branch Exec Source
1


152844
-- -------------------------------------------------------------------------------------------------
2
-- Copyright (c) Lukas Vik. All rights reserved.
3
--
4
-- This file is part of the tsfpga project.
5
-- https://tsfpga.com
6
-- https://gitlab.com/tsfpga/tsfpga
7
-- -------------------------------------------------------------------------------------------------
8
9
library ieee;
10
use ieee.std_logic_1164.all;
11
use ieee.numeric_std.all;
12
13
library common;
14
use common.addr_pkg.all;
15
16
library math;
17
use math.math_pkg.all;
18
19
20
package reg_file_pkg is
21
22
38
  constant reg_width : integer := 32;
23
  subtype reg_t is std_logic_vector(reg_width - 1 downto 0);
24
  type reg_vec_t is array (integer range <>) of reg_t;
25
26
  type reg_type_t is (
27
    r, -- Bus can read a value that fabric provides
28
    w, -- Bus can write a value that is available for fabric usage
29
    r_w, -- Bus can write a value and read it back. The written value is available for fabric usage
30
    wpulse, -- Bus can write a value that is asserted for one cycle in fabric
31
    r_wpulse -- Bus can read a value that fabric provides. Bus can write a value that is asserted for one cycle in fabric
32
  );
33
34
  function is_read_type(reg_type : reg_type_t) return boolean;
35
  function is_write_type(reg_type : reg_type_t) return boolean;
36
  function is_write_pulse_type(reg_type : reg_type_t) return boolean;
37
  function is_fabric_gives_value_type(reg_type : reg_type_t) return boolean;
38
39
  type reg_definition_t is record
40
    idx : integer;
41
    reg_type : reg_type_t;
42
  end record;
43
  type reg_definition_vec_t is array (natural range <>) of reg_definition_t;
44
45
  function get_highest_idx(regs : reg_definition_vec_t) return integer;
46
  function get_addr_mask(regs : reg_definition_vec_t) return addr_t;
47
  function to_addr_and_mask_vec(regs : reg_definition_vec_t) return addr_and_mask_vec_t;
48
49
end;
50
51
package body reg_file_pkg is
52
53
  function is_read_type(reg_type : reg_type_t) return boolean is
54
  begin
55

96
    return reg_type = r or reg_type = r_w or reg_type = r_wpulse;
56
  end function;
57
58
  function is_write_type(reg_type : reg_type_t) return boolean is
59
  begin
60

148
    return reg_type = w or reg_type = r_w or reg_type = wpulse or reg_type = r_wpulse;
61
  end function;
62
63
  function is_write_pulse_type(reg_type : reg_type_t) return boolean is
64
  begin
65
109128
    return reg_type = wpulse or reg_type = r_wpulse;
66
  end function;
67
68
  function is_fabric_gives_value_type(reg_type : reg_type_t) return boolean is
69
  begin
70
42444
    return reg_type = r or reg_type = r_wpulse;
71
  end function;
72
73
  function get_highest_idx(regs : reg_definition_vec_t) return integer is
74
  begin
75

100
    assert regs(0).idx = 0 severity failure;
76


100
    assert regs(regs'high).idx = regs'length - 1 severity failure;
77

100
    return regs(regs'high).idx;
78
  end function;
79
80
  function get_addr_mask(regs : reg_definition_vec_t) return addr_t is
81
100
    constant num_bits : integer := num_bits_needed(get_highest_idx(regs));
82
3300
    variable result : addr_t := (others => '0');
83
  begin
84
    -- Lowest bits are always zero since registers are 32-bits i.e. four-byte aligned.
85


418
    result(num_bits + 2 - 1 downto 2) := (others => '1');
86
100
    return result;
87
  end function;
88
89
  function to_addr_and_mask_vec(regs : reg_definition_vec_t) return addr_and_mask_vec_t is
90
94
    constant mask : addr_t := get_addr_mask(regs);
91


60154
    variable result : addr_and_mask_vec_t(regs'range);
92
  begin
93
94
    for list_idx in regs'range loop
94
      -- Registers are 32-bits i.e. four-byte aligned, hence the multiplication.
95



924
      result(list_idx).addr := to_unsigned(4 * regs(list_idx).idx, result(list_idx).addr'length);
96


924
      result(list_idx).mask := mask;
97
    end loop;
98

132
    return result;
99
  end function;
100
101
end;