Implement .arith/div.

This commit is contained in:
steve 2005-02-19 01:32:52 +00:00
parent 2fcaac4060
commit 589eb1d315
3 changed files with 66 additions and 17 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: arith.cc,v 1.38 2005/02/04 05:13:02 steve Exp $"
#ident "$Id: arith.cc,v 1.39 2005/02/19 01:32:52 steve Exp $"
#endif
# include "arith.h"
@ -58,15 +58,60 @@ void vvp_arith_::dispatch_operand_(vvp_net_ptr_t ptr, vvp_vector4_t bit)
// Division
inline void vvp_arith_div::wide(vvp_ipoint_t base, bool push)
vvp_arith_div::vvp_arith_div(unsigned wid, bool signed_flag)
: vvp_arith_(wid), signed_flag_(signed_flag)
{
}
vvp_arith_div::~vvp_arith_div()
{
}
void vvp_arith_div::wide_(vvp_net_ptr_t ptr)
{
assert(0);
}
void vvp_arith_div::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
{
dispatch_operand_(ptr, bit);
if (wid_ > 8 * sizeof(unsigned long)) {
wide_(ptr);
return ;
}
unsigned long a;
if (! vector4_to_value(op_a_, a)) {
vvp_send_vec4(ptr.ptr()->out, x_val_);
return;
}
unsigned long b;
if (! vector4_to_value(op_b_, b)) {
vvp_send_vec4(ptr.ptr()->out, x_val_);
return;
}
unsigned long val = a / b;
assert(wid_ <= 8*sizeof(val));
vvp_vector4_t vval (wid_);
for (unsigned idx = 0 ; idx < wid_ ; idx += 1) {
if (val & 1)
vval.set_bit(idx, BIT4_1);
else
vval.set_bit(idx, BIT4_0);
val >>= 1;
}
vvp_send_vec4(ptr.ptr()->out, vval);
}
#if 0
void vvp_arith_div::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
{
#if 0
put(i, val);
vvp_ipoint_t base = ipoint_make(i,0);
@ -119,10 +164,8 @@ void vvp_arith_div::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
result = 0 - result;
output_val_(base, push, result);
#else
fprintf(stderr, "XXXX forgot how to implement vvp_arith_div::set\n");
#endif
}
#endif
inline void vvp_arith_mod::wide(vvp_ipoint_t base, bool push)
{
@ -673,6 +716,9 @@ void vvp_shiftr::set(vvp_ipoint_t i, bool push, unsigned val, unsigned)
/*
* $Log: arith.cc,v $
* Revision 1.39 2005/02/19 01:32:52 steve
* Implement .arith/div.
*
* Revision 1.38 2005/02/04 05:13:02 steve
* Add wide .arith/mult, and vvp_vector2_t vectors.
*

View File

@ -1,7 +1,7 @@
#ifndef __arith_H
#define __arith_H
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
* Copyright (c) 2001-2005 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
@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: arith.h,v 1.25 2005/02/04 05:13:02 steve Exp $"
#ident "$Id: arith.h,v 1.26 2005/02/19 01:32:52 steve Exp $"
#endif
# include "functor.h"
@ -56,13 +56,11 @@ class vvp_arith_ : public vvp_net_fun_t {
class vvp_arith_div : public vvp_arith_ {
public:
explicit vvp_arith_div(unsigned wid, bool signed_flag)
: vvp_arith_(wid), signed_flag_(signed_flag) {}
void set(vvp_ipoint_t i, bool push, unsigned val, unsigned str);
void wide(vvp_ipoint_t base, bool push);
explicit vvp_arith_div(unsigned wid, bool signed_flag);
~vvp_arith_div();
void recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit);
private:
void wide_(vvp_net_ptr_t ptr);
bool signed_flag_;
};
@ -191,6 +189,9 @@ class vvp_shiftr : public vvp_arith_ {
/*
* $Log: arith.h,v $
* Revision 1.26 2005/02/19 01:32:52 steve
* Implement .arith/div.
*
* Revision 1.25 2005/02/04 05:13:02 steve
* Add wide .arith/mult, and vvp_vector2_t vectors.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: compile.cc,v 1.187 2005/02/14 01:50:23 steve Exp $"
#ident "$Id: compile.cc,v 1.188 2005/02/19 01:32:53 steve Exp $"
#endif
# include "arith.h"
@ -880,14 +880,13 @@ void compile_arith_div(char*label, long wid, bool signed_flag,
{
assert( wid > 0 );
if ((long)argc != 2*wid) {
if (argc != 2) {
fprintf(stderr, "%s; .arith/div has wrong number of symbols\n", label);
compile_errors += 1;
return;
}
vvp_arith_ *arith = new vvp_arith_div(wid, signed_flag);
make_arith(arith, label, wid, argc, argv);
}
@ -1618,6 +1617,9 @@ void compile_param_string(char*label, char*name, char*str, char*value)
/*
* $Log: compile.cc,v $
* Revision 1.188 2005/02/19 01:32:53 steve
* Implement .arith/div.
*
* Revision 1.187 2005/02/14 01:50:23 steve
* Signals may receive part vectors from %set/x0
* instructions. Re-implement the %set/x0 to do