2005-01-22 01:01:09 +01:00
|
|
|
/*
|
2021-11-04 18:02:07 +01:00
|
|
|
* Copyright (c) 2004-2021 Stephen Williams (steve@icarus.com)
|
2005-01-22 01:01:09 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2005-01-22 01:01:09 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
# include "compile.h"
|
|
|
|
|
# include "vvp_net.h"
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cstdlib>
|
2005-06-17 05:46:52 +02:00
|
|
|
# include <iostream>
|
2010-05-31 22:12:06 +02:00
|
|
|
# include <cassert>
|
2005-01-22 01:01:09 +01:00
|
|
|
|
2021-11-04 18:02:07 +01:00
|
|
|
using namespace std;
|
2005-01-22 01:01:09 +01:00
|
|
|
|
|
|
|
|
vvp_fun_concat::vvp_fun_concat(unsigned w0, unsigned w1,
|
|
|
|
|
unsigned w2, unsigned w3)
|
|
|
|
|
: val_(w0+w1+w2+w3)
|
|
|
|
|
{
|
|
|
|
|
wid_[0] = w0;
|
|
|
|
|
wid_[1] = w1;
|
|
|
|
|
wid_[2] = w2;
|
|
|
|
|
wid_[3] = w3;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < val_.size() ; idx += 1)
|
2010-03-20 17:53:56 +01:00
|
|
|
val_.set_bit(idx, BIT4_Z);
|
2005-01-22 01:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_concat::~vvp_fun_concat()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_concat::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-01-22 01:01:09 +01:00
|
|
|
{
|
|
|
|
|
unsigned pdx = port.port();
|
|
|
|
|
|
2005-06-17 05:46:52 +02:00
|
|
|
if (bit.size() != wid_[pdx]) {
|
|
|
|
|
cerr << "internal error: port " << pdx
|
|
|
|
|
<< " expects wid=" << wid_[pdx]
|
|
|
|
|
<< ", got wid=" << bit.size() << endl;
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2005-01-22 01:01:09 +01:00
|
|
|
|
|
|
|
|
unsigned off = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < pdx ; idx += 1)
|
|
|
|
|
off += wid_[idx];
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_[pdx] ; idx += 1) {
|
|
|
|
|
val_.set_bit(off+idx, bit.value(idx));
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-04 05:40:26 +02:00
|
|
|
port.ptr()->send_vec4(val_, 0);
|
2005-01-22 01:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-20 17:53:56 +01:00
|
|
|
void vvp_fun_concat::recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid, vvp_context_t)
|
2010-03-20 17:53:56 +01:00
|
|
|
{
|
|
|
|
|
unsigned pdx = port.port();
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned wid = bit.size();
|
2010-03-20 17:53:56 +01:00
|
|
|
|
|
|
|
|
if (vwid != wid_[pdx]) {
|
|
|
|
|
cerr << "internal error: port " << pdx
|
|
|
|
|
<< " expects wid=" << wid_[pdx]
|
|
|
|
|
<< ", got wid=" << vwid << endl;
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned off = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < pdx ; idx += 1)
|
|
|
|
|
off += wid_[idx];
|
|
|
|
|
|
|
|
|
|
unsigned limit = off + wid_[pdx];
|
|
|
|
|
|
|
|
|
|
off += base;
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
|
|
|
|
if (off+idx >= limit) break;
|
|
|
|
|
val_.set_bit(off+idx, bit.value(idx));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port.ptr()->send_vec4(val_, 0);
|
|
|
|
|
}
|
|
|
|
|
|
2005-01-22 01:01:09 +01:00
|
|
|
void compile_concat(char*label, unsigned w0, unsigned w1,
|
|
|
|
|
unsigned w2, unsigned w3,
|
|
|
|
|
unsigned argc, struct symb_s*argv)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_concat*fun = new vvp_fun_concat(w0, w1, w2, w3);
|
|
|
|
|
|
|
|
|
|
vvp_net_t*net = new vvp_net_t;
|
|
|
|
|
net->fun = fun;
|
2013-02-02 19:44:16 +01:00
|
|
|
|
|
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
inputs_connect(net, argc, argv);
|
|
|
|
|
free(argv);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vvp_fun_concat8::vvp_fun_concat8(unsigned w0, unsigned w1,
|
|
|
|
|
unsigned w2, unsigned w3)
|
|
|
|
|
: val_(w0+w1+w2+w3)
|
|
|
|
|
{
|
|
|
|
|
wid_[0] = w0;
|
|
|
|
|
wid_[1] = w1;
|
|
|
|
|
wid_[2] = w2;
|
|
|
|
|
wid_[3] = w3;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < val_.size() ; idx += 1)
|
|
|
|
|
val_.set_bit(idx, vvp_scalar_t(BIT4_Z, 0, 0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_concat8::~vvp_fun_concat8()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_concat8::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
|
|
|
|
{
|
|
|
|
|
vvp_vector8_t bit8 (bit, 6, 6);
|
|
|
|
|
recv_vec8(port, bit8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_concat8::recv_vec4_pv(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid, vvp_context_t)
|
2013-02-02 19:44:16 +01:00
|
|
|
{
|
|
|
|
|
vvp_vector8_t bit8 (bit, 6, 6);
|
2022-05-28 13:04:53 +02:00
|
|
|
recv_vec8_pv(port, bit8, base, vwid);
|
2013-02-02 19:44:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_concat8::recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit)
|
|
|
|
|
{
|
|
|
|
|
unsigned pdx = port.port();
|
|
|
|
|
|
|
|
|
|
if (bit.size() != wid_[pdx]) {
|
|
|
|
|
cerr << "internal error: port " << pdx
|
|
|
|
|
<< " expects wid=" << wid_[pdx]
|
|
|
|
|
<< ", got wid=" << bit.size() << endl;
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned off = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < pdx ; idx += 1)
|
|
|
|
|
off += wid_[idx];
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_[pdx] ; idx += 1) {
|
|
|
|
|
val_.set_bit(off+idx, bit.value(idx));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port.ptr()->send_vec8(val_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_fun_concat8::recv_vec8_pv(vvp_net_ptr_t port, const vvp_vector8_t&bit,
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned base, unsigned vwid)
|
2013-02-02 19:44:16 +01:00
|
|
|
{
|
|
|
|
|
unsigned pdx = port.port();
|
2022-05-28 13:04:53 +02:00
|
|
|
unsigned wid = bit.size();
|
2013-02-02 19:44:16 +01:00
|
|
|
|
|
|
|
|
if (vwid != wid_[pdx]) {
|
|
|
|
|
cerr << "internal error: port " << pdx
|
|
|
|
|
<< " expects wid=" << wid_[pdx]
|
|
|
|
|
<< ", got wid=" << vwid << endl;
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned off = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < pdx ; idx += 1)
|
|
|
|
|
off += wid_[idx];
|
|
|
|
|
|
|
|
|
|
unsigned limit = off + wid_[pdx];
|
|
|
|
|
|
|
|
|
|
off += base;
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid ; idx += 1) {
|
|
|
|
|
if (off+idx >= limit) break;
|
|
|
|
|
val_.set_bit(off+idx, bit.value(idx));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
port.ptr()->send_vec8(val_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_concat8(char*label, unsigned w0, unsigned w1,
|
|
|
|
|
unsigned w2, unsigned w3,
|
|
|
|
|
unsigned argc, struct symb_s*argv)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_concat8*fun = new vvp_fun_concat8(w0, w1, w2, w3);
|
|
|
|
|
|
|
|
|
|
vvp_net_t*net = new vvp_net_t;
|
|
|
|
|
net->fun = fun;
|
2005-01-22 01:01:09 +01:00
|
|
|
|
|
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
inputs_connect(net, argc, argv);
|
2009-01-13 18:57:12 +01:00
|
|
|
free(argv);
|
2005-01-22 01:01:09 +01:00
|
|
|
}
|
|
|
|
|
|
2005-02-07 23:42:42 +01:00
|
|
|
vvp_fun_repeat::vvp_fun_repeat(unsigned width, unsigned repeat)
|
|
|
|
|
: wid_(width), rep_(repeat)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvp_fun_repeat::~vvp_fun_repeat()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void vvp_fun_repeat::recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t)
|
2005-02-07 23:42:42 +01:00
|
|
|
{
|
|
|
|
|
assert(bit.size() == wid_/rep_);
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t val (wid_);
|
|
|
|
|
|
|
|
|
|
for (unsigned rdx = 0 ; rdx < rep_ ; rdx += 1) {
|
|
|
|
|
unsigned off = rdx * bit.size();
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < bit.size() ; idx += 1)
|
|
|
|
|
val.set_bit(off+idx, bit.value(idx));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-04 05:40:26 +02:00
|
|
|
port.ptr()->send_vec4(val, 0);
|
2005-02-07 23:42:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void compile_repeat(char*label, long width, long repeat, struct symb_s arg)
|
|
|
|
|
{
|
|
|
|
|
vvp_fun_repeat*fun = new vvp_fun_repeat(width, repeat);
|
|
|
|
|
|
|
|
|
|
vvp_net_t*net = new vvp_net_t;
|
|
|
|
|
net->fun = fun;
|
|
|
|
|
|
|
|
|
|
define_functor_symbol(label, net);
|
|
|
|
|
free(label);
|
|
|
|
|
|
|
|
|
|
input_connect(net, 0, arg.text);
|
|
|
|
|
}
|