⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integer_plus.bdy

📁 6端口寄存器IP内核VHDL源代码
💻 BDY
字号:
-- Source: T:/hwdev/generic/VHDL/integer_plus.bdy
-- Designer: Tim Pagden    

-- Description: Extensions to the std.standard.integer package to allow
-- conversion functions and mixed operators
 
-- Revision history: T:/hwdev/generic/etc/integer_plus_bdy.dnh
-- 29.12.97 TP 0.0 created from integer_plus.pkg

library IEEE;
-- library vfp;

package body integer_plus is
  use IEEE.std_logic_1164.all;
  -- use vfp.std_logic_class.all;
    
  -- extensions to vfp.integer_class and std.standard.integer
  -- integer defined in std.standard
  -- integer subtypes

  -- ____________________
  -- conversion functions

  -- vfp.integer_plus.to_integer (std_ulogic_vector) -> integer
  function to_integer (  -- 29.11.95
    a: std_ulogic_vector
  ) return integer is
    variable y: integer := 0;
  begin
    y := 0;
    if (a'length < 32) then
      for i in a'length-1 downto 0 loop
        y := y * 2;
        if (a(i) = '1') or (a(i) = 'H') then
          y := y + 1;
        elsif (a(i) = 'U') or (a(i) = 'X') or (a(i) = 'Z') or
              (a(i) = 'W') or (a(i) = '-') then
  			  y := y + 0;
  --        assert false
  --          report "Error 0001." & 
  --                 "Library = vfp." & 
  --                 "Package Body = generic_conversions." & 
  --                 "Function = to_integer." & 
  --                 "The std_ulogic_vector input to this function MUST contain 0, 1, L, or H."
  --          severity error;
  --      upon this assertion, 0 will have effectively been added to y
  --    else y := y + 0; thus there's no update to y for this "bit" anyway
        end if;       
      end loop;
    else
      assert false
        report "Error 0002." & 
               "Library = vfp." & 
               "Package Body = generic_conversions." & 
               "Function = to_integer." & 
               "The std_ulogic_vector input to this function MUST be less than 32 bits."
        severity error;
    end if;
    return y;      -- y returns 0 if std_ulogic_vector is > 31 bits
  end to_integer; 
  
  -- vfp.integer_plus.to_integer (std_logic_vector) -> integer
  function to_integer (   -- 03.02.95
    a: std_logic_vector
  ) return integer is
    variable y: integer := 0;
  begin
    y := 0;
    if (a'length < 32) then
      for i in a'length-1 downto 0 loop
        y := y * 2;
        if (a(i) = '1') or (a(i) = 'H') then
          y := y + 1;
        elsif (a(i) = 'U') or (a(i) = 'X') or (a(i) = 'Z') or
              (a(i) = 'W') or (a(i) = '-') then
  			  y := y + 0;
  --        assert false
  --          report "Error 0001." & 
  --                 "Library = vfp." & 
  --                 "Package Body = generic_conversions." & 
  --                 "Function = to_integer." & 
  --                 "The std_logic_vector input to this function MUST contain 0, 1, L, or H."
  --          severity error;
  --      upon this assertion, 0 will have effectively been added to y
  --    else y := y + 0; thus there's no update to y for this "bit" anyway
        end if;       
      end loop;
    else
      assert false
        report "Error 0002." & 
               "Library = vfp." & 
               "Package Body = generic_conversions." & 
               "Function = to_integer." & 
               "The std_logic_vector input to this function MUST be less than 32 bits."
        severity error;
    end if;
    return y;      -- y returns 0 if std_logic_vector is > 31 bits
  end to_integer; 
  
  -- vfp.integer_plus.to_integer (twos_complement) -> integer
  function to_integer (    -- 29.11.95
    a: twos_complement
  ) return integer is
    variable y: integer := 0;
  begin
    if (a(a'length-1) = '1') or (a(a'length-1) = 'H') then
      y := -1;
    elsif (a(a'length-1) = 'U') or (a(a'length-1) = 'X') or (a(a'length-1) = 'Z') or
          (a(a'length-1) = 'W') or (a(a'length-1) = '-') then
  		y := 0; -- was integer'low
  --    assert false
  --      report "Warning 0001." & 
  --             "Library = vfp." & 
  --             "Package Body = generic_conversions." & 
  --             "Function = to_integer (input = 2's complement)." & 
  --             "The 2's complement input to this function MUST contain 0, 1, L, or H."
  --      severity warning;
  --  upon this assertion, y will still be uninitialized
    else       -- a(i'length-1) is '0' or 'L'
      y := 0;       
    end if;         
    for i in a'length-2 downto 0 loop
      y := y * 2;
      if (a(i) = '1') or (a(i) = 'H') then
        y := y + 1;
      elsif (a(i) = 'U') or (a(i) = 'X') or (a(i) = 'Z') or
            (a(i) = 'W') or (a(i) = '-') then
  		  y := y + 0;
  --      assert false
  --        report "Warning 0002." & 
  --               "Library = vfp." & 
  --               "Package Body = generic_conversions." & 
  --               "Function = to_integer (input = 2's complement)." & 
  --               "The 2's complement input to this function MUST contain 0, 1, L, or H."
  --        severity warning;
  --    upon this assertion, 0 will have effectively been added to y
  --  else y := y + 0; thus there's no update to y for this "bit" anyway
      end if;       
    end loop;
    return y;
  end to_integer; 

  -- mixed operators

end integer_plus;



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -