From 7e06a87b8e15275f756b4d0048e2cd24e48681e7 Mon Sep 17 00:00:00 2001 From: Cary R Date: Thu, 17 Dec 2009 19:22:34 -0800 Subject: [PATCH] Properly extend/crop a user function argument in a continuous assignment. When passing an argument to a user function in a continuous assignment we need to sign extend the value if it is signed and too short. We need to crop an argument if it is too long. --- expr_synth.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/expr_synth.cc b/expr_synth.cc index 3c7e258b8..e5bd183b3 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -1413,9 +1413,15 @@ NetNet* NetEUFunc::synthesize(Design*des, NetScope*scope, NetExpr*root) /* Connect the pins to the arguments. */ NetFuncDef*def = func_->func_def(); for (unsigned idx = 0; idx < eparms.count(); idx += 1) { - NetNet*tmp = pad_to_width(des, eparms[idx], - def->port(idx)->vector_width(), *this); - connect(net->pin(idx+1), tmp->pin(0)); + unsigned width = def->port(idx)->vector_width(); + NetNet*tmp; + if (eparms[idx]->get_signed()) { + tmp = pad_to_width_signed(des, eparms[idx], width, *this); + } else { + tmp = pad_to_width(des, eparms[idx], width, *this); + } + NetNet*tmpc = crop_to_width(des, tmp, width); + connect(net->pin(idx+1), tmpc->pin(0)); } return osig;