GCC Code Coverage Report
Directory: generated/vunit_out/preprocessed/ Exec Total Coverage
File: generated/vunit_out/preprocessed/common/addr_pkg.vhd Lines: 16 16 100.0 %
Date: 2021-06-12 04:12:08 Branches: 34 54 63.0 %

Line Branch Exec Source
1


6438
-- -------------------------------------------------------------------------------------------------
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 math;
14
use math.math_pkg.all;
15
16
17
package addr_pkg is
18
19
50
  constant addr_width : integer := 32;
20
  subtype addr_t is unsigned(addr_width - 1 downto 0);
21
  type addr_vec_t is array (integer range <>) of addr_t;
22
23
  type addr_and_mask_t is record
24
    addr : addr_t;
25
    mask : addr_t;
26
  end record;
27
  type addr_and_mask_vec_t is array (integer range <>) of addr_and_mask_t;
28
29
  function addr_bits_needed(addrs : addr_and_mask_vec_t) return positive;
30
31
  function match(addr : unsigned; addr_and_mask : addr_and_mask_t) return boolean;
32
33
  function decode(addr : unsigned; addrs : addr_and_mask_vec_t) return integer;
34
35
end package;
36
37
package body addr_pkg is
38
39
  function addr_bits_needed(addrs : addr_and_mask_vec_t) return positive is
40
40
    variable result : positive := 1;
41
  begin
42
    -- Return the number of bits that are needed to decode and handle the addresses.
43
40
    for addr_idx in addrs'range loop
44



176
      result := maximum(result, num_bits_needed(addrs(addr_idx).mask));
45
    end loop;
46
40
    return result;
47
  end function;
48
49
  function match(addr : unsigned; addr_and_mask : addr_and_mask_t) return boolean is
50
4556
    variable test_ok : boolean := true;
51
  begin
52
4556
    for bit_idx in addr_and_mask.addr'range loop
53

145792
      if addr_and_mask.mask(bit_idx) then
54


145792
        test_ok := test_ok and (addr(bit_idx) = addr_and_mask.addr(bit_idx));
55
      end if;
56
    end loop;
57
58
4556
    return test_ok;
59
  end function;
60
61
  function decode(addr : unsigned; addrs : addr_and_mask_vec_t) return integer is
62
1648
    constant decode_fail : integer := addrs'length;
63
  begin
64
1648
    for addr_idx in addrs'range loop
65

4556
      if match(addr, addrs(addr_idx)) then
66

4556
        return addr_idx;
67
      end if;
68
    end loop;
69
70

68
    return decode_fail;
71
  end function;
72
73
end package body;