2001-06-05 05:05:41 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2001 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
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT)
|
2002-05-07 06:15:43 +02:00
|
|
|
#ident "$Id: arith.cc,v 1.23 2002/05/07 04:15:43 steve Exp $"
|
2001-06-05 05:05:41 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "arith.h"
|
|
|
|
|
# include "schedule.h"
|
2001-07-13 02:38:57 +02:00
|
|
|
# include <limits.h>
|
2001-10-16 05:06:18 +02:00
|
|
|
# include <stdio.h>
|
2001-06-05 05:05:41 +02:00
|
|
|
# include <assert.h>
|
2001-11-04 06:03:21 +01:00
|
|
|
# include <stdlib.h>
|
|
|
|
|
#ifdef HAVE_MALLOC_H
|
2001-10-31 05:27:46 +01:00
|
|
|
# include <malloc.h>
|
2001-11-04 06:03:21 +01:00
|
|
|
#endif
|
2001-06-05 05:05:41 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_arith_::output_x_(vvp_ipoint_t base, bool push, unsigned val)
|
2001-06-05 05:05:41 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
|
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
|
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
obj->put_oval(val, push);
|
2001-10-31 05:27:46 +01:00
|
|
|
}
|
2001-06-05 05:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_arith_::output_val_(vvp_ipoint_t base, bool push, unsigned long sum)
|
2001-06-05 05:05:41 +02:00
|
|
|
{
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
2001-06-05 05:05:41 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
2001-10-31 05:27:46 +01:00
|
|
|
|
|
|
|
|
unsigned val = sum & 1;
|
|
|
|
|
sum >>= 1;
|
|
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
obj->put_oval(val, push);
|
2001-06-05 05:05:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
// Make sure the static sum_ scratch space is large enough for everybody
|
|
|
|
|
|
|
|
|
|
vvp_wide_arith_::vvp_wide_arith_(unsigned wid)
|
|
|
|
|
: vvp_arith_(wid)
|
2001-10-16 04:47:37 +02:00
|
|
|
{
|
2002-05-07 06:15:43 +02:00
|
|
|
pagecount_ = (wid + pagesize - 1)/pagesize;
|
|
|
|
|
sum_ = (unsigned long *)calloc(pagecount_, sizeof(unsigned long));
|
2001-10-31 05:27:46 +01:00
|
|
|
assert(sum_);
|
2001-10-16 04:47:37 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_wide_arith_::output_val_(vvp_ipoint_t base, bool push)
|
2001-10-16 04:47:37 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned page = 0;
|
|
|
|
|
unsigned pbit = 0;
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
|
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
|
|
|
|
functor_t obj = functor_index(ptr);
|
2001-10-16 04:47:37 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = (sum_[page] >> pbit) & 1;
|
2001-10-16 04:47:37 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
pbit += 1;
|
|
|
|
|
if (pbit == pagesize) {
|
|
|
|
|
pbit = 0;
|
|
|
|
|
page += 1;
|
2001-10-16 05:06:18 +02:00
|
|
|
}
|
|
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
obj->put_oval(val, push);
|
2001-10-31 05:27:46 +01:00
|
|
|
}
|
|
|
|
|
}
|
2001-10-16 04:47:37 +02:00
|
|
|
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
// Division
|
2001-10-16 04:47:37 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
inline void vvp_arith_div::wide(vvp_ipoint_t base, bool push)
|
|
|
|
|
{
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
2001-10-16 04:47:37 +02:00
|
|
|
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_arith_div::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
|
|
|
|
{
|
|
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
2001-10-16 04:47:37 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
if(wid_ > 8*sizeof(unsigned long)) {
|
|
|
|
|
wide(base, push);
|
|
|
|
|
return;
|
2001-10-16 04:47:37 +02:00
|
|
|
}
|
2001-06-17 01:45:05 +02:00
|
|
|
|
|
|
|
|
unsigned long a = 0, b = 0;
|
2001-10-31 05:27:46 +01:00
|
|
|
|
2001-06-17 01:45:05 +02:00
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
2001-06-17 01:45:05 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
2001-10-31 05:27:46 +01:00
|
|
|
|
|
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0xaa) {
|
|
|
|
|
output_x_(base, push);
|
2001-06-17 01:45:05 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2001-10-31 05:27:46 +01:00
|
|
|
|
|
|
|
|
if (val & 0x01)
|
2001-06-17 01:45:05 +02:00
|
|
|
a += 1 << idx;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x04)
|
2001-06-17 01:45:05 +02:00
|
|
|
b += 1 << idx;
|
2001-10-31 05:27:46 +01:00
|
|
|
}
|
2001-06-17 01:45:05 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
if (b == 0) {
|
|
|
|
|
output_x_(base, push);
|
|
|
|
|
return;
|
2001-06-17 01:45:05 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
output_val_(base, push, a/b);
|
|
|
|
|
}
|
|
|
|
|
|
2002-01-03 05:19:01 +01:00
|
|
|
inline void vvp_arith_mod::wide(vvp_ipoint_t base, bool push)
|
|
|
|
|
{
|
|
|
|
|
assert(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvp_arith_mod::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
|
|
|
|
{
|
|
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
|
|
|
|
|
|
|
|
|
if(wid_ > 8*sizeof(unsigned long)) {
|
|
|
|
|
wide(base, push);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long a = 0, b = 0;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
|
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
|
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
|
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0xaa) {
|
|
|
|
|
output_x_(base, push);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (val & 0x01)
|
|
|
|
|
a += 1 << idx;
|
|
|
|
|
if (val & 0x04)
|
|
|
|
|
b += 1 << idx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (b == 0) {
|
|
|
|
|
output_x_(base, push);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output_val_(base, push, a%b);
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
// Multiplication
|
|
|
|
|
|
|
|
|
|
void vvp_arith_mult::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
|
|
|
|
{
|
|
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
|
|
|
|
|
|
|
|
|
if(wid_ > 8*sizeof(unsigned long)) {
|
|
|
|
|
wide(base, push);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned long a = 0, b = 0;
|
2001-06-17 01:45:05 +02:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
2001-06-17 01:45:05 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0xaa) {
|
|
|
|
|
output_x_(base, push);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-06-17 01:45:05 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x01)
|
|
|
|
|
a += 1 << idx;
|
|
|
|
|
if (val & 0x04)
|
|
|
|
|
b += 1 << idx;
|
|
|
|
|
}
|
2001-06-17 01:45:05 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
output_val_(base, push, a*b);
|
|
|
|
|
}
|
2001-06-17 01:45:05 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_arith_mult::wide(vvp_ipoint_t base, bool push)
|
|
|
|
|
{
|
2001-10-14 18:36:43 +02:00
|
|
|
unsigned char *a, *b, *sum;
|
|
|
|
|
a = new unsigned char[wid_];
|
|
|
|
|
b = new unsigned char[wid_];
|
|
|
|
|
sum = new unsigned char[wid_];
|
|
|
|
|
|
|
|
|
|
int mxa = -1;
|
|
|
|
|
int mxb = -1;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base, idx);
|
2001-10-14 18:36:43 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
|
|
|
|
unsigned ival = obj->ival;
|
|
|
|
|
if (ival & 0xaa) {
|
2001-10-31 05:27:46 +01:00
|
|
|
output_x_(base, push);
|
2001-10-14 18:36:43 +02:00
|
|
|
delete[]sum;
|
|
|
|
|
delete[]b;
|
|
|
|
|
delete[]a;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-14 19:36:18 +02:00
|
|
|
if((a[idx] = ((ival & 0x01) != 0))) mxa=idx+1;
|
2001-10-14 18:36:43 +02:00
|
|
|
if((b[idx] = ((ival & 0x04) != 0))) mxb=idx;
|
|
|
|
|
sum[idx] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// do "unsigned ZZ sum = a * b" the hard way..
|
|
|
|
|
for(int i=0;i<=mxb;i++)
|
|
|
|
|
{
|
|
|
|
|
if(b[i])
|
|
|
|
|
{
|
|
|
|
|
unsigned char carry=0;
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
|
|
|
|
for(int j=0;j<=mxa;j++)
|
|
|
|
|
{
|
|
|
|
|
if(i+j>=(int)wid_) break;
|
|
|
|
|
temp=sum[i+j]+a[j]+carry;
|
|
|
|
|
sum[i+j]=(temp&1);
|
|
|
|
|
carry=(temp>>1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx);
|
2001-10-14 18:36:43 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = sum[idx];
|
2001-10-14 18:36:43 +02:00
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
obj->put_oval(val, push);
|
2001-10-14 18:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
delete[]sum;
|
|
|
|
|
delete[]b;
|
|
|
|
|
delete[]a;
|
2001-10-14 18:36:43 +02:00
|
|
|
}
|
|
|
|
|
|
2001-06-17 01:45:05 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
// Addition
|
2001-06-29 03:20:20 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_arith_sum::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
2001-06-29 03:20:20 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
2001-06-07 05:09:03 +02:00
|
|
|
|
2001-06-29 03:20:20 +02:00
|
|
|
unsigned page = 0;
|
|
|
|
|
unsigned pbit = 0;
|
2001-06-29 03:20:20 +02:00
|
|
|
unsigned long carry = 0;
|
2001-06-29 03:20:20 +02:00
|
|
|
|
|
|
|
|
sum_[0] = 0;
|
2001-06-05 05:05:41 +02:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base, idx);
|
2001-06-05 05:05:41 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0xaa) {
|
|
|
|
|
output_x_(base, push);
|
2001-06-05 05:05:41 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-29 03:20:20 +02:00
|
|
|
// Accumulate the sum of the input bits.
|
2001-06-29 03:20:20 +02:00
|
|
|
unsigned long tmp = 0;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x01)
|
2001-06-05 05:05:41 +02:00
|
|
|
tmp += 1;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x04)
|
2001-06-05 05:05:41 +02:00
|
|
|
tmp += 1;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x10)
|
2001-06-05 05:05:41 +02:00
|
|
|
tmp += 1;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x40)
|
2001-06-05 05:05:41 +02:00
|
|
|
tmp += 1;
|
|
|
|
|
|
2001-10-27 05:22:26 +02:00
|
|
|
// Save carry bits
|
|
|
|
|
if (pbit >= pagesize - 2)
|
|
|
|
|
carry += (tmp + (sum_[page]>>pbit)) >> (pagesize-pbit);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
// Put the next bits into the sum,
|
2001-10-27 05:22:26 +02:00
|
|
|
sum_[page] += tmp << pbit;
|
2001-06-29 03:20:20 +02:00
|
|
|
|
|
|
|
|
pbit += 1;
|
2001-10-27 05:22:26 +02:00
|
|
|
if (pbit >= pagesize) {
|
2001-06-29 03:20:20 +02:00
|
|
|
pbit = 0;
|
|
|
|
|
page += 1;
|
2002-05-07 06:15:43 +02:00
|
|
|
if (page < pagecount_)
|
|
|
|
|
sum_[page] = carry;
|
2001-10-27 05:22:26 +02:00
|
|
|
carry = 0;
|
2001-06-29 03:20:20 +02:00
|
|
|
}
|
2001-06-05 05:05:41 +02:00
|
|
|
}
|
2001-06-29 03:20:20 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
output_val_(base, push);
|
2001-06-05 05:05:41 +02:00
|
|
|
}
|
|
|
|
|
|
2001-06-07 05:09:03 +02:00
|
|
|
|
2001-07-13 02:38:57 +02:00
|
|
|
/*
|
|
|
|
|
* Subtraction works by adding the 2s complement of the B, C and D
|
|
|
|
|
* inputs from the A input. The 2s complement is the 1s complement
|
|
|
|
|
* plus one, so we further reduce the operation to adding in the
|
|
|
|
|
* inverted value and adding a correction.
|
|
|
|
|
*/
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_arith_sub::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
2001-06-07 05:09:03 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
|
|
|
|
|
2001-07-13 02:38:57 +02:00
|
|
|
unsigned page = 0;
|
|
|
|
|
unsigned pbit = 0;
|
2001-10-27 05:22:26 +02:00
|
|
|
unsigned long carry = 0;
|
2001-07-13 02:38:57 +02:00
|
|
|
|
|
|
|
|
/* There are 3 values subtracted from the first parameter, so
|
|
|
|
|
there are three 2s complements, so three ~X +1. That's why
|
2001-10-27 05:22:26 +02:00
|
|
|
the sum_ starts with 3. */
|
|
|
|
|
sum_[0] = 3;
|
2001-06-07 05:09:03 +02:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base, idx);
|
2001-06-07 05:09:03 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0xaa) {
|
|
|
|
|
output_x_(base, push);
|
2001-06-07 05:09:03 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-07-13 02:38:57 +02:00
|
|
|
// Accumulate the sum of the input bits. Add in the
|
|
|
|
|
// first value, and the ones complement of the other values.
|
|
|
|
|
unsigned long tmp = 0;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (val & 0x01)
|
2001-06-07 05:09:03 +02:00
|
|
|
tmp += 1;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (! (val & 0x04))
|
2001-07-13 02:38:57 +02:00
|
|
|
tmp += 1;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (! (val & 0x10))
|
2001-07-13 02:38:57 +02:00
|
|
|
tmp += 1;
|
2001-10-31 05:27:46 +01:00
|
|
|
if (! (val & 0x40))
|
2001-07-13 02:38:57 +02:00
|
|
|
tmp += 1;
|
2001-06-07 05:09:03 +02:00
|
|
|
|
2001-10-27 05:22:26 +02:00
|
|
|
// Save carry bits
|
|
|
|
|
if (pbit >= pagesize - 2)
|
|
|
|
|
carry += (tmp + (sum_[page]>>pbit)) >> (pagesize-pbit);
|
|
|
|
|
|
|
|
|
|
// Put the next bits into the sum,
|
|
|
|
|
sum_[page] += tmp << pbit;
|
2001-07-13 02:38:57 +02:00
|
|
|
|
|
|
|
|
pbit += 1;
|
2001-10-27 05:22:26 +02:00
|
|
|
if (pbit >= pagesize) {
|
2001-07-13 02:38:57 +02:00
|
|
|
pbit = 0;
|
|
|
|
|
page += 1;
|
2002-05-07 06:15:43 +02:00
|
|
|
if (page < pagecount_)
|
|
|
|
|
sum_[page] = carry;
|
2001-10-27 05:22:26 +02:00
|
|
|
carry = 0;
|
2001-07-13 02:38:57 +02:00
|
|
|
}
|
2001-06-07 05:09:03 +02:00
|
|
|
}
|
2001-07-13 02:38:57 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
output_val_(base, push);
|
2001-06-07 05:09:03 +02:00
|
|
|
}
|
|
|
|
|
|
2001-06-15 06:07:57 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_cmp_ge::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
2001-06-15 06:07:57 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
|
|
|
|
|
2001-06-16 05:36:03 +02:00
|
|
|
unsigned out_val = 1;
|
2001-06-15 06:07:57 +02:00
|
|
|
|
2001-06-16 05:36:03 +02:00
|
|
|
for (unsigned idx = wid_ ; idx > 0 ; idx -= 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base,idx-1);
|
2001-06-15 06:07:57 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0x0a) {
|
2001-06-15 06:07:57 +02:00
|
|
|
out_val = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned a = (val & 0x01)? 1 : 0;
|
|
|
|
|
unsigned b = (val & 0x04)? 1 : 0;
|
2001-06-16 05:36:03 +02:00
|
|
|
|
|
|
|
|
if (a > b) {
|
|
|
|
|
out_val = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2001-06-15 06:07:57 +02:00
|
|
|
|
2001-06-16 05:36:03 +02:00
|
|
|
if (a < b) {
|
|
|
|
|
out_val = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-15 06:07:57 +02:00
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
put_oval(out_val, push);
|
2001-06-15 06:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_cmp_gt::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
2001-06-15 06:07:57 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
2001-06-15 06:07:57 +02:00
|
|
|
|
|
|
|
|
unsigned out_val = 0;
|
2001-10-31 05:27:46 +01:00
|
|
|
|
2001-06-16 05:36:03 +02:00
|
|
|
for (unsigned idx = wid_ ; idx > 0 ; idx -= 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base, idx-1);
|
2001-06-15 06:07:57 +02:00
|
|
|
functor_t obj = functor_index(ptr);
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned val = obj->ival;
|
|
|
|
|
if (val & 0x0a) {
|
2001-06-15 06:07:57 +02:00
|
|
|
out_val = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned a = (val & 0x01)? 1 : 0;
|
|
|
|
|
unsigned b = (val & 0x04)? 1 : 0;
|
2001-06-15 06:07:57 +02:00
|
|
|
|
2001-06-16 05:36:03 +02:00
|
|
|
if (a > b) {
|
|
|
|
|
out_val = 1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a < b) {
|
|
|
|
|
out_val = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-15 06:07:57 +02:00
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
put_oval(out_val, push);
|
2001-06-15 06:07:57 +02:00
|
|
|
}
|
|
|
|
|
|
2001-07-06 06:46:44 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_shiftl::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
2001-07-06 06:46:44 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
|
|
|
|
|
|
|
|
|
unsigned amount = 0;
|
|
|
|
|
|
2001-07-06 06:46:44 +02:00
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base, idx);
|
2001-07-06 06:46:44 +02:00
|
|
|
functor_t fp = functor_index(ptr);
|
|
|
|
|
|
|
|
|
|
unsigned val = (fp->ival >> 2) & 0x03;
|
|
|
|
|
switch (val) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2001-10-31 05:27:46 +01:00
|
|
|
amount |= 1 << idx;
|
2001-07-06 06:46:44 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2001-10-31 05:27:46 +01:00
|
|
|
output_x_(base, push);
|
2001-07-06 06:46:44 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
if (amount >= wid_) {
|
|
|
|
|
output_x_(base, push, 0);
|
|
|
|
|
return;
|
2001-07-06 06:46:44 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
vvp_ipoint_t optr, iptr;
|
|
|
|
|
functor_t ofp, ifp;
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
for (unsigned idx = 0 ; idx < amount ; idx += 1) {
|
|
|
|
|
optr = ipoint_index(base, idx);
|
2001-07-06 06:46:44 +02:00
|
|
|
ofp = functor_index(optr);
|
2001-12-06 04:31:24 +01:00
|
|
|
ofp->put_oval(0, push);
|
2001-07-06 06:46:44 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
for (unsigned idx = amount ; idx < wid_ ; idx += 1) {
|
|
|
|
|
optr = ipoint_index(base, idx);
|
2001-07-06 06:46:44 +02:00
|
|
|
ofp = functor_index(optr);
|
2001-10-31 05:27:46 +01:00
|
|
|
iptr = ipoint_index(base, idx - amount);
|
2001-07-06 06:46:44 +02:00
|
|
|
ifp = functor_index(iptr);
|
|
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
ofp->put_oval(ifp->ival & 3, push);
|
2001-07-06 06:46:44 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
void vvp_shiftr::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
|
2001-07-07 04:57:33 +02:00
|
|
|
{
|
2001-10-31 05:27:46 +01:00
|
|
|
put(i, val);
|
|
|
|
|
vvp_ipoint_t base = ipoint_make(i,0);
|
2001-07-07 04:57:33 +02:00
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
unsigned amount = 0;
|
2001-07-07 04:57:33 +02:00
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
|
2001-10-31 05:27:46 +01:00
|
|
|
vvp_ipoint_t ptr = ipoint_index(base, idx);
|
2001-07-07 04:57:33 +02:00
|
|
|
functor_t fp = functor_index(ptr);
|
|
|
|
|
|
|
|
|
|
unsigned val = (fp->ival >> 2) & 0x03;
|
|
|
|
|
switch (val) {
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
2001-10-31 05:27:46 +01:00
|
|
|
amount |= 1 << idx;
|
2001-07-07 04:57:33 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
2001-10-31 05:27:46 +01:00
|
|
|
output_x_(base, push);
|
2001-07-07 04:57:33 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
if (amount >= wid_) {
|
|
|
|
|
output_x_(base, push, 0);
|
|
|
|
|
return;
|
2001-07-07 04:57:33 +02:00
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
vvp_ipoint_t optr, iptr;
|
|
|
|
|
functor_t ofp, ifp;
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
for (unsigned idx = 0 ; idx < (wid_-amount) ; idx += 1) {
|
|
|
|
|
optr = ipoint_index(base, idx);
|
2001-07-07 04:57:33 +02:00
|
|
|
ofp = functor_index(optr);
|
2001-10-31 05:27:46 +01:00
|
|
|
iptr = ipoint_index(base, idx + amount);
|
2001-07-07 04:57:33 +02:00
|
|
|
ifp = functor_index(iptr);
|
|
|
|
|
|
2001-12-06 04:31:24 +01:00
|
|
|
ofp->put_oval(ifp->ival & 3, push);
|
2001-07-07 04:57:33 +02:00
|
|
|
}
|
|
|
|
|
|
2001-10-31 05:27:46 +01:00
|
|
|
for (unsigned idx = wid_-amount; idx < wid_ ; idx += 1) {
|
|
|
|
|
optr = ipoint_index(base, idx);
|
2001-07-07 04:57:33 +02:00
|
|
|
ofp = functor_index(optr);
|
2001-12-06 04:31:24 +01:00
|
|
|
ofp->put_oval(0, push);
|
2001-07-07 04:57:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-05 05:05:41 +02:00
|
|
|
/*
|
|
|
|
|
* $Log: arith.cc,v $
|
2002-05-07 06:15:43 +02:00
|
|
|
* Revision 1.23 2002/05/07 04:15:43 steve
|
|
|
|
|
* Fix uninitialized memory accesses.
|
|
|
|
|
*
|
2002-01-03 05:19:01 +01:00
|
|
|
* Revision 1.22 2002/01/03 04:19:02 steve
|
|
|
|
|
* Add structural modulus support down to vvp.
|
|
|
|
|
*
|
2001-12-06 04:31:24 +01:00
|
|
|
* Revision 1.21 2001/12/06 03:31:24 steve
|
|
|
|
|
* Support functor delays for gates and UDP devices.
|
|
|
|
|
* (Stephan Boettcher)
|
|
|
|
|
*
|
2001-11-07 04:34:41 +01:00
|
|
|
* Revision 1.20 2001/11/07 03:34:41 steve
|
|
|
|
|
* Use functor pointers where vvp_ipoint_t is unneeded.
|
|
|
|
|
*
|
2001-11-04 06:03:21 +01:00
|
|
|
* Revision 1.19 2001/11/04 05:03:21 steve
|
|
|
|
|
* MacOSX 10.1 updates.
|
|
|
|
|
*
|
2001-10-31 05:27:46 +01:00
|
|
|
* Revision 1.18 2001/10/31 04:27:46 steve
|
|
|
|
|
* Rewrite the functor type to have fewer functor modes,
|
|
|
|
|
* and use objects to manage the different types.
|
|
|
|
|
* (Stephan Boettcher)
|
|
|
|
|
*
|
2001-10-27 05:22:26 +02:00
|
|
|
* Revision 1.17 2001/10/27 03:22:26 steve
|
|
|
|
|
* Minor rework of summation carry propagation (Stephan Boettcher)
|
|
|
|
|
*
|
2001-10-16 05:10:20 +02:00
|
|
|
* Revision 1.16 2001/10/16 03:10:20 steve
|
|
|
|
|
* Get Division error into the division method!
|
|
|
|
|
*
|
2001-10-16 05:06:18 +02:00
|
|
|
* Revision 1.15 2001/10/16 03:06:18 steve
|
|
|
|
|
* Catch division by zero in .arith/div.
|
|
|
|
|
*
|
2001-10-16 04:47:37 +02:00
|
|
|
* Revision 1.14 2001/10/16 02:47:37 steve
|
|
|
|
|
* Add arith/div object.
|
|
|
|
|
*
|
2001-10-14 19:36:18 +02:00
|
|
|
* Revision 1.13 2001/10/14 17:36:18 steve
|
|
|
|
|
* Forgot to propagate carry.
|
|
|
|
|
*
|
2001-10-14 18:36:43 +02:00
|
|
|
* Revision 1.12 2001/10/14 16:36:43 steve
|
|
|
|
|
* Very wide multiplication (Anthony Bybell)
|
|
|
|
|
*
|
2001-07-13 02:38:57 +02:00
|
|
|
* Revision 1.11 2001/07/13 00:38:57 steve
|
|
|
|
|
* Remove width restriction on subtraction.
|
|
|
|
|
*
|
2001-07-11 04:27:21 +02:00
|
|
|
* Revision 1.10 2001/07/11 02:27:21 steve
|
|
|
|
|
* Add support for REadOnlySync and monitors.
|
|
|
|
|
*
|
2001-07-07 04:57:33 +02:00
|
|
|
* Revision 1.9 2001/07/07 02:57:33 steve
|
|
|
|
|
* Add the .shift/r functor.
|
|
|
|
|
*
|
2001-07-06 06:46:44 +02:00
|
|
|
* Revision 1.8 2001/07/06 04:46:44 steve
|
|
|
|
|
* Add structural left shift (.shift/l)
|
|
|
|
|
*
|
2001-06-29 03:20:20 +02:00
|
|
|
* Revision 1.7 2001/06/29 01:21:48 steve
|
|
|
|
|
* Relax limit on width of structural sum.
|
|
|
|
|
*
|
2001-06-29 03:20:20 +02:00
|
|
|
* Revision 1.6 2001/06/29 01:20:20 steve
|
|
|
|
|
* Relax limit on width of structural sum.
|
|
|
|
|
*
|
2001-06-17 01:45:05 +02:00
|
|
|
* Revision 1.5 2001/06/16 23:45:05 steve
|
|
|
|
|
* Add support for structural multiply in t-dll.
|
|
|
|
|
* Add code generators and vvp support for both
|
|
|
|
|
* structural and behavioral multiply.
|
2001-06-05 05:05:41 +02:00
|
|
|
*/
|
|
|
|
|
|