1 #ifndef IVL_part_H
2 #define IVL_part_H
3 /*
4  * Copyright (c) 2005-2014 Stephen Williams (steve@icarus.com)
5  *
6  *    This source code is free software; you can redistribute it
7  *    and/or modify it in source code form under the terms of the GNU
8  *    General Public License as published by the Free Software
9  *    Foundation; either version 2 of the License, or (at your option)
10  *    any later version.
11  *
12  *    This program is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with this program; if not, write to the Free Software
19  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 # include  "schedule.h"
23 # include  "config.h"
24 
25 /* vvp_fun_part
26  * This node takes a part select of the input vector. Input 0 is the
27  * vector to be selected from, and input 1 is the location where the
28  * select starts. Input 2, which is typically constant, is the width
29  * of the result.
30  */
31 class vvp_fun_part  : public vvp_net_fun_t {
32 
33     public:
34       vvp_fun_part(unsigned base, unsigned wid);
35       ~vvp_fun_part();
36 
37     protected:
38       unsigned base_;
39       unsigned wid_;
40 };
41 
42 /*
43  * Statically allocated vvp_fun_part.
44  */
45 class vvp_fun_part_sa  : public vvp_fun_part, public vvp_gen_event_s {
46 
47     public:
48       vvp_fun_part_sa(unsigned base, unsigned wid);
49       ~vvp_fun_part_sa();
50 
51     public:
52       void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
53                      vvp_context_t);
54 
55       void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
56 			unsigned, unsigned, unsigned,
57                         vvp_context_t);
58 
59     private:
60       void run_run();
61 
62     private:
63       vvp_vector4_t val_;
64       vvp_net_t*net_;
65 };
66 
67 /*
68  * Automatically allocated vvp_fun_part.
69  */
70 class vvp_fun_part_aa  : public vvp_fun_part, public automatic_hooks_s {
71 
72     public:
73       vvp_fun_part_aa(unsigned base, unsigned wid);
74       ~vvp_fun_part_aa();
75 
76     public:
77       void alloc_instance(vvp_context_t context);
78       void reset_instance(vvp_context_t context);
79 #ifdef CHECK_WITH_VALGRIND
80       void free_instance(vvp_context_t context);
81 #endif
82 
83       void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
84                      vvp_context_t context);
85 
86       void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
87 			unsigned, unsigned, unsigned,
88                         vvp_context_t context);
89 
90     private:
91       __vpiScope*context_scope_;
92       unsigned context_idx_;
93 };
94 
95 /* vvp_fun_part_pv
96  * This node takes a vector input and turns it into the part select of
97  * a wider output network. It used the recv_vec4_pv methods of the
98  * destination nodes to propagate the part select. It can be used in
99  * both statically and automatically allocated scopes, as it has no
100  * dynamic state.
101  */
102 class vvp_fun_part_pv  : public vvp_net_fun_t {
103 
104     public:
105       vvp_fun_part_pv(unsigned base, unsigned wid, unsigned vec_wid);
106       ~vvp_fun_part_pv();
107 
108     public:
109       void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
110                      vvp_context_t context);
111 
112       void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
113                         unsigned, unsigned, unsigned,
114                         vvp_context_t);
115 
116       void recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit);
117 
118     private:
119       unsigned base_;
120       unsigned wid_;
121       unsigned vwid_;
122 };
123 
124 /*
125  * This part select is more flexible in that it takes the vector to
126  * part in port 0, and the base of the part in port 1. The width of
127  * the part to take out is fixed.
128  */
129 class vvp_fun_part_var  : public vvp_net_fun_t {
130 
131     public:
132       explicit vvp_fun_part_var(unsigned wid, bool is_signed);
133       ~vvp_fun_part_var();
134 
135     protected:
136       bool recv_vec4_(vvp_net_ptr_t port, const vvp_vector4_t&bit,
137                       int&base, vvp_vector4_t&source,
138                       vvp_vector4_t&ref);
139 
140       unsigned wid_;
141       bool is_signed_;
142 };
143 
144 /*
145  * Statically allocated vvp_fun_part_var.
146  */
147 class vvp_fun_part_var_sa  : public vvp_fun_part_var {
148 
149     public:
150       explicit vvp_fun_part_var_sa(unsigned wid, bool is_signed);
151       ~vvp_fun_part_var_sa();
152 
153     public:
154       void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
155                      vvp_context_t);
156 
157       void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
158 			unsigned, unsigned, unsigned,
159                         vvp_context_t);
160 
161     private:
162       int base_;
163       vvp_vector4_t source_;
164 	// Save the last output, for detecting change.
165       vvp_vector4_t ref_;
166 };
167 
168 /*
169  * Automatically allocated vvp_fun_part_var.
170  */
171 class vvp_fun_part_var_aa  : public vvp_fun_part_var, public automatic_hooks_s {
172 
173     public:
174       explicit vvp_fun_part_var_aa(unsigned wid, bool is_signed);
175       ~vvp_fun_part_var_aa();
176 
177     public:
178       void alloc_instance(vvp_context_t context);
179       void reset_instance(vvp_context_t context);
180 #ifdef CHECK_WITH_VALGRIND
181       void free_instance(vvp_context_t context);
182 #endif
183 
184       void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
185                      vvp_context_t context);
186 
187       void recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
188 			unsigned, unsigned, unsigned,
189                         vvp_context_t context);
190 
191     private:
192       __vpiScope*context_scope_;
193       unsigned context_idx_;
194 };
195 
196 #endif /* IVL_part_H */
197