Add support for real valued modulus.

This commit is contained in:
steve 2006-08-09 05:19:08 +00:00
parent fc0695beb6
commit 50800fd3a1
6 changed files with 56 additions and 8 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: elab_expr.cc,v 1.107 2006/07/31 03:50:17 steve Exp $"
#ident "$Id: elab_expr.cc,v 1.108 2006/08/09 05:19:08 steve Exp $"
#endif
# include "config.h"
@ -111,8 +111,19 @@ NetEBinary* PEBinary::elaborate_expr_base_(Design*des,
tmp->set_line(*this);
break;
case '/':
case '%':
/* The % operator does not support real arguments in
baseline Verilog. But we allow it in our extended
form of verilog. */
if (generation_flag < GN_VER2001X) {
if (lp->expr_type()==IVL_VT_REAL || rp->expr_type()==IVL_VT_REAL) {
cerr << get_line() << ": error: Modulus operator may not "
"have REAL operands." << endl;
des->errors += 1;
}
}
/* Fall through to handle the % with the / operator. */
case '/':
tmp = new NetEBDiv(op_, lp, rp);
tmp->set_line(*this);
break;
@ -1387,6 +1398,9 @@ NetExpr* PEUnary::elaborate_expr(Design*des, NetScope*scope,
/*
* $Log: elab_expr.cc,v $
* Revision 1.108 2006/08/09 05:19:08 steve
* Add support for real valued modulus.
*
* Revision 1.107 2006/07/31 03:50:17 steve
* Add support for power in constant expressions.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: eval_real.c,v 1.14 2005/07/13 04:52:31 steve Exp $"
#ident "$Id: eval_real.c,v 1.15 2006/08/09 05:19:08 steve Exp $"
#endif
/*
@ -80,6 +80,10 @@ static int draw_binary_real(ivl_expr_t exp)
fprintf(vvp_out, " %%div/wr %d, %d;\n", l, r);
break;
case '%':
fprintf(vvp_out, " %%mod/wr %d, %d;\n", l, r);
break;
#if 0
case '%':
{ struct vector_info res = draw_eval_expr(exp, STUFF_OK_XZ);
l = allocate_word();
@ -89,7 +93,7 @@ static int draw_binary_real(ivl_expr_t exp)
clr_vector(res);
}
break;
#endif
default:
fprintf(stderr, "XXXX draw_binary_real(%c)\n",
ivl_expr_opcode(exp));
@ -312,6 +316,9 @@ int draw_eval_real(ivl_expr_t exp)
/*
* $Log: eval_real.c,v $
* Revision 1.15 2006/08/09 05:19:08 steve
* Add support for real valued modulus.
*
* Revision 1.14 2005/07/13 04:52:31 steve
* Handle functions with real values.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: codes.h,v 1.78 2006/02/02 02:44:00 steve Exp $"
#ident "$Id: codes.h,v 1.79 2006/08/09 05:19:08 steve Exp $"
#endif
@ -95,6 +95,7 @@ extern bool of_LOAD_XP(vthread_t thr, vvp_code_t code);
extern bool of_LOADI_WR(vthread_t thr, vvp_code_t code);
extern bool of_MOD(vthread_t thr, vvp_code_t code);
extern bool of_MOD_S(vthread_t thr, vvp_code_t code);
extern bool of_MOD_WR(vthread_t thr, vvp_code_t code);
extern bool of_MOV(vthread_t thr, vvp_code_t code);
extern bool of_MUL(vthread_t thr, vvp_code_t code);
extern bool of_MUL_WR(vthread_t thr, vvp_code_t code);
@ -178,6 +179,9 @@ extern vvp_code_t codespace_null(void);
/*
* $Log: codes.h,v $
* Revision 1.79 2006/08/09 05:19:08 steve
* Add support for real valued modulus.
*
* Revision 1.78 2006/02/02 02:44:00 steve
* Allow part selects of memory words in l-values.
*

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.222 2006/08/08 05:11:37 steve Exp $"
#ident "$Id: compile.cc,v 1.223 2006/08/09 05:19:08 steve Exp $"
#endif
# include "arith.h"
@ -139,6 +139,7 @@ const static struct opcode_table_s opcode_table[] = {
{ "%loadi/wr",of_LOADI_WR,3,{OA_BIT1, OA_NUMBER, OA_BIT2} },
{ "%mod", of_MOD, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%mod/s", of_MOD_S, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%mod/wr", of_MOD_WR, 2, {OA_BIT1, OA_BIT2, OA_NONE} },
{ "%mov", of_MOV, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%mul", of_MUL, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%mul/wr", of_MUL_WR, 2, {OA_BIT1, OA_BIT2, OA_NONE} },
@ -1496,6 +1497,9 @@ void compile_param_string(char*label, char*name, char*value)
/*
* $Log: compile.cc,v $
* Revision 1.223 2006/08/09 05:19:08 steve
* Add support for real valued modulus.
*
* Revision 1.222 2006/08/08 05:11:37 steve
* Handle 64bit delay constants.
*

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2001-2003 Stephen Williams (steve@icarus.com)
*
* $Id: opcodes.txt,v 1.70 2006/02/02 02:44:00 steve Exp $
* $Id: opcodes.txt,v 1.71 2006/08/09 05:19:08 steve Exp $
*/
@ -424,6 +424,10 @@ replaced with the result.
The /s form does signed %.
* %mod/wr <bit-l>, <bit-r>
This opcode is the real-valued modulus of the two real values.
* %mov <dst>, <src>, <wid>
This instruction copies a vector from one place in register space to

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: vthread.cc,v 1.155 2006/08/08 05:11:37 steve Exp $"
#ident "$Id: vthread.cc,v 1.156 2006/08/09 05:19:08 steve Exp $"
#endif
# include "config.h"
@ -2279,6 +2279,18 @@ bool of_MOD_S(vthread_t thr, vvp_code_t cp)
return true;
}
/*
* %mod/wr <dest>, <src>
*/
bool of_MOD_WR(vthread_t thr, vvp_code_t cp)
{
double l = thr->words[cp->bit_idx[0]].w_real;
double r = thr->words[cp->bit_idx[1]].w_real;
thr->words[cp->bit_idx[0]].w_real = fmod(l,r);
return true;
}
/*
* %mov <dest>, <src>, <wid>
* This instruction is implemented by the of_MOV function
@ -3272,6 +3284,9 @@ bool of_JOIN_UFUNC(vthread_t thr, vvp_code_t cp)
/*
* $Log: vthread.cc,v $
* Revision 1.156 2006/08/09 05:19:08 steve
* Add support for real valued modulus.
*
* Revision 1.155 2006/08/08 05:11:37 steve
* Handle 64bit delay constants.
*