2 * Copyright (c) 2004-2005 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #ident "$Id: concat.cc,v 1.5 2005/06/22 00:04:48 steve Exp $"
31 vvp_fun_concat::vvp_fun_concat(unsigned w0
, unsigned w1
,
32 unsigned w2
, unsigned w3
)
40 for (unsigned idx
= 0 ; idx
< val_
.size() ; idx
+= 1)
41 val_
.set_bit(idx
, BIT4_X
);
44 vvp_fun_concat::~vvp_fun_concat()
48 void vvp_fun_concat::recv_vec4(vvp_net_ptr_t port
, const vvp_vector4_t
&bit
)
50 unsigned pdx
= port
.port();
52 if (bit
.size() != wid_
[pdx
]) {
53 cerr
<< "internal error: port " << pdx
54 << " expects wid=" << wid_
[pdx
]
55 << ", got wid=" << bit
.size() << endl
;
60 for (unsigned idx
= 0 ; idx
< pdx
; idx
+= 1)
63 for (unsigned idx
= 0 ; idx
< wid_
[pdx
] ; idx
+= 1) {
64 val_
.set_bit(off
+idx
, bit
.value(idx
));
67 vvp_send_vec4(port
.ptr()->out
, val_
);
70 void compile_concat(char*label
, unsigned w0
, unsigned w1
,
71 unsigned w2
, unsigned w3
,
72 unsigned argc
, struct symb_s
*argv
)
74 vvp_fun_concat
*fun
= new vvp_fun_concat(w0
, w1
, w2
, w3
);
76 vvp_net_t
*net
= new vvp_net_t
;
79 define_functor_symbol(label
, net
);
82 inputs_connect(net
, argc
, argv
);
85 vvp_fun_repeat::vvp_fun_repeat(unsigned width
, unsigned repeat
)
86 : wid_(width
), rep_(repeat
)
90 vvp_fun_repeat::~vvp_fun_repeat()
94 void vvp_fun_repeat::recv_vec4(vvp_net_ptr_t port
, const vvp_vector4_t
&bit
)
96 assert(bit
.size() == wid_
/rep_
);
98 vvp_vector4_t
val (wid_
);
100 for (unsigned rdx
= 0 ; rdx
< rep_
; rdx
+= 1) {
101 unsigned off
= rdx
* bit
.size();
103 for (unsigned idx
= 0 ; idx
< bit
.size() ; idx
+= 1)
104 val
.set_bit(off
+idx
, bit
.value(idx
));
108 vvp_send_vec4(port
.ptr()->out
, val
);
111 void compile_repeat(char*label
, long width
, long repeat
, struct symb_s arg
)
113 vvp_fun_repeat
*fun
= new vvp_fun_repeat(width
, repeat
);
115 vvp_net_t
*net
= new vvp_net_t
;
118 define_functor_symbol(label
, net
);
121 input_connect(net
, 0, arg
.text
);
126 * $Log: concat.cc,v $
127 * Revision 1.5 2005/06/22 00:04:48 steve
128 * Reduce vvp_vector4 copies by using const references.
130 * Revision 1.4 2005/06/17 03:46:52 steve
131 * Make functors know their own width.
133 * Revision 1.3 2005/04/09 05:30:38 steve
134 * Default behavior for recv_vec8 methods.
136 * Revision 1.2 2005/02/07 22:42:42 steve
137 * Add .repeat functor and BIFIF functors.
139 * Revision 1.1 2005/01/22 00:01:09 steve
140 * Add missing concat.cc to cvs