Add the integer modulus function.
This commit is contained in:
parent
2f419f0e08
commit
28df01b880
|
|
@ -18,7 +18,7 @@
|
|||
# 59 Temple Place - Suite 330
|
||||
# Boston, MA 02111-1307, USA
|
||||
#
|
||||
#ident "$Id: Makefile.in,v 1.30 2000/05/07 18:20:08 steve Exp $"
|
||||
#ident "$Id: Makefile.in,v 1.31 2000/05/19 04:22:55 steve Exp $"
|
||||
#
|
||||
#
|
||||
SHELL = /bin/sh
|
||||
|
|
@ -60,7 +60,7 @@ all: libvvm.a
|
|||
|
||||
O = vvm_add_sub.o vvm_bit.o vvm_calltf.o vvm_clshift.o vvm_compare.o \
|
||||
vvm_event.o vvm_ff.o vvm_force.o \
|
||||
vvm_func.o vvm_gates.o vvm_idiv.o vvm_mult.o vvm_mux.o \
|
||||
vvm_func.o vvm_gates.o vvm_idiv.o vvm_imod.o vvm_mult.o vvm_mux.o \
|
||||
vvm_nexus.o vvm_pevent.o vvm_signal.o vvm_thread.o vvm_udp.o vpip.o
|
||||
|
||||
P = vpi_bit.o vpi_callback.o \
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
*/
|
||||
#if !defined(WINNT) && !defined(macintosh)
|
||||
#ident "$Id: vvm_func.h,v 1.28 2000/04/01 21:40:23 steve Exp $"
|
||||
#ident "$Id: vvm_func.h,v 1.29 2000/05/19 04:22:56 steve Exp $"
|
||||
#endif
|
||||
|
||||
# include "vvm.h"
|
||||
|
|
@ -87,11 +87,14 @@ extern void vvm_binop_plus(vvm_bitset_t&v,
|
|||
const vvm_bitset_t&r);
|
||||
|
||||
/*
|
||||
* Integer division.
|
||||
* Integer division and modulus
|
||||
*/
|
||||
extern void vvm_binop_idiv(vvm_bitset_t&v,
|
||||
const vvm_bitset_t&l,
|
||||
const vvm_bitset_t&r);
|
||||
extern void vvm_binop_imod(vvm_bitset_t&v,
|
||||
const vvm_bitset_t&l,
|
||||
const vvm_bitset_t&r);
|
||||
|
||||
/*
|
||||
* The binary - operator is turned into + by doing 2's complement
|
||||
|
|
@ -203,6 +206,9 @@ extern void vvm_ternary(vvm_bitset_t&v, vpip_bit_t c,
|
|||
|
||||
/*
|
||||
* $Log: vvm_func.h,v $
|
||||
* Revision 1.29 2000/05/19 04:22:56 steve
|
||||
* Add the integer modulus function.
|
||||
*
|
||||
* Revision 1.28 2000/04/01 21:40:23 steve
|
||||
* Add support for integer division.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Copyright (c) 2000 Stephen Williams (steve@picturel.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) && !defined(WINNT)
|
||||
#ident "$Id: vvm_imod.cc,v 1.1 2000/05/19 04:22:56 steve Exp $"
|
||||
#endif
|
||||
|
||||
|
||||
# include "vvm_func.h"
|
||||
# include "vvm_gates.h"
|
||||
# include <assert.h>
|
||||
|
||||
void vvm_binop_imod(vvm_bitset_t&v, const vvm_bitset_t&l, const vvm_bitset_t&r)
|
||||
{
|
||||
assert(v.get_width() <= 8*sizeof(unsigned long));
|
||||
assert(l.get_width() <= 8*sizeof(unsigned long));
|
||||
assert(r.get_width() <= 8*sizeof(unsigned long));
|
||||
|
||||
unsigned long lv = 0, rv = 0;
|
||||
unsigned long vv;
|
||||
|
||||
for (unsigned idx = 0 ; idx < l.get_width() ; idx += 1) {
|
||||
|
||||
if (B_ISXZ(l[idx]))
|
||||
goto unknown_result;
|
||||
|
||||
if (B_IS1(l[idx]))
|
||||
lv |= 1 << idx;
|
||||
}
|
||||
|
||||
for (unsigned idx = 0 ; idx < r.get_width() ; idx += 1) {
|
||||
|
||||
if (B_ISXZ(r[idx]))
|
||||
goto unknown_result;
|
||||
|
||||
if (B_IS1(r[idx]))
|
||||
rv |= 1 << idx;
|
||||
}
|
||||
|
||||
if (rv == 0)
|
||||
goto unknown_result;
|
||||
|
||||
vv = lv % rv;
|
||||
|
||||
for (unsigned idx = 0 ; idx < v.get_width() ; idx += 1) {
|
||||
|
||||
if (vv & 1)
|
||||
v[idx] = St1;
|
||||
else
|
||||
v[idx] = St0;
|
||||
|
||||
vv >>= 1;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
unknown_result:
|
||||
for (unsigned idx= 0 ; idx < v.get_width() ; idx += 1)
|
||||
v[idx] = StX;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* $Log: vvm_imod.cc,v $
|
||||
* Revision 1.1 2000/05/19 04:22:56 steve
|
||||
* Add the integer modulus function.
|
||||
*
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue