add XOR support.

This commit is contained in:
steve 2001-04-15 16:37:48 +00:00
parent 05e30ed43b
commit 41ce198a1f
8 changed files with 161 additions and 24 deletions

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: eval_expr.c,v 1.15 2001/04/15 04:07:56 steve Exp $"
#ident "$Id: eval_expr.c,v 1.16 2001/04/15 16:37:48 steve Exp $"
#endif
# include "vvp_priv.h"
@ -291,6 +291,11 @@ static struct vector_info draw_binary_expr_logic(ivl_expr_t exp,
lv.base, rv.base, wid);
break;
case '^':
fprintf(vvp_out, " %%xor %u, %u, %u;\n",
lv.base, rv.base, wid);
break;
case 'X': /* exclusive nor (~^) */
fprintf(vvp_out, " %%xnor %u, %u, %u;\n",
lv.base, rv.base, wid);
@ -355,6 +360,7 @@ static struct vector_info draw_binary_expr(ivl_expr_t exp, unsigned wid)
case '&':
case '|':
case '^':
case 'X':
rv = draw_binary_expr_logic(exp, wid);
break;
@ -663,6 +669,9 @@ struct vector_info draw_eval_expr(ivl_expr_t exp)
/*
* $Log: eval_expr.c,v $
* Revision 1.16 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.15 2001/04/15 04:07:56 steve
* Add support for behavioral xnor.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vvp_scope.c,v 1.15 2001/04/14 05:11:49 steve Exp $"
#ident "$Id: vvp_scope.c,v 1.16 2001/04/15 16:37:48 steve Exp $"
#endif
# include "vvp_priv.h"
@ -142,6 +142,10 @@ static void draw_logic_in_scope(ivl_net_logic_t lptr)
ltype = "OR";
break;
case IVL_LO_XOR:
ltype = "XOR";
break;
default:
ltype = "?";
break;
@ -302,6 +306,9 @@ int draw_scope(ivl_scope_t net, ivl_scope_t parent)
/*
* $Log: vvp_scope.c,v $
* Revision 1.16 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.15 2001/04/14 05:11:49 steve
* Use event/or for wide anyedge statements.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: codes.h,v 1.18 2001/04/15 04:07:56 steve Exp $"
#ident "$Id: codes.h,v 1.19 2001/04/15 16:37:48 steve Exp $"
#endif
@ -60,6 +60,7 @@ extern bool of_SET(vthread_t thr, vvp_code_t code);
extern bool of_VPI_CALL(vthread_t thr, vvp_code_t code);
extern bool of_WAIT(vthread_t thr, vvp_code_t code);
extern bool of_XNOR(vthread_t thr, vvp_code_t code);
extern bool of_XOR(vthread_t thr, vvp_code_t code);
extern bool of_ZOMBIE(vthread_t thr, vvp_code_t code);
@ -109,6 +110,9 @@ extern void codespace_dump(FILE*fd);
/*
* $Log: codes.h,v $
* Revision 1.19 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.18 2001/04/15 04:07:56 steve
* Add support for behavioral xnor.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: compile.cc,v 1.33 2001/04/15 04:07:56 steve Exp $"
#ident "$Id: compile.cc,v 1.34 2001/04/15 16:37:48 steve Exp $"
#endif
# include "compile.h"
@ -89,6 +89,7 @@ const static struct opcode_table_s opcode_table[] = {
{ "%set", of_SET, 2, {OA_FUNC_PTR, OA_BIT1, OA_NONE} },
{ "%wait", of_WAIT, 1, {OA_FUNC_PTR, OA_NONE, OA_NONE} },
{ "%xnor", of_XNOR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ "%xor", of_XOR, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} },
{ 0, of_NOOP, 0, {OA_NONE, OA_NONE, OA_NONE} }
};
@ -267,6 +268,9 @@ void compile_functor(char*label, char*type, unsigned init,
} else if (strcmp(type, "NOT") == 0) {
obj->table = ft_NOT;
} else if (strcmp(type, "XOR") == 0) {
obj->table = ft_XOR;
} else {
yyerror("invalid functor type.");
}
@ -759,6 +763,9 @@ void compile_dump(FILE*fd)
/*
* $Log: compile.cc,v $
* Revision 1.34 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.33 2001/04/15 04:07:56 steve
* Add support for behavioral xnor.
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: draw_tt.c,v 1.4 2001/04/01 21:31:46 steve Exp $"
#ident "$Id: draw_tt.c,v 1.5 2001/04/15 16:37:48 steve Exp $"
#endif
# include <stdio.h>
@ -188,6 +188,70 @@ static void draw_OR(void)
printf("};\n");
}
static void draw_XNOR(void)
{
unsigned i0, i1, i2, i3;
printf("const unsigned char ft_XNOR[64] = {");
for (i3 = 0 ; i3 < 4 ; i3 += 1)
for (i2 = 0 ; i2 < 4 ; i2 += 1) {
printf("\n ");
for (i1 = 0 ; i1 < 4 ; i1 += 1) {
unsigned idx = (i3 << 4) | (i2 << 2) | i1;
unsigned char byte = 0;
for (i0 = 0 ; i0 < 4 ; i0 += 1) {
unsigned val;
if ((i0 > 1) || (i1 > 1)
|| (i2 > 1) || (i3 > 1))
val = 2;
else
val = (i0 + i1 + i2 + i3) % 2 ^ 1;
byte |= val << (i0*2);
}
printf("0x%02x, ", byte);
}
}
printf("};\n");
}
static void draw_XOR(void)
{
unsigned i0, i1, i2, i3;
printf("const unsigned char ft_XOR[64] = {");
for (i3 = 0 ; i3 < 4 ; i3 += 1)
for (i2 = 0 ; i2 < 4 ; i2 += 1) {
printf("\n ");
for (i1 = 0 ; i1 < 4 ; i1 += 1) {
unsigned idx = (i3 << 4) | (i2 << 2) | i1;
unsigned char byte = 0;
for (i0 = 0 ; i0 < 4 ; i0 += 1) {
unsigned val;
if ((i0 > 1) || (i1 > 1)
|| (i2 > 1) || (i3 > 1))
val = 2;
else
val = (i0 + i1 + i2 + i3) % 2;
byte |= val << (i0*2);
}
printf("0x%02x, ", byte);
}
}
printf("};\n");
}
/*
* The hex_digits table is not a functor truth table per say, but a
* map of a 4-vbit value to a hex digit. The table handles the display
@ -293,6 +357,8 @@ main()
draw_NOR();
draw_NOT();
draw_OR();
draw_XNOR();
draw_XOR();
draw_hex_table();
draw_oct_table();
return 0;
@ -300,6 +366,9 @@ main()
/*
* $Log: draw_tt.c,v $
* Revision 1.5 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.4 2001/04/01 21:31:46 steve
* Add the buf functor type.
*

View File

@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: functor.h,v 1.11 2001/04/14 05:10:56 steve Exp $"
#ident "$Id: functor.h,v 1.12 2001/04/15 16:37:48 steve Exp $"
#endif
# include "pointers.h"
@ -172,10 +172,14 @@ extern const unsigned char ft_BUF[];
extern const unsigned char ft_NOR[];
extern const unsigned char ft_NOT[];
extern const unsigned char ft_OR[];
extern const unsigned char ft_XOR[];
extern const unsigned char ft_var[];
/*
* $Log: functor.h,v $
* Revision 1.12 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.11 2001/04/14 05:10:56 steve
* support the .event/or statement.
*
@ -193,21 +197,5 @@ extern const unsigned char ft_var[];
*
* Revision 1.6 2001/03/26 04:00:39 steve
* Add the .event statement and the %wait instruction.
*
* Revision 1.5 2001/03/25 19:38:23 steve
* Support NOR and NOT gates.
*
* Revision 1.4 2001/03/22 05:08:00 steve
* implement %load, %inv, %jum/0 and %cmp/u
*
* Revision 1.3 2001/03/20 06:16:24 steve
* Add support for variable vectors.
*
* Revision 1.2 2001/03/11 22:42:11 steve
* Functor values and propagation.
*
* Revision 1.1 2001/03/11 00:29:38 steve
* Add the vvp engine to cvs.
*
*/
#endif

