From 09a134d973b45844f3ab965ab42d1e717c222c20 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 24 Feb 2024 11:39:22 +0000 Subject: [PATCH] Fix synthesis of concatentation to always make result unsigned. When there is only one operand, we elide the concatenation during expression synthesis. But if that operand is signed, we need to insert an intermediate local signel to cast it to unsigned. This fixes issue #1099. --- expr_synth.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/expr_synth.cc b/expr_synth.cc index 54142e51c..ba4696485 100644 --- a/expr_synth.cc +++ b/expr_synth.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999-2021 Stephen Williams (steve@icarus.com) + * Copyright (c) 1999-2024 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 @@ -818,6 +818,17 @@ NetNet* NetEConcat::synthesize(Design*des, NetScope*scope, NetExpr*root) } } ivl_assert(*this, osig); + if (osig->get_signed()) { + // A concatenation is always unsigned, so make a new signal to + // reflect this. + NetNet*isig = osig; + auto osig_vec = new netvector_t(data_type, isig->vector_width() - 1, 0); + osig = new NetNet(scope, scope->local_symbol(), NetNet::IMPLICIT, + osig_vec); + osig->set_line(*this); + osig->local_flag(true); + connect(isig->pin(0), osig->pin(0)); + } } if (repeat() != 1) {