diff --git a/vunit/vhdl/helpers/src/helpers_pkg.vhd b/vunit/vhdl/helpers/src/helpers_pkg.vhd new file mode 100644 index 0000000000..9d1b475dc4 --- /dev/null +++ b/vunit/vhdl/helpers/src/helpers_pkg.vhd @@ -0,0 +1,22 @@ +-- This Source Code Form is subject to the terms of the Mozilla Public +-- License, v. 2.0. If a copy of the MPL was not distributed with this file, +-- You can obtain one at http://mozilla.org/MPL/2.0/. +-- +-- Copyright (c) 2014-2020, Lars Asplund lars.anders.asplund@gmail.com + +package helpers_pkg is + function calc_width(data_width : positive) return natural; +end package; + +package body helpers_pkg is + function calc_width(d : positive) return natural is + variable i : natural; + variable v : natural := d-1; + begin + while v > 0 loop + v := v/2; + i := i + 1; + end loop; + return i; + end; +end package body; diff --git a/vunit/vhdl/verification_components/src/avalon_stream_pkg.vhd b/vunit/vhdl/verification_components/src/avalon_stream_pkg.vhd index 74a59cd6a2..402aa5c0b7 100644 --- a/vunit/vhdl/verification_components/src/avalon_stream_pkg.vhd +++ b/vunit/vhdl/verification_components/src/avalon_stream_pkg.vhd @@ -10,6 +10,7 @@ use ieee.std_logic_1164.all; use work.logger_pkg.all; use work.stream_master_pkg.all; use work.stream_slave_pkg.all; +use work.helpers_pkg.all; context work.com_context; context work.data_types_context; @@ -45,7 +46,6 @@ package avalon_stream_pkg is channel_length : natural := 0) return avalon_sink_t; impure function data_length(source : avalon_source_t) return natural; impure function data_length(source : avalon_sink_t) return natural; - function calc_empty_length(data_width : positive) return natural; impure function empty_length(source : avalon_source_t) return natural; impure function empty_length(source : avalon_sink_t) return natural; impure function channel_length(source : avalon_source_t) return natural; @@ -147,27 +147,16 @@ package body avalon_stream_pkg is return source.p_data_length; end; - function calc_empty_length(data_width : positive) return natural is - variable v : natural; - variable i : natural; - begin - assert data_width mod 8 = 0; - v := data_width/8-1; - while v > 0 loop - v := v/2; - i := i + 1; - end loop; - return i; - end; - impure function empty_length(source : avalon_source_t) return natural is begin - return calc_empty_length(source.p_data_length); + assert source.p_data_length mod 8 = 0; + return calc_width(source.p_data_length/8); end; impure function empty_length(source : avalon_sink_t) return natural is begin - return calc_empty_length(source.p_data_length); + assert source.p_data_length mod 8 = 0; + return calc_width(source.p_data_length/8); end; impure function channel_length(source : avalon_source_t) return natural is