View File

@ -1,7 +1,7 @@
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*
* $Id: opcodes.txt,v 1.12 2001/04/15 04:07:56 steve Exp $
* $Id: opcodes.txt,v 1.13 2001/04/15 16:37:48 steve Exp $
*/
@ -203,6 +203,19 @@ and leaves the result in the <dst> vector. xnor is this:
1 xnor 1 --> 1
otherwise x
* %xor <dst>, <src>, <wid>
This does a bitwise exclusive or (^) of the <src> and <dst> vector,
and leaves the result in the <dst> vector. xor is this:
0 xnor 0 --> 0
0 xnor 1 --> 1
1 xnor 0 --> 1
1 xnor 1 --> 0
otherwise x
/*
* Copyright (c) 2001 Stephen Williams (steve@icarus.com)
*

View File

@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if !defined(WINNT)
#ident "$Id: vthread.cc,v 1.25 2001/04/15 04:07:56 steve Exp $"
#ident "$Id: vthread.cc,v 1.26 2001/04/15 16:37:48 steve Exp $"
#endif
# include "vthread.h"
@ -727,6 +727,43 @@ bool of_XNOR(vthread_t thr, vvp_code_t cp)
}
bool of_XOR(vthread_t thr, vvp_code_t cp)
{
assert(cp->bit_idx1 >= 4);
unsigned idx1 = cp->bit_idx1;
unsigned idx2 = cp->bit_idx2;
for (unsigned idx = 0 ; idx < cp->number ; idx += 1) {
unsigned lb = thr_get_bit(thr, idx1);
unsigned rb = thr_get_bit(thr, idx2);
if ((lb == 1) && (rb == 1)) {
thr_put_bit(thr, idx1, 0);
} else if ((lb == 0) && (rb == 0)) {
thr_put_bit(thr, idx1, 0);
} else if ((lb == 1) && (rb == 0)) {
thr_put_bit(thr, idx1, 1);
} else if ((lb == 0) && (rb == 1)) {
thr_put_bit(thr, idx1, 1);
} else {
thr_put_bit(thr, idx1, 2);
}
idx1 += 1;
if (idx2 >= 4)
idx2 += 1;
}
return true;
}
bool of_ZOMBIE(vthread_t, vvp_code_t)
{
return false;
@ -734,6 +771,9 @@ bool of_ZOMBIE(vthread_t, vvp_code_t)
/*
* $Log: vthread.cc,v $
* Revision 1.26 2001/04/15 16:37:48 steve
* add XOR support.
*
* Revision 1.25 2001/04/15 04:07:56 steve
* Add support for behavioral xnor.
*