------------------------------------------------------------------------------ -- -- This package was developed by CAD Language Systems, Inc. as part of an -- effort to define a basis for portable VHDL models. It has been submitted -- to the VHDL Design Exchange Group (VDEG) to be considered as the basis for -- a set of industry-wide, portable modeling conventions. -- -- This package body contains the implementations of the subprograms defined -- in package VDEG_Portable.Types. -- -- HISTORY: -- 26-MAY-89 PJM Change statements of the form "if then -- exit; end if;" to "exit when ;". -- 11-MAY-89 PJM Updated to reflect May 9-10 VDEG consensus. -- 15-APR-89 WAG Created. -- ------------------------------------------------------------------------------ package body Types is -- An internal type to map Logic4 X Logic4 -> Logic4 for various functions: type Logic4Table is array (Logic4, Logic4) of Logic4; -- Logical operations: function "and" (L, R: Logic4) return Logic4 is constant Table: Logic4Table := (('X', '0', 'X', 'X'), ('0', '0', '0', '0'), ('X', '0', '1', 'X'), ('X', '0', 'X', 'X')); begin assert L /= 'Z' and R /= 'Z'; return Table (L, R); end "and"; function "nand" (L, R: Logic4) return Logic4 is begin assert L /= 'Z' and R /= 'Z'; return not (L and R); end "nand"; function "or" (L, R: Logic4) return Logic4 is constant Table: Logic4Table := (('X', 'X', '1', 'X'), ('X', '0', '1', 'X'), ('1', '1', '1', '1'), ('X', 'X', '1', 'X')); begin assert L /= 'Z' and R /= 'Z'; return Table (L, R); end "or"; function "nor" (L, R: Logic4) return Logic4 is begin assert L /= 'Z' and R /= 'Z'; return not (L or R); end "nor"; function "xor" (L, R: Logic4) return Logic4 is constant Table: Logic4Table := (('X', 'X', 'X', 'X'), ('X', '0', '1', 'X'), ('X', '1', '0', 'X'), ('X', 'X', 'X', 'X')); begin assert L /= 'Z' and R /= 'Z'; return Table (L, R); end "xor"; function "not" (Value: Logic4) return Logic4 is type Logic4Vector is array (Logic4) of Logic4; constant Table: Logic4Vector := ('X', '1', '0', 'X'); begin assert Value /= 'Z'; return Table (Value); end "not"; function "and" (L, R: Vector4) return Vector4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Vector4 (1 to L'length); begin assert L'length = R'length; for i in Result'range loop Result(i) := LV(i) and RV(i); end loop; return Result; end "and"; function "nand" (L, R: Vector4) return Vector4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Vector4 (1 to L'length); begin assert L'length = R'length; for i in Result'range loop Result(i) := LV(i) nand RV(i); end loop; return Result; end "nand"; function "or" (L, R: Vector4) return Vector4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Vector4 (1 to L'length); begin assert L'length = R'length; for i in Result'range loop Result(i) := LV(i) or RV(i); end loop; return Result; end "or"; function "nor" (L, R: Vector4) return Vector4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Vector4 (1 to L'length); begin assert L'length = R'length; for i in Result'range loop Result(i) := LV(i) nor RV(i); end loop; return Result; end "nor"; function "xor" (L, R: Vector4) return Vector4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Vector4 (1 to L'length); begin assert L'length = R'length; for i in Result'range loop Result(i) := LV(i) xor RV(i); end loop; return Result; end "xor"; function "not" (Value: Vector4) return Vector4 is alias V: Vector4 (1 to Value'length) is Value; variable Result: Vector4 (1 to Value'length); begin for i in Result'range loop Result(i) := not V(i); end loop; return Result; end "not"; -- Comparison operations returning Logic4: function "=" (L, R: Logic4) return Logic4 is constant Table: Logic4Table := (('X', 'X', 'X', 'X'), ('X', '1', '0', 'X'), ('X', '0', '1', 'X'), ('X', 'X', 'X', 'X')); begin assert L /= 'Z' and R /= 'Z'; return Table (L, R); end "="; function "/=" (L, R: Logic4) return Logic4 is begin assert L /= 'Z' and R /= 'Z'; return not (L = R); end "/="; function "=" (L, R: Vector4) return Logic4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Logic4; begin assert L'length = R'length; for i in LV'range loop Result := LV(i) = RV(i); if Result /= '1' then return Result; end if; end loop; return '1'; end "="; function "/=" (L, R: Vector4) return Logic4 is alias LV: Vector4 (1 to L'length) is L; alias RV: Vector4 (1 to R'length) is R; variable Result: Logic4; begin assert L'length = R'length; for i in LV'range loop Result := LV(i) /= RV(i); if Result /= '1' then return Result; end if; end loop; return '1'; end "/="; -- Resolution functions for wired signals: function WiredX (V: Vector4) return Logic4 is variable Result: Logic4 := 'Z'; constant Table: Logic4Table := (('X', 'X', 'X', 'X'), ('X', '0', 'X', '0'), ('X', 'X', '1', '1'), ('X', '0', '1', 'Z')); begin for i in V'range loop Result := Table (Result, V(i)); exit when Result = 'X'; -- local optimization end loop; return Result; end WiredX; function WiredAnd (V: Vector4) return Logic4 is variable Result: Logic4 := 'Z'; constant Table: Logic4Table := (('X', '0', 'X', 'X'), ('0', '0', '0', '0'), ('X', '0', '1', '1'), ('X', '0', '1', 'Z')); begin for i in V'range loop Result := Table (Result, V(i)); exit when Result = '0'; -- local optimization end loop; return Result; end WiredAnd; function WiredOr (V: Vector4) return Logic4 is variable Result: Logic4 := 'Z'; constant Table: Logic4Table := (('X', 'X', '1', 'X'), ('X', '0', '1', '0'), ('1', '1', '1', '1'), ('X', '0', '1', 'Z')); begin for i in V'range loop Result := Table (Result, V(i)); exit when Result = '1'; -- local optimization end loop; return Result; end WiredOr; -- Definitions for driving various types: function Drive (V: Logic4) return Logic4 is begin return V; end Drive; function Drive (V: Vector4) return Vector4 is begin return V; end Drive; function Drive (V: Vector4) return BusX is begin return BusX (V); end Drive; function Drive (V: Vector4) return BusAnd is begin return BusAnd (V); end Drive; function Drive (V: Vector4) return BusOr is begin return BusOr (V); end Drive; -- Functions for sensing various types: function Sense (V: Logic4; vZ: LX01) return Logic4 is begin if V = 'Z' then return vZ; else return V; end if; end Sense; function Sense (V: Vector4; vZ: LX01) return Vector4 is alias Value: Vector4 (1 to V'length) is V; variable Result: Vector4 (1 to V'length); begin for i in Value'range loop Result(i) := Sense (Value(i), vZ); end loop; return Result; end Sense; function Sense (V: BusX; vZ: LX01) return Vector4 is alias Value: BusX (1 to V'length) is V; variable Result: Vector4 (1 to V'length); begin for i in Value'range loop Result(i) := Sense (Value(i), vZ); end loop; return Result; end Sense; function Sense (V: BusAnd; vZ: LX01) return Vector4 is alias Value: BusAnd (1 to V'length) is V; variable Result: Vector4 (1 to V'length); begin for i in Value'range loop Result(i) := Sense (Value(i), vZ); end loop; return Result; end Sense; function Sense (V: BusOr; vZ: LX01) return Vector4 is alias Value: BusOr (1 to V'length) is V; variable Result: Vector4 (1 to V'length); begin for i in Value'range loop Result(i) := Sense (Value(i), vZ); end loop; return Result; end Sense; end Types;