OpenCores
URL https://opencores.org/ocsvn/common_pkg/common_pkg/trunk

Subversion Repositories common_pkg

[/] [common_pkg/] [trunk/] [common_pkg.vhd] - Diff between revs 6 and 9

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 6 Rev 9
Line 1... Line 1...
 
 
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
--
--
-- Copyright (C) 2009
-- Copyright (C) 2019
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
--
--
-- This program is free software: you can redistribute it and/or modify
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- it under the terms of the GNU General Public License as published by
Line 18... Line 17...
-- You should have received a copy of the GNU General Public License
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
--
--
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
 
 
 
-- Author:
 
-- . Eric Kooistra
 
-- Purpose:
 
-- . Collection of commonly used base funtions
 
-- Interface:
 
-- . [n/a]
 
-- Description:
 
-- . This is a package containing generic constants and functions.
 
-- . More information can be found in the comments near the code.
 
 
LIBRARY IEEE;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE IEEE.NUMERIC_STD.ALL;
USE IEEE.MATH_REAL.ALL;
USE IEEE.MATH_REAL.ALL;
 
 
Line 379... Line 388...
  FUNCTION s_round_up(vec : STD_LOGIC_VECTOR; n : NATURAL; clip : BOOLEAN) RETURN STD_LOGIC_VECTOR;  -- idem but round up to +infinity (s_round_up = u_round)
  FUNCTION s_round_up(vec : STD_LOGIC_VECTOR; n : NATURAL; clip : BOOLEAN) RETURN STD_LOGIC_VECTOR;  -- idem but round up to +infinity (s_round_up = u_round)
  FUNCTION s_round_up(vec : STD_LOGIC_VECTOR; n : NATURAL)                 RETURN STD_LOGIC_VECTOR;  -- idem but round up to +infinity (s_round_up = u_round)
  FUNCTION s_round_up(vec : STD_LOGIC_VECTOR; n : NATURAL)                 RETURN STD_LOGIC_VECTOR;  -- idem but round up to +infinity (s_round_up = u_round)
  FUNCTION u_round(   vec : STD_LOGIC_VECTOR; n : NATURAL; clip : BOOLEAN) RETURN STD_LOGIC_VECTOR;  -- idem round up for unsigned values
  FUNCTION u_round(   vec : STD_LOGIC_VECTOR; n : NATURAL; clip : BOOLEAN) RETURN STD_LOGIC_VECTOR;  -- idem round up for unsigned values
  FUNCTION u_round(   vec : STD_LOGIC_VECTOR; n : NATURAL)                 RETURN STD_LOGIC_VECTOR;  -- idem round up for unsigned values
  FUNCTION u_round(   vec : STD_LOGIC_VECTOR; n : NATURAL)                 RETURN STD_LOGIC_VECTOR;  -- idem round up for unsigned values
 
 
 
  FUNCTION u_to_s(u : NATURAL; w : NATURAL) RETURN INTEGER;   -- interpret w bit unsigned u as w bit   signed, and remove any MSbits
 
  FUNCTION s_to_u(s : INTEGER; w : NATURAL) RETURN NATURAL;   -- interpret w bit   signed s as w bit unsigned, and remove any MSbits
 
 
 
  FUNCTION u_wrap(u : NATURAL; w : NATURAL) RETURN NATURAL;   -- return u & 2**w-1 (bit wise and), so keep w LSbits of unsigned u, and remove MSbits
 
  FUNCTION s_wrap(s : INTEGER; w : NATURAL) RETURN INTEGER;   -- return s & 2**w-1 (bit wise and), so keep w LSbits of   signed s, and remove MSbits
 
 
 
  FUNCTION u_clip(u : NATURAL; max : NATURAL) RETURN NATURAL;                  -- if s < max return s, else return n
 
  FUNCTION s_clip(s : INTEGER; max : NATURAL; min : INTEGER) RETURN INTEGER;   -- if s <=  min return  min, else if s >= max return max, else return s
 
  FUNCTION s_clip(s : INTEGER; max : NATURAL               ) RETURN INTEGER;   -- if s <= -max return -max, else if s >= max return max, else return s
 
 
  FUNCTION hton(a : STD_LOGIC_VECTOR; w, sz : NATURAL) RETURN STD_LOGIC_VECTOR;  -- convert endianity from host to network, sz in symbols of width w
  FUNCTION hton(a : STD_LOGIC_VECTOR; w, sz : NATURAL) RETURN STD_LOGIC_VECTOR;  -- convert endianity from host to network, sz in symbols of width w
  FUNCTION hton(a : STD_LOGIC_VECTOR;    sz : NATURAL) RETURN STD_LOGIC_VECTOR;  -- convert endianity from host to network, sz in bytes
  FUNCTION hton(a : STD_LOGIC_VECTOR;    sz : NATURAL) RETURN STD_LOGIC_VECTOR;  -- convert endianity from host to network, sz in bytes
  FUNCTION hton(a : STD_LOGIC_VECTOR                 ) RETURN STD_LOGIC_VECTOR;  -- convert endianity from host to network, for all bytes in a
  FUNCTION hton(a : STD_LOGIC_VECTOR                 ) RETURN STD_LOGIC_VECTOR;  -- convert endianity from host to network, for all bytes in a
  FUNCTION ntoh(a : STD_LOGIC_VECTOR;    sz : NATURAL) RETURN STD_LOGIC_VECTOR;  -- convert endianity from network to host, sz in bytes, ntoh() = hton()
  FUNCTION ntoh(a : STD_LOGIC_VECTOR;    sz : NATURAL) RETURN STD_LOGIC_VECTOR;  -- convert endianity from network to host, sz in bytes, ntoh() = hton()
  FUNCTION ntoh(a : STD_LOGIC_VECTOR                 ) RETURN STD_LOGIC_VECTOR;  -- convert endianity from network to host, for all bytes in a, ntoh() = hton()
  FUNCTION ntoh(a : STD_LOGIC_VECTOR                 ) RETURN STD_LOGIC_VECTOR;  -- convert endianity from network to host, for all bytes in a, ntoh() = hton()
