From ec87c7f6def68f302cd963039c4e91431c2e010c Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 27 Feb 2008 09:15:40 -0800 Subject: [PATCH 1/4] Fix %ix/load to work with all index registers. draw_number_bool64() in tgt-vvp/eval_bool.c was using %ix/load to load immediate values into registers greater than three. The problem was that of_IX_LOAD() in vvp/vthread.cc was masking off the upper bits. This was putting the results in the wrong register. This patch removes the bit masking from of_IX_LOAD() and updates the %ix/load documentation. --- vvp/opcodes.txt | 6 +++--- vvp/vthread.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index 117e5c83b..b6b6a4c90 100644 --- a/vvp/opcodes.txt +++ b/vvp/opcodes.txt @@ -342,9 +342,9 @@ bits 4/5/6 just line %ix/get. This instruction loads an immediate value into the addressed index register. The index register holds numeric values, so the is a -number. The idx value selects the index register, and may be 0, 1, 2 -or 3. This is different from %ix/get, which loads the index register -from a value in the thread bit vector. +number. The idx value selects the index register. This is different +from %ix/get, which loads the index register from a value in the +thread bit vector. * %ix/add , diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 4eca71f1c..d8bde41d0 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -1858,7 +1858,7 @@ bool of_IX_MUL(vthread_t thr, vvp_code_t cp) bool of_IX_LOAD(vthread_t thr, vvp_code_t cp) { - thr->words[cp->bit_idx[0] & 3].w_int = cp->number; + thr->words[cp->bit_idx[0]].w_int = cp->number; return true; } From 75df8fb6bb438092b8bbdfd9004bf358fc30890e Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 27 Feb 2008 17:01:53 -0800 Subject: [PATCH 2/4] Remove index register restrictions on ix/arith instructions. The %ix/ instructions are currently not in use, but even so it is just plain wrong to restrict their register argument to 0-3. --- vvp/opcodes.txt | 3 +-- vvp/vthread.cc | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/vvp/opcodes.txt b/vvp/opcodes.txt index b6b6a4c90..f8275e9a8 100644 --- a/vvp/opcodes.txt +++ b/vvp/opcodes.txt @@ -353,8 +353,7 @@ thread bit vector. This instruction adds, subtracts, or multiplies an immediate value to the addressed index register. The index register holds numeric values, -so the is a number. The value selects the index register, -and may be 0, 1, 2 or 3. +so the is a number. The value selects the index register. * %jmp diff --git a/vvp/vthread.cc b/vvp/vthread.cc index d8bde41d0..5915a71bf 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -1840,19 +1840,19 @@ bool of_INV(vthread_t thr, vvp_code_t cp) bool of_IX_ADD(vthread_t thr, vvp_code_t cp) { - thr->words[cp->bit_idx[0] & 3].w_int += cp->number; + thr->words[cp->bit_idx[0]].w_int += cp->number; return true; } bool of_IX_SUB(vthread_t thr, vvp_code_t cp) { - thr->words[cp->bit_idx[0] & 3].w_int -= cp->number; + thr->words[cp->bit_idx[0]].w_int -= cp->number; return true; } bool of_IX_MUL(vthread_t thr, vvp_code_t cp) { - thr->words[cp->bit_idx[0] & 3].w_int *= cp->number; + thr->words[cp->bit_idx[0]].w_int *= cp->number; return true; } From 70c5c9fe149067b45aa49b1bfc8bc624d387fa36 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 27 Feb 2008 11:34:51 -0800 Subject: [PATCH 3/4] Propagate file and line information in more places. There where a few places that were not propagating the file and line information. --- dup_expr.cc | 26 ++++++++++++++++++++------ elab_pexpr.cc | 9 ++++++--- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/dup_expr.cc b/dup_expr.cc index 494afd37e..5c1158b9f 100644 --- a/dup_expr.cc +++ b/dup_expr.cc @@ -24,14 +24,17 @@ NetEBComp* NetEBComp::dup_expr() const { - NetEBComp*result = new NetEBComp(op_, left_->dup_expr(), - right_->dup_expr()); - return result; + NetEBComp*tmp = new NetEBComp(op_, left_->dup_expr(), + right_->dup_expr()); + assert(tmp); + tmp->set_line(*this); + return tmp; } NetEConst* NetEConst::dup_expr() const { NetEConst*tmp = new NetEConst(value_); + assert(tmp); tmp->set_line(*this); return tmp; } @@ -39,6 +42,7 @@ NetEConst* NetEConst::dup_expr() const NetEConstParam* NetEConstParam::dup_expr() const { NetEConstParam*tmp = new NetEConstParam(scope_, name_, value()); + assert(tmp); tmp->set_line(*this); return tmp; } @@ -46,6 +50,7 @@ NetEConstParam* NetEConstParam::dup_expr() const NetECRealParam* NetECRealParam::dup_expr() const { NetECRealParam*tmp = new NetECRealParam(scope_, name_, value()); + assert(tmp); tmp->set_line(*this); return tmp; } @@ -64,9 +69,12 @@ NetEScope* NetEScope::dup_expr() const NetESelect* NetESelect::dup_expr() const { - return new NetESelect(expr_->dup_expr(), - base_? base_->dup_expr() : 0, - expr_width()); + NetESelect*tmp = new NetESelect(expr_->dup_expr(), + base_? base_->dup_expr() : 0, + expr_width()); + assert(tmp); + tmp->set_line(*this); + return tmp; } NetESFunc* NetESFunc::dup_expr() const @@ -80,6 +88,7 @@ NetESFunc* NetESFunc::dup_expr() const tmp->parm(idx, tmp->parm(idx)->dup_expr()); } + tmp->set_line(*this); return tmp; } @@ -96,6 +105,8 @@ NetETernary* NetETernary::dup_expr() const NetETernary*tmp = new NetETernary(cond_->dup_expr(), true_val_->dup_expr(), false_val_->dup_expr()); + assert(tmp); + tmp->set_line(*this); return tmp; } @@ -112,6 +123,7 @@ NetEUFunc* NetEUFunc::dup_expr() const tmp = new NetEUFunc(scope_, func_, result_sig_->dup_expr(), tmp_parms); assert(tmp); + tmp->set_line(*this); return tmp; } @@ -119,6 +131,7 @@ NetEUnary* NetEUnary::dup_expr() const { NetEUnary*tmp = new NetEUnary(op_, expr_->dup_expr()); assert(tmp); + tmp->set_line(*this); return tmp; } @@ -126,5 +139,6 @@ NetEUReduce* NetEUReduce::dup_expr() const { NetEUReduce*tmp = new NetEUReduce(op_, expr_->dup_expr()); assert(tmp); + tmp->set_line(*this); return tmp; } diff --git a/elab_pexpr.cc b/elab_pexpr.cc index ab687a8cd..cfd31d9a1 100644 --- a/elab_pexpr.cc +++ b/elab_pexpr.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2007 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2008 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 @@ -187,6 +187,7 @@ NetExpr*PEIdent::elaborate_pexpr(Design*des, NetScope*scope) const NetExpr*tmp = name_tail.index.back().msb->elaborate_pexpr(des, scope); if (tmp != 0) { res = new NetESelect(res, tmp, 1); + res->set_line(*this); } break; } @@ -216,7 +217,10 @@ NetETernary* PETernary::elaborate_pexpr(Design*des, NetScope*scope) const if (c == 0) return 0; if (t == 0) return 0; if (f == 0) return 0; - return new NetETernary(c, t, f); + + NetETernary*tmp = new NetETernary(c, t, f); + tmp->set_line(*this); + return tmp; } NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const @@ -251,4 +255,3 @@ NetExpr*PEUnary::elaborate_pexpr (Design*des, NetScope*scope) const } return tmp; } - From f8caebd0768fe07eec2fe0fe1a03e93fc4424110 Mon Sep 17 00:00:00 2001 From: Cary R Date: Wed, 27 Feb 2008 15:01:09 -0800 Subject: [PATCH 4/4] Convert real array index to integer. This patch converts a constant real index to an integer value when defining an array. This can happen when using 2**8 which returns a real value since the operands are signed. --- elab_sig.cc | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/elab_sig.cc b/elab_sig.cc index 3119e976c..56153d516 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2007 Stephen Williams (steve@icarus.com) + * Copyright (c) 2000-2008 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 @@ -35,6 +35,32 @@ # include "util.h" # include "ivl_assert.h" +static bool get_const_argument(NetExpr*exp, verinum&res) +{ + switch (exp->expr_type()) { + case IVL_VT_REAL: { + NetECReal*cv = dynamic_cast(exp); + if (cv == 0) return false; + verireal tmp = cv->value(); + res = verinum(tmp.as_long()); + break; + } + + case IVL_VT_BOOL: + case IVL_VT_LOGIC: { + NetEConst*cv = dynamic_cast(exp); + if (cv == 0) return false; + res = cv->value(); + break; + } + + default: + assert(0);; + } + + return true; +} + void Statement::elaborate_sig(Design*des, NetScope*scope) const { } @@ -715,10 +741,14 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const return 0; } - NetEConst*lcon = dynamic_cast (lexp); - NetEConst*rcon = dynamic_cast (rexp); + bool const_flag = true; + verinum lval, rval; + const_flag &= get_const_argument(lexp, lval); + const_flag &= get_const_argument(rexp, rval); + delete rexp; + delete lexp; - if ((lcon == 0) || (rcon == 0)) { + if (!const_flag) { cerr << get_fileline() << ": internal error: The indices " << "are not constant for array ``" << name_ << "''." << endl; @@ -726,12 +756,6 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const return 0; } - verinum lval = lcon->value(); - verinum rval = rcon->value(); - - delete lexp; - delete rexp; - array_dimensions = 1; array_s0 = lval.as_long(); array_e0 = rval.as_long(); @@ -807,4 +831,3 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const return sig; } -