library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_signed.all;

package MINE is
  function SEARCH(VECTOR, SUBVECTOR : std_logic_vector) return integer;
  subtype ONE_SIDED is integer range 2 to integer'high;
  --type ONE_SIDED_VECTOR is array ONE_SIDED of std_logic;
  subtype ONE_SIDED_ARRAY is std_logic_vector(ONE_SIDED);
end MINE;

package body MINE is
  function SEARCH(VECTOR, SUBVECTOR : std_logic_vector) return integer is
    variable POSITION : integer;
    variable FOUND : boolean := FALSE;
  begin
    POSITION := -1;
    if (VECTOR'length < SUBVECTOR'length) then
      report "Incorrect usage of SEARCH function"
      severity error;
      return POSITION;
    end if;
    for I in VECTOR'length - 1 downto SUBVECTOR'length - 1 loop
      if not FOUND then
        if (VECTOR(I downto I - (SUBVECTOR'length -1)) = SUBVECTOR) then
          POSITION := I;
          FOUND := TRUE;
        end if;
      end if;
    end loop;
    return POSITION;
  end SEARCH;
end MINE;

use work.MINE.all;
library ieee;
use ieee.std_logic_1164.all;

entity TEST_SEARCH is
end TEST_SEARCH;

architecture TEST of TEST_SEARCH is
  signal A : std_logic_vector(2 downto 0) := "000";
  signal B : std_logic_vector(7 downto 0) := "11111111";
  signal C : std_logic_vector(32 downto 0) :=
             "110010101111000111111111100101011";
  signal D, E, F : integer;
begin
  D <= SEARCH(C, A) after 1 ns;
  E <= SEARCH(B, A) after 2 ns;
  F <= SEARCH(A, B) after 3 ns;
end TEST;
