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

📄 pred_fns.vhd

📁 debussy中文使用手册
💻 VHD
字号:
library IEEE;use std.standard.all;package functions is  type int_arr is array(Integer range<>) of INTEGER;  type bit_arr is array(Integer range<>) of Bit;  function int_Wired_OR (input : int_arr) return INTEGER;  function bit_Wired_OR (input : bit_arr) return Bit;  function bit_Wired_AND (input : bit_arr) return Bit;  function bits_to_int (input : Bit_Vector) return INTEGER ;  function "+" (Left, Right : Bit_Vector) return Bit_Vector;  function "+" (Left : Bit_Vector; Right : Integer) return Bit_Vector;  function "+" (Left : Integer; Right : Bit_Vector) return Bit_Vector;  function "-" (Left, Right : Bit_Vector) return Bit_Vector;  function "-" (Left : Bit_Vector; Right : Integer) return Bit_Vector;  function "-" (Left : Integer; Right : Bit_Vector) return Bit_Vector;  function "/" (Left, Right : Bit_Vector) return Bit_Vector;  function "/" (Left : Bit_Vector; Right : Integer) return Bit_Vector;  function "/" (Left : Integer; Right : Bit_Vector) return Integer;  function "*" (Left, Right : Bit_Vector) return Bit_Vector;  function "*" (Left : Bit_Vector; Right : Integer) return Bit_Vector;  function "*" (Left : Integer; Right : Bit_Vector) return Integer;  procedure left_shift (InpReg : inout Bit_Vector);  procedure sig_left_shift (signal InpReg : inout Bit_Vector);  procedure right_shift (InpReg : inout Bit_Vector);  procedure sig_right_shift (signal InpReg : inout Bit_Vector);end functions;package body functions is  procedure left_shift(InpReg : inout Bit_Vector) is  begin    if (InpReg'LEFT >= InpReg'Right)    then       for i in InpReg'RANGE loop         if i > InpReg'LOW         then           InpReg(i) := InpReg(i-1);         end if;       end loop;       InpReg(InpReg'LOW) := '0';    else       for i in InpReg'RANGE loop	 if i < InpReg'HIGH	 then	   InpReg(i) := InpReg(i+1);	 end if;       end loop;       InpReg(InpReg'HIGH) := '0';    end if;   end left_shift;  procedure sig_left_shift(signal InpReg : inout Bit_Vector) is  begin    if (InpReg'LEFT >= InpReg'Right)    then       for i in InpReg'RANGE loop         if i > InpReg'LOW         then           InpReg(i) <= InpReg(i-1);         end if;       end loop;       InpReg(InpReg'LOW) <= '0';    else       for i in InpReg'RANGE loop         if i < InpReg'HIGH                  then           InpReg(i) <= InpReg(i+1);         end if;       end loop;       InpReg(InpReg'HIGH) <= '0';    end if;  end sig_left_shift;  procedure right_shift(InpReg : inout Bit_Vector) is  begin    if (InpReg'Left >= InpReg'Right)    then       for i in InpReg'REVERSE_RANGE loop         if i < InpReg'HIGH         then           InpReg(i) := InpReg(i+1);         end if;       end loop;       InpReg(InpReg'HIGH) := '0';    else       for i in InpReg'RANGE loop         if i > InpReg'LOW         then	    InpReg(i) := InpReg(i-1);         end if;       end loop;       InpReg(InpReg'LOW) := '0';     end if;  end right_shift;  procedure sig_right_shift(signal InpReg : inout Bit_Vector) is  begin    if (InpReg'Left >= InpReg'Right)    then       for i in InpReg'REVERSE_RANGE loop         if i < InpReg'HIGH         then           InpReg(i) <= InpReg(i+1);         end if;       end loop;       InpReg(InpReg'HIGH) <= '0';    else       for i in InpReg'RANGE loop         if i > InpReg'LOW         then            InpReg(i) <= InpReg(i-1);         end if;       end loop;       InpReg(InpReg'LOW) <= '0';    end if;  end sig_right_shift;  function int_Wired_OR(input : int_arr) return INTEGER is  variable resolved_value : INTEGER := 0;  begin    for i in input'RANGE loop      if input(i) > 0 then	resolved_value := input(i);      end if;    end loop;    return resolved_value;   end int_Wired_OR;  function bits_to_int (input : Bit_Vector )return INTEGER is   variable ret_val : INTEGER := 0;  begin    for i in input'RANGE loop      if input(i) = '1' then	ret_val := 2**i + ret_val;      end if;    end loop;    return ret_val;  end bits_to_int;  function bit_Wired_OR (input : bit_arr) return Bit is  variable resolved_value : Bit;  begin    for i in input'RANGE loop      if input(i) = '1' then return '1';      end if;    end loop;    return '0';  end bit_Wired_OR;  function bit_Wired_AND (input : bit_arr) return Bit is  variable resolved_value : Bit;  begin    for i in input'RANGE loop      if input(i) = '0' then return '0';      end if;    end loop;    return '1';  end bit_Wired_AND;  function "+" (Left, Right : Bit_Vector) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Length downto 0);  variable carry : Bit := '0';  variable dummy : Bit_Vector(0 to 2);  variable i : Integer;  begin     for i in Left'Reverse_Range loop	dummy(0) := Left(i);	dummy(1) := Right(i);	dummy(2) := carry;        case dummy is	  when "000" => 	    return_vector(i) := '0';	    carry := '0';	  when "001" => 	    return_vector(i) := '1';	    carry := '0';	  when "010" => 	    return_vector(i) := '1';	    carry := '0';	  when "011" => 	    return_vector(i) := '0';	    carry := '1';	  when "100" => 	    return_vector(i) := '1';	    carry := '0';	  when "101" => 	    return_vector(i) := '0';	    carry := '1';	  when "110" => 	    return_vector(i) := '0';	    carry := '1';	  when "111" => 	    return_vector(i) := '1';	    carry := '1';	end case;     end loop;     return_vector(Left'Length) := carry;     return return_vector;  end;  function "+" (Left : Bit_Vector; Right : Integer) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Range);  variable Right_rem, Right_val : Integer;  variable carry : Bit := '0';  begin     Right_val := Right;     for i in Left'Range loop	Right_rem := Right_val rem 2;	Right_val := Right_val / 2;	if Right_rem = 1 then	   return_vector(i) := '1';	else	   return_vector(i) := '0';	end if;     end loop;     return_vector := return_vector + Left;     return return_vector;  end;  function "+" (Left : Integer; Right : Bit_Vector) return Bit_Vector is  variable return_vector : Bit_Vector(Right'Range);  variable Left_rem, Left_val : Integer;  variable carry : Bit := '0';  begin     Left_val := Left;     for i in Right'Range loop	Left_rem := Left_val rem 2;	Left_val := Left_val / 2;	if Left_rem = 1 then	   return_vector(i) := '1';	else	   return_vector(i) := '0';	end if;     end loop;     return_vector := return_vector + Left;     return return_vector;  end;  function "-" (Left, Right : Bit_Vector) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Length downto 0);  variable borrow : Bit := '0';  variable dummy : Bit_Vector(2 downto 0);  variable i : Integer;  begin     for i in Left'Reverse_Range loop	dummy(2) := Left(i);	dummy(1) := Right(i);	dummy(0) := borrow;        case dummy is	  when "000" => 	    return_vector(i) := '0';	    borrow := '0';	  when "001" => 	    return_vector(i) := '1';	    borrow := '1';	  when "010" => 	    return_vector(i) := '1';	    borrow := '1';	  when "011" => 	    return_vector(i) := '0';	    borrow := '1';	  when "100" => 	    return_vector(i) := '1';	    borrow := '0';	  when "101" => 	    return_vector(i) := '0';	    borrow := '0';	  when "110" => 	    return_vector(i) := '0';	    borrow := '0';	  when "111" => 	    return_vector(i) := '1';	    borrow := '1';	end case;     end loop;     return_vector(Left'Length) := borrow;     return return_vector;  end;  function "-" (Left : Bit_Vector; Right : Integer) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Range);  variable result : Bit_Vector(Left'Length downto 0);  variable Right_rem, Right_val : Integer;  variable carry : Bit := '0';  begin     Right_val := Right;     for i in Left'Range loop	Right_rem := Right_val rem 2;	Right_val := Right_val / 2;	if Right_rem = 1 then	   return_vector(i) := '1';	else	   return_vector(i) := '0';	end if;     end loop;     result := Left - return_vector;     return_vector := result(Left'Length - 1 downto 0);     return return_vector;  end;  function "-" (Left : Integer; Right : Bit_Vector) return Bit_Vector is  variable return_vector : Bit_Vector(Right'Range);  variable Left_rem, Left_val : Integer;  variable carry : Bit := '0';  begin     Left_val := Left;     for i in Right'Range loop	Left_rem := Left_val rem 2;	Left_val := Left_val / 2;	if Left_rem = 1 then	   return_vector(i) := '1';	else	   return_vector(i) := '0';	end if;     end loop;     return_vector := Left - return_vector;     return return_vector;  end;  function "/" (Left,Right : Bit_Vector) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Range);  variable Right_val : Integer;  variable Left_rem,Left_val : Integer;  begin     Left_val := bits_to_int(Left);     Right_val := bits_to_int(Right);     Left_val := Left_val / Right_val;     for i in Left'Range loop        Left_rem := Left_val rem 2;        Left_val := Left_val / 2;        if Left_rem = 1 then           return_vector(i) := '1';        else           return_vector(i) := '0';        end if;     end loop;     return return_vector;  end;  function "/" (Left : Bit_Vector; Right : Integer) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Range);  variable Left_rem,Left_val : Integer;  begin     Left_val := bits_to_int(Left);     Left_val := Left_val / Right;     for i in Left'Range loop        Left_rem := Left_val rem 2;        Left_val := Left_val / 2;        if Left_rem = 1 then           return_vector(i) := '1';        else           return_vector(i) := '0';        end if;     end loop;     return return_vector;  end;  function "/" (Left : Integer; Right : Bit_Vector) return Integer is  variable return_val : Integer;  begin     return_val := bits_to_int(Right);     return_val := Left / return_val;     return return_val;  end;  function "*" (Left,Right : Bit_Vector) return Bit_Vector is  variable return_vector : Bit_Vector(0 to (Left'Length + Right'Length -1));  variable Right_val : Integer;  variable Left_rem,Left_val : Integer;  begin     Left_val := bits_to_int(Left);     Right_val := bits_to_int(Right);     Left_val := Left_val * Right_val;     for i in return_vector'Range loop        Left_rem := Left_val rem 2;        Left_val := Left_val / 2;        if Left_rem = 1 then           return_vector(i) := '1';        else           return_vector(i) := '0';        end if;     end loop;     return return_vector;  end;  function "*" (Left : Bit_Vector; Right : Integer) return Bit_Vector is  variable return_vector : Bit_Vector(Left'Range);  variable Left_rem,Left_val : Integer;  begin     Left_val := bits_to_int(Left);     Left_val := Left_val * Right;     for i in Left'Range loop        Left_rem := Left_val rem 2;        Left_val := Left_val / 2;        if Left_rem = 1 then           return_vector(i) := '1';        else           return_vector(i) := '0';        end if;     end loop;     return return_vector;  end;  function "*" (Left : Integer; Right : Bit_Vector) return Integer is  variable return_val : Integer;  begin     return_val := bits_to_int(Right);     return_val := Left * return_val;     return return_val;  end;end functions;

⌨️ 快捷键说明

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