2000-01-13 04:35:35 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2000-02-23 03:56:53 +01:00
|
|
|
#if !defined(WINNT) && !defined(macintosh)
|
2000-03-22 05:26:40 +01:00
|
|
|
#ident "$Id: vvm_mult.cc,v 1.5 2000/03/22 04:26:41 steve Exp $"
|
2000-01-13 04:35:35 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vvm_gates.h"
|
|
|
|
|
# include <assert.h>
|
|
|
|
|
|
|
|
|
|
void vvm_binop_mult(vpip_bit_t*r, unsigned nr,
|
|
|
|
|
const vpip_bit_t*a, unsigned na,
|
|
|
|
|
const vpip_bit_t*b, unsigned nb)
|
|
|
|
|
{
|
2000-03-04 02:13:54 +01:00
|
|
|
assert(nr <= 8*sizeof(unsigned long));
|
|
|
|
|
assert(na <= 8*sizeof(unsigned long));
|
|
|
|
|
assert(nb <= 8*sizeof(unsigned long));
|
|
|
|
|
|
|
|
|
|
unsigned long av = 0, bv = 0;
|
|
|
|
|
unsigned long rv;
|
|
|
|
|
|
2000-03-22 05:26:40 +01:00
|
|
|
for (unsigned idx = 0 ; idx < na ; idx += 1) {
|
2000-03-04 02:13:54 +01:00
|
|
|
|
2000-03-22 05:26:40 +01:00
|
|
|
if (B_ISXZ(a[idx]))
|
|
|
|
|
goto unknown_result;
|
|
|
|
|
|
|
|
|
|
if (B_IS1(a[idx]))
|
|
|
|
|
av |= 1 << idx;
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
2000-03-04 02:13:54 +01:00
|
|
|
|
2000-03-22 05:26:40 +01:00
|
|
|
for (unsigned idx = 0 ; idx < nb ; idx += 1) {
|
|
|
|
|
|
|
|
|
|
if (B_ISXZ(b[idx]))
|
|
|
|
|
goto unknown_result;
|
2000-03-04 02:13:54 +01:00
|
|
|
|
2000-03-22 05:26:40 +01:00
|
|
|
if (B_IS1(b[idx]))
|
|
|
|
|
bv |= 1 << idx;
|
2000-03-04 02:13:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rv = av * bv;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < nr ; idx += 1) {
|
|
|
|
|
|
|
|
|
|
if (rv & 1)
|
2000-03-22 05:26:40 +01:00
|
|
|
r[idx] = St1;
|
2000-03-04 02:13:54 +01:00
|
|
|
else
|
2000-03-22 05:26:40 +01:00
|
|
|
r[idx] = St0;
|
2000-03-04 02:13:54 +01:00
|
|
|
|
|
|
|
|
rv >>= 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
unknown_result:
|
|
|
|
|
for (unsigned idx= 0 ; idx < nr ; idx += 1)
|
2000-03-22 05:26:40 +01:00
|
|
|
r[idx] = StX;
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvm_mult::vvm_mult(unsigned rwid, unsigned awid,
|
|
|
|
|
unsigned bwid, unsigned swid)
|
|
|
|
|
: rwid_(rwid), awid_(awid), bwid_(bwid), swid_(swid)
|
|
|
|
|
{
|
|
|
|
|
bits_ = new vpip_bit_t[rwid_+awid_+bwid_+swid_];
|
2000-03-17 04:05:13 +01:00
|
|
|
out_ = new vvm_nexus::drive_t[rwid_];
|
2000-01-13 04:35:35 +01:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < rwid_+awid_+bwid_+swid_ ; idx += 1)
|
2000-03-22 05:26:40 +01:00
|
|
|
bits_[idx] = StX;
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvm_mult::~vvm_mult()
|
|
|
|
|
{
|
|
|
|
|
delete[]bits_;
|
|
|
|
|
delete[]out_;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-17 04:05:13 +01:00
|
|
|
vvm_nexus::drive_t* vvm_mult::config_rout(unsigned idx)
|
2000-01-13 04:35:35 +01:00
|
|
|
{
|
|
|
|
|
assert(idx < rwid_);
|
2000-03-17 04:05:13 +01:00
|
|
|
return out_+idx;
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
2000-03-17 04:05:13 +01:00
|
|
|
unsigned vvm_mult::key_DataA(unsigned idx) const
|
2000-01-13 04:35:35 +01:00
|
|
|
{
|
|
|
|
|
assert(idx < awid_);
|
2000-03-17 04:05:13 +01:00
|
|
|
return rwid_ + idx;
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
2000-03-17 04:05:13 +01:00
|
|
|
void vvm_mult::init_DataA(unsigned idx, vpip_bit_t val)
|
2000-01-13 04:35:35 +01:00
|
|
|
{
|
|
|
|
|
assert(idx < awid_);
|
|
|
|
|
bits_[rwid_+idx] = val;
|
|
|
|
|
}
|
|
|
|
|
|
2000-03-17 04:05:13 +01:00
|
|
|
unsigned vvm_mult::key_DataB(unsigned idx) const
|
2000-01-13 04:35:35 +01:00
|
|
|
{
|
|
|
|
|
assert(idx < bwid_);
|
2000-03-17 04:05:13 +01:00
|
|
|
return rwid_+awid_+idx;
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
2000-03-17 04:05:13 +01:00
|
|
|
void vvm_mult::init_DataB(unsigned idx, vpip_bit_t val)
|
2000-01-13 04:35:35 +01:00
|
|
|
{
|
|
|
|
|
assert(idx < bwid_);
|
|
|
|
|
bits_[rwid_+awid_+idx] = val;
|
2000-03-17 04:05:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_mult::take_value(unsigned key, vpip_bit_t val)
|
|
|
|
|
{
|
|
|
|
|
bits_[key] = val;
|
2000-01-13 04:35:35 +01:00
|
|
|
vvm_binop_mult(bits_, rwid_,
|
|
|
|
|
bits_+rwid_, awid_,
|
|
|
|
|
bits_+rwid_+awid_, bwid_);
|
|
|
|
|
for (unsigned idx = 0 ; idx < rwid_ ; idx += 1)
|
2000-03-17 04:05:13 +01:00
|
|
|
out_[idx].set_value(bits_[idx]);
|
2000-01-13 04:35:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: vvm_mult.cc,v $
|
2000-03-22 05:26:40 +01:00
|
|
|
* Revision 1.5 2000/03/22 04:26:41 steve
|
|
|
|
|
* Replace the vpip_bit_t with a typedef and
|
|
|
|
|
* define values for all the different bit
|
|
|
|
|
* values, including strengths.
|
|
|
|
|
*
|
2000-03-17 04:05:13 +01:00
|
|
|
* Revision 1.4 2000/03/17 03:05:13 steve
|
|
|
|
|
* Update vvm_mult to nexus style.
|
|
|
|
|
*
|
2000-03-04 02:13:54 +01:00
|
|
|
* Revision 1.3 2000/03/04 01:13:54 steve
|
|
|
|
|
* Simpler implementation of multiplication.
|
|
|
|
|
*
|
2000-02-23 03:56:53 +01:00
|
|
|
* Revision 1.2 2000/02/23 02:56:57 steve
|
|
|
|
|
* Macintosh compilers do not support ident.
|
|
|
|
|
*
|
2000-01-13 04:35:35 +01:00
|
|
|
* Revision 1.1 2000/01/13 03:35:36 steve
|
|
|
|
|
* Multiplication all the way to simulation.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|