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

📄 numeric_bit-body.vhdl

📁 vhdl集成电路设计软件.需要用gcc-4.0.2版本编译.
💻 VHDL
📖 第 1 页 / 共 4 页
字号:
  -- Id: S.1  function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is  begin    if (ARG'LENGTH < 1) then return NAU;    end if;    return UNSIGNED(XSLL(BIT_VECTOR(ARG), COUNT));  end SHIFT_LEFT;  -- Id: S.2  function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is  begin    if (ARG'LENGTH < 1) then return NAU;    end if;    return UNSIGNED(XSRL(BIT_VECTOR(ARG), COUNT));  end SHIFT_RIGHT;  -- Id: S.3  function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is  begin    if (ARG'LENGTH < 1) then return NAS;    end if;    return SIGNED(XSLL(BIT_VECTOR(ARG), COUNT));  end SHIFT_LEFT;  -- Id: S.4  function SHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is  begin    if (ARG'LENGTH < 1) then return NAS;    end if;    return SIGNED(XSRA(BIT_VECTOR(ARG), COUNT));  end SHIFT_RIGHT;  --============================================================================  -- Id: S.5  function ROTATE_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is  begin    if (ARG'LENGTH < 1) then return NAU;    end if;    return UNSIGNED(XROL(BIT_VECTOR(ARG), COUNT));  end ROTATE_LEFT;  -- Id: S.6  function ROTATE_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED is  begin    if (ARG'LENGTH < 1) then return NAU;    end if;    return UNSIGNED(XROR(BIT_VECTOR(ARG), COUNT));  end ROTATE_RIGHT;  -- Id: S.7  function ROTATE_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is  begin    if (ARG'LENGTH < 1) then return NAS;    end if;    return SIGNED(XROL(BIT_VECTOR(ARG), COUNT));  end ROTATE_LEFT;  -- Id: S.8  function ROTATE_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED is  begin    if (ARG'LENGTH < 1) then return NAS;    end if;    return SIGNED(XROR(BIT_VECTOR(ARG), COUNT));  end ROTATE_RIGHT;  --============================================================================--START-V93  ------------------------------------------------------------------------------  -- Note : Function S.9 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.9  function "sll" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is  begin    if (COUNT >= 0) then      return SHIFT_LEFT(ARG, COUNT);    else      return SHIFT_RIGHT(ARG, -COUNT);    end if;  end "sll";  ------------------------------------------------------------------------------  -- Note : Function S.10 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.10  function "sll" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is  begin    if (COUNT >= 0) then      return SHIFT_LEFT(ARG, COUNT);    else      return SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), -COUNT));    end if;  end "sll";  ------------------------------------------------------------------------------  -- Note : Function S.11 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.11  function "srl" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is  begin    if (COUNT >= 0) then      return SHIFT_RIGHT(ARG, COUNT);    else      return SHIFT_LEFT(ARG, -COUNT);    end if;  end "srl";  ------------------------------------------------------------------------------  -- Note : Function S.12 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.12  function "srl" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is  begin    if (COUNT >= 0) then      return SIGNED(SHIFT_RIGHT(UNSIGNED(ARG), COUNT));    else      return SHIFT_LEFT(ARG, -COUNT);    end if;  end "srl";  ------------------------------------------------------------------------------  -- Note : Function S.13 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.13  function "rol" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is  begin    if (COUNT >= 0) then      return ROTATE_LEFT(ARG, COUNT);    else      return ROTATE_RIGHT(ARG, -COUNT);    end if;  end "rol";  ------------------------------------------------------------------------------  -- Note : Function S.14 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.14  function "rol" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is  begin    if (COUNT >= 0) then      return ROTATE_LEFT(ARG, COUNT);    else      return ROTATE_RIGHT(ARG, -COUNT);    end if;  end "rol";  ------------------------------------------------------------------------------  -- Note : Function S.15 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.15  function "ror" (ARG: UNSIGNED; COUNT: INTEGER) return UNSIGNED is  begin    if (COUNT >= 0) then      return ROTATE_RIGHT(ARG, COUNT);    else      return ROTATE_LEFT(ARG, -COUNT);    end if;  end "ror";  ------------------------------------------------------------------------------  -- Note : Function S.16 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: S.16  function "ror" (ARG: SIGNED; COUNT: INTEGER) return SIGNED is  begin    if (COUNT >= 0) then      return ROTATE_RIGHT(ARG, COUNT);    else      return ROTATE_LEFT(ARG, -COUNT);    end if;  end "ror";--END-V93  --============================================================================  -- Id: D.1  function TO_INTEGER (ARG: UNSIGNED) return NATURAL is    constant ARG_LEFT: INTEGER := ARG'LENGTH-1;    alias XARG: UNSIGNED(ARG_LEFT downto 0) is ARG;    variable RESULT: NATURAL := 0;  begin    if (ARG'LENGTH < 1) then      assert NO_WARNING          report "NUMERIC_BIT.TO_INTEGER: null detected, returning 0"          severity WARNING;      return 0;    end if;    for I in XARG'RANGE loop      RESULT := RESULT+RESULT;      if XARG(I) = '1' then        RESULT := RESULT + 1;      end if;    end loop;    return RESULT;  end TO_INTEGER;  -- Id: D.2  function TO_INTEGER (ARG: SIGNED) return INTEGER is  begin    if (ARG'LENGTH < 1) then      assert NO_WARNING          report "NUMERIC_BIT.TO_INTEGER: null detected, returning 0"          severity WARNING;      return 0;    end if;    if ARG(ARG'LEFT) = '0' then      return TO_INTEGER(UNSIGNED(ARG));    else      return (- (TO_INTEGER(UNSIGNED(- (ARG + 1)))) -1);    end if;  end TO_INTEGER;  -- Id: D.3  function TO_UNSIGNED (ARG, SIZE: NATURAL) return UNSIGNED is    variable RESULT: UNSIGNED(SIZE-1 downto 0);    variable I_VAL: NATURAL := ARG;  begin    if (SIZE < 1) then return NAU;    end if;    for I in 0 to RESULT'LEFT loop      if (I_VAL mod 2) = 0 then        RESULT(I) := '0';      else RESULT(I) := '1';      end if;      I_VAL := I_VAL/2;    end loop;    if not(I_VAL =0) then      assert NO_WARNING          report "NUMERIC_BIT.TO_UNSIGNED: vector truncated"          severity WARNING;    end if;    return RESULT;  end TO_UNSIGNED;  -- Id: D.4  function TO_SIGNED (ARG: INTEGER;    SIZE: NATURAL) return SIGNED is        variable RESULT: SIGNED(SIZE-1 downto 0);    variable B_VAL: BIT := '0';    variable I_VAL: INTEGER := ARG;  begin    if (SIZE < 1) then return NAS;    end if;    if (ARG < 0) then      B_VAL := '1';      I_VAL := -(ARG+1);    end if;    for I in 0 to RESULT'LEFT loop      if (I_VAL mod 2) = 0 then        RESULT(I) := B_VAL;      else        RESULT(I) := not B_VAL;      end if;      I_VAL := I_VAL/2;    end loop;    if ((I_VAL/=0) or (B_VAL/=RESULT(RESULT'LEFT))) then      assert NO_WARNING          report "NUMERIC_BIT.TO_SIGNED: vector truncated"          severity WARNING;    end if;    return RESULT;  end TO_SIGNED;  --============================================================================  -- Id: R.1  function RESIZE (ARG: SIGNED; NEW_SIZE: NATURAL) return SIGNED is    alias INVEC: SIGNED(ARG'LENGTH-1 downto 0) is ARG;    variable RESULT: SIGNED(NEW_SIZE-1 downto 0) := (others => '0');    constant BOUND: INTEGER := MIN(ARG'LENGTH, RESULT'LENGTH)-2;  begin    if (NEW_SIZE < 1) then return NAS;    end if;    if (ARG'LENGTH = 0) then return RESULT;    end if;    RESULT := (others => ARG(ARG'LEFT));    if BOUND >= 0 then      RESULT(BOUND downto 0) := INVEC(BOUND downto 0);    end if;    return RESULT;  end RESIZE;  -- Id: R.2  function RESIZE (ARG: UNSIGNED; NEW_SIZE: NATURAL) return UNSIGNED is    constant ARG_LEFT: INTEGER := ARG'LENGTH-1;    alias XARG: UNSIGNED(ARG_LEFT downto 0) is ARG;    variable RESULT: UNSIGNED(NEW_SIZE-1 downto 0) := (others => '0');  begin    if (NEW_SIZE < 1) then return NAU;    end if;    if XARG'LENGTH =0 then return RESULT;    end if;    if (RESULT'LENGTH < ARG'LENGTH) then      RESULT(RESULT'LEFT downto 0) := XARG(RESULT'LEFT downto 0);    else      RESULT(RESULT'LEFT downto XARG'LEFT+1) := (others => '0');      RESULT(XARG'LEFT downto 0) := XARG;    end if;    return RESULT;  end RESIZE;  --============================================================================  -- Id: L.1  function "not" (L: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(not(BIT_VECTOR(L)));    return RESULT;  end "not";  -- Id: L.2  function "and" (L, R: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(BIT_VECTOR(L) and BIT_VECTOR(R));    return RESULT;  end "and";  -- Id: L.3  function "or" (L, R: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(BIT_VECTOR(L) or BIT_VECTOR(R));    return RESULT;  end "or";  -- Id: L.4  function "nand" (L, R: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(BIT_VECTOR(L) nand BIT_VECTOR(R));    return RESULT;  end "nand";  -- Id: L.5  function "nor" (L, R: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(BIT_VECTOR(L) nor BIT_VECTOR(R));    return RESULT;  end "nor";  -- Id: L.6  function "xor" (L, R: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(BIT_VECTOR(L) xor BIT_VECTOR(R));    return RESULT;  end "xor";--START-V93  ------------------------------------------------------------------------------  -- Note : Function L.7 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: L.7  function "xnor" (L, R: UNSIGNED) return UNSIGNED is    variable RESULT: UNSIGNED(L'LENGTH-1 downto 0);  begin    RESULT := UNSIGNED(BIT_VECTOR(L) xnor BIT_VECTOR(R));    return RESULT;  end "xnor";--END-V93  -- Id: L.8  function "not" (L: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(not(BIT_VECTOR(L)));    return RESULT;  end "not";  -- Id: L.9  function "and" (L, R: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(BIT_VECTOR(L) and BIT_VECTOR(R));    return RESULT;  end "and";  -- Id: L.10  function "or" (L, R: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(BIT_VECTOR(L) or BIT_VECTOR(R));    return RESULT;  end "or";  -- Id: L.11  function "nand" (L, R: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(BIT_VECTOR(L) nand BIT_VECTOR(R));    return RESULT;  end "nand";  -- Id: L.12  function "nor" (L, R: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(BIT_VECTOR(L) nor BIT_VECTOR(R));    return RESULT;  end "nor";  -- Id: L.13  function "xor" (L, R: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(BIT_VECTOR(L) xor BIT_VECTOR(R));    return RESULT;  end "xor";--START-V93  ------------------------------------------------------------------------------  -- Note : Function L.14 is not compatible with VHDL 1076-1987. Comment  -- out the function (declaration and body) for VHDL 1076-1987 compatibility.  ------------------------------------------------------------------------------  -- Id: L.14  function "xnor" (L, R: SIGNED) return SIGNED is    variable RESULT: SIGNED(L'LENGTH-1 downto 0);  begin    RESULT := SIGNED(BIT_VECTOR(L) xnor BIT_VECTOR(R));    return RESULT;  end "xnor";--END-V93  --============================================================================  -- Id: E.1  function RISING_EDGE (signal S: BIT) return BOOLEAN is  begin    return S'EVENT and S = '1';  end RISING_EDGE;  -- Id: E.2  function FALLING_EDGE (signal S: BIT) return BOOLEAN is  begin    return S'EVENT and S = '0';  end FALLING_EDGE;  --============================================================================end NUMERIC_BIT;

⌨️ 快捷键说明

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