Line 1909... Line 1928...
  FUNCTION u_round(vec : STD_LOGIC_VECTOR; n : NATURAL) RETURN STD_LOGIC_VECTOR IS
  FUNCTION u_round(vec : STD_LOGIC_VECTOR; n : NATURAL) RETURN STD_LOGIC_VECTOR IS
  BEGIN
  BEGIN
    RETURN u_round(vec, n, FALSE);  -- no round clip
    RETURN u_round(vec, n, FALSE);  -- no round clip
  END;
  END;
 
 
 
  FUNCTION u_to_s(u : NATURAL; w : NATURAL) RETURN INTEGER IS
 
    VARIABLE v_u : STD_LOGIC_VECTOR(31 DOWNTO 0) := TO_UVEC(u, 32);  -- via 32 bit word to avoid NUMERIC_STD.TO_SIGNED: vector truncated warming
 
  BEGIN
 
    RETURN TO_SINT(v_u(w-1 DOWNTO 0));
 
  END;
 
 
 
  FUNCTION s_to_u(s : INTEGER; w : NATURAL) RETURN NATURAL IS
 
    VARIABLE v_s : STD_LOGIC_VECTOR(31 DOWNTO 0) := TO_SVEC(s, 32);  -- via 32 bit word to avoid NUMERIC_STD.TO_SIGNED: vector truncated warming
 
  BEGIN
 
    RETURN TO_UINT(v_s(w-1 DOWNTO 0));
 
  END;
 
 
 
  FUNCTION u_wrap(u : NATURAL; w : NATURAL) RETURN NATURAL IS
 
    VARIABLE v_u : STD_LOGIC_VECTOR(31 DOWNTO 0) := TO_UVEC(u, 32);  -- via 32 bit word to avoid NUMERIC_STD.TO_SIGNED: vector truncated warming
 
  BEGIN
 
    RETURN TO_UINT(v_u(w-1 DOWNTO 0));
 
  END;
 
 
 
  FUNCTION s_wrap(s : INTEGER; w : NATURAL) RETURN INTEGER IS
 
    VARIABLE v_s : STD_LOGIC_VECTOR(31 DOWNTO 0) := TO_SVEC(s, 32);  -- via 32 bit word to avoid NUMERIC_STD.TO_SIGNED: vector truncated warming
 
  BEGIN
 
    RETURN TO_SINT(v_s(w-1 DOWNTO 0));
 
  END;
 
 
 
  FUNCTION u_clip(u : NATURAL; max : NATURAL) RETURN NATURAL IS
 
  BEGIN
 
    IF u > max THEN
 
      RETURN max;
 
    ELSE
 
      RETURN u;
 
    END IF;
 
  END;
 
 
 
  FUNCTION s_clip(s : INTEGER; max : NATURAL; min : INTEGER) RETURN INTEGER IS
 
  BEGIN
 
    IF s < min THEN
 
      RETURN min;
 
    ELSE
 
      IF s > max THEN
 
        RETURN max;
 
      ELSE
 
        RETURN s;
 
      END IF;
 
    END IF;
 
  END;
 
 
 
  FUNCTION s_clip(s : INTEGER; max : NATURAL) RETURN INTEGER IS
 
  BEGIN
 
    RETURN s_clip(s, max, -max);
 
  END;
 
 
  FUNCTION hton(a : STD_LOGIC_VECTOR; w, sz : NATURAL) RETURN STD_LOGIC_VECTOR IS
  FUNCTION hton(a : STD_LOGIC_VECTOR; w, sz : NATURAL) RETURN STD_LOGIC_VECTOR IS
    VARIABLE v_a : STD_LOGIC_VECTOR(a'LENGTH-1 DOWNTO 0) := a;  -- map a to range [h:0]
    VARIABLE v_a : STD_LOGIC_VECTOR(a'LENGTH-1 DOWNTO 0) := a;  -- map a to range [h:0]
    VARIABLE v_b : STD_LOGIC_VECTOR(a'LENGTH-1 DOWNTO 0) := a;  -- default b = a
    VARIABLE v_b : STD_LOGIC_VECTOR(a'LENGTH-1 DOWNTO 0) := a;  -- default b = a
    VARIABLE vL  : NATURAL;
    VARIABLE vL  : NATURAL;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.