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

Subversion Repositories motion_estimation_processor

[/] [motion_estimation_processor/] [trunk/] [src_me/] [sad_selector.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 eejlny
----------------------------------------------------------------------------
2
--  This file is a part of the LM VHDL IP LIBRARY
3
--  Copyright (C) 2009 Jose Nunez-Yanez
4
--
5
--  This program is free software; you can redistribute it and/or modify
6
--  it under the terms of the GNU General Public License as published by
7
--  the Free Software Foundation; either version 2 of the License, or
8
--  (at your option) any later version.
9
--
10
--  See the file COPYING for the full details of the license.
11
--
12
--  The license allows free and unlimited use of the library and tools for research and education purposes. 
13
--  The full LM core supports many more advanced motion estimation features and it is available under a 
14
--  low-cost commercial license. See the readme file to learn more or contact us at 
15
--  eejlny@byacom.co.uk or www.byacom.co.uk
16
--------------------------------------
17
--  entity       = sad_selector     --
18
--  version      = 1.0              --
19
--  last update  = 30/12/07         --
20
--  author       = Jose Nunez       --
21
--------------------------------------
22
library IEEE;
23
use IEEE.std_logic_1164.all;
24
use IEEE.std_logic_unsigned."<";
25
use IEEE.std_logic_unsigned."+";
26
use IEEE.Numeric_STD.all;
27
use work.config.all;
28
 
29
entity sad_selector is
30
generic (integer_pipeline_count : integer);
31
port (
32
      clk : in std_logic;
33
        reset : in std_logic;
34
        clear : in std_logic;
35
      calculate_sad_done : in std_logic;
36
        active_pipelines : in std_logic_vector(CFG_PIPELINE_COUNT-1 downto 0);
37
      update : in std_logic; --end of program
38
        update_fp : in std_logic; -- end of iteraction
39
        best_eu : out std_logic_vector(3 downto 0);
40
        best_sad : in std_logic_vector(15 downto 0);
41
        best_mv : in std_logic_vector(15 downto 0);
42
      rest_best_sad : in rest_type_displacement;
43
        rest_best_mv : in rest_type_displacement;
44
        best_sad_out : out std_logic_vector(15 downto 0);
45
        best_mv_out : out std_logic_vector(15 downto 0));
46
end sad_selector;
47
 
48
architecture behavioral of sad_selector is
49
 
50
type eu_id_type is array(CFG_PIPELINE_COUNT-1 downto 0) of std_logic_vector(3 downto 0); -- max number of integer eu is 15
51
-- zero identifies when there is no winner
52
type active_pipelines_type is array(5 downto 0) of std_logic_vector(CFG_PIPELINE_COUNT-1 downto 0);
53
 
54
type state_register_type is record
55
   best_sad_candidate : std_logic_vector(15 downto 0); -- found sad for the best mv
56
   best_sad : std_logic_vector(15 downto 0); -- stored sad for the best mv
57
   best_mv  : std_logic_vector(15 downto 0); -- mv associated to best sad
58
   best_eu : std_logic_vector(3 downto 0);
59
   eu_id : eu_id_type; -- keep track of the winning eu
60
   active_pipelines_r : active_pipelines_type; -- reproduce pipeline effects
61
   calculate_sad_done_int : std_logic; -- pipeline for performance
62
 
63
end record;
64
 
65
signal r, r_in: state_register_type; -- state register
66
 
67
begin
68
 
69
    selection : process(best_sad,best_mv,rest_best_sad,rest_best_mv,update,calculate_sad_done,update_fp)
70
    variable vbest_sad_fp,vbest_mv_fp : std_logic_vector(15 downto 0);
71
    variable v : state_register_type; -- state register
72
    variable veu_id : std_logic_vector(3 downto 0); -- execution unit identifier 
73
 
74
        begin
75
 
76
      vbest_sad_fp := best_sad;
77
      vbest_mv_fp := best_mv;
78
        veu_id := r.eu_id(0);
79
           v := r;
80
 
81
    for i in 1 to (integer_pipeline_count-1) loop
82
         if (v.active_pipelines_r(5)(i) = '1') then
83
          if rest_best_sad(i) < vbest_sad_fp then
84
              vbest_sad_fp := rest_best_sad(i);
85
              vbest_mv_fp := rest_best_mv(i);
86
                  veu_id := r.eu_id(i);
87
          end if;
88
          end if;
89
      end loop;
90
 
91
   v.best_sad_candidate := vbest_sad_fp;
92
 
93
 
94
 
95
 
96
   v.active_pipelines_r(5) := v.active_pipelines_r(4);
97
   v.active_pipelines_r(4) := v.active_pipelines_r(3);
98
   v.active_pipelines_r(3) := v.active_pipelines_r(2);
99
   v.active_pipelines_r(2) := v.active_pipelines_r(1);
100
   v.active_pipelines_r(1) := v.active_pipelines_r(0);
101
   v.active_pipelines_r(0) := active_pipelines; -- pipeline effect
102
 
103
 
104
 
105
 
106
  if (r.best_sad_candidate < r.best_sad and v.calculate_sad_done_int = '1') then
107
                        v.best_sad := r.best_sad_candidate;
108
                        v.best_mv := vbest_mv_fp;
109
                        v.best_eu := veu_id;
110
                        best_sad_out <= r.best_sad_candidate;
111
                        best_mv_out <= vbest_mv_fp;
112
                        best_eu <= veu_id;
113
   else
114
                best_sad_out <= r.best_sad;
115
                        best_mv_out <= r.best_mv;
116
                        best_eu <= r.best_eu;
117
   end if;
118
 
119
 
120
   if (update = '1') then
121
      v.best_sad := x"FFFF"; --new program new max value
122
    elsif (update_fp = '1') then --iteraction completes
123
                for i in 0 to (CFG_PIPELINE_COUNT-1) loop
124
                        v.eu_id(i) := std_logic_vector(to_unsigned((i+1),4));
125
                end loop;
126
                v.best_eu := (others => '0');
127
   elsif (v.calculate_sad_done_int = '1') then
128
                   for i in 0 to (CFG_PIPELINE_COUNT-1) loop
129
                        v.eu_id(i) := v.eu_id(i)+CFG_PIPELINE_COUNT;
130
                        end loop;
131
 
132
    end if;
133
 
134
   v.calculate_sad_done_int := calculate_sad_done;
135
 
136
   r_in <= v;
137
 
138
  end process;
139
 
140
 
141
regs : process(clk,clear)
142
 
143
begin
144
 
145
 if (clear = '1') then
146
        r.best_sad <= x"FFFF"; -- start with the highest value
147
        r.best_sad_candidate <= (others => '0');
148
        r.best_mv <= (others => '0');
149
        r.best_eu <= (others => '0');
150
        for i in 0 to 5 loop
151
                r.active_pipelines_r(i) <= (others => '0');
152
        end loop;
153
        for i in 0 to (CFG_PIPELINE_COUNT-1) loop
154
                r.eu_id(i) <= std_logic_vector(to_unsigned((i+1),4));
155
        end loop;
156
      r.calculate_sad_done_int <= '0';
157
 elsif rising_edge(clk) then
158
                if (reset = '1') then -- general enable
159
                 r.best_sad <= x"FFFF"; -- start with the highest value
160
                   r.best_sad_candidate <= (others => '0');
161
                 r.best_mv <= (others => '0');
162
                   r.best_eu <= (others => '0');
163
                   for i in 0 to 5 loop
164
                        r.active_pipelines_r(i) <= (others => '0');
165
                   end loop;
166
                   for i in 0 to (CFG_PIPELINE_COUNT-1) loop
167
                        r.eu_id(i) <= std_logic_vector(to_unsigned((i+1),4));
168
                   end loop;
169
                   r.calculate_sad_done_int <= '0';
170
                else
171
                         r <= r_in;
172
                end if;
173
 end if;
174
 
175
 
176
end process regs;
177
 
178
end  behavioral;
179
 
180
 

powered by: WebSVN 2.1.0

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