Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

vhdl - How to access implicit "=" function for an array type when it is overloaded in the same package?

I had a sudden thought. Is it possible to access the implicit "=" function for an array type when an overload exists in the same package as the array type declaration?

For example, in numeric_std, the unsigned and signed types are declared, along with overloads for the "=" function.

Lets say I want to compare an exact bitstring for signed and unsigned types, for example:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;  -- added to make full path to "=" function a requirement

variable a, b : unsigned(7 downto 0);
...
a := "UXUXUXUX";
b := "UXUXUXUX";

if a = b then  -- this fails with the overloaded "=" function

If I could access the implicit "=" function for unsigned, then the a = b check would pass. but ieee.numeric_std."=" will go direct to the overloaded version.

The only workaround here is to convert to std_logic_vector and compare using the implicit "=" function in std_logic_1164:

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.numeric_std_unsigned.all;  -- added to make full path to "=" function a requirement

variable a, b : unsigned(7 downto 0);
...
a := "UXUXUXUX";
b := "UXUXUXUX";

if ieee.std_logic_1164."="(std_logic_vector(a), std_logic_vector(b) ) then  

Unless I am missing a way to get at the implicit "=" function for unsigned?

question from:https://stackoverflow.com/questions/65952772/how-to-access-implicit-function-for-an-array-type-when-it-is-overloaded-in-t

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Why not write your own function and call it with function call syntax rather than operator syntax? The similar problem I ran into is with ?= / STD_MATCH. In the OSVVM package AlertLogPkg, I created MetaMatch. It is similar to STD_MATCH, except it returns TRUE for U=U, X=X, Z=Z, and W=W. All other values are consistent with STD_MATCH.

  type BooleanTableType is array(std_ulogic, std_ulogic) of boolean;

  constant MetaMatchTable : BooleanTableType := (
    --------------------------------------------------------------------------
    -- U      X      0      1      Z      W      L      H      -
    --------------------------------------------------------------------------
    (TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE),  -- | U |
    (FALSE, TRUE,  FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE),  -- | X |
    (FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, TRUE,  FALSE, TRUE),  -- | 0 |
    (FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, TRUE,  TRUE),  -- | 1 |
    (FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, TRUE),  -- | Z |
    (FALSE, FALSE, FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, TRUE),  -- | W |
    (FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, TRUE,  FALSE, TRUE),  -- | L |
    (FALSE, FALSE, FALSE, TRUE,  FALSE, FALSE, FALSE, TRUE,  TRUE),  -- | H |
    (TRUE,  TRUE,  TRUE,  TRUE,  TRUE,  TRUE,  TRUE,  TRUE,  TRUE)   -- | - |
    );

  function MetaMatch (l, r : std_ulogic) return boolean is
  begin
    return MetaMatchTable(l, r);
  end function MetaMatch;

  function MetaMatch (L, R : std_ulogic_vector) return boolean is
    alias aL : std_ulogic_vector(1 to L'length) is L;
    alias aR : std_ulogic_vector(1 to R'length) is R;
  begin
    if aL'length /= aR'length then
      --! log(OSVVM_ALERTLOG_ID, "AlertLogPkg.MetaMatch: Length Mismatch", DEBUG) ;
      return FALSE;
    else
      for i in aL'range loop
        if not (MetaMatchTable(aL(i), aR(i))) then
          return FALSE;
        end if;
      end loop;
      return TRUE;
    end if;
  end function MetaMatch;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...