From 09f3eb4a364a28a0c6bc651f660e1bd09ebe371d Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 1 Aug 2008 16:27:55 +0100 Subject: [PATCH] Don't bother calling reduction function if argument is std_logic --- tgt-vhdl/expr.cc | 26 +++++++++++++++++--------- tgt-vhdl/lpm.cc | 25 ++++++++++++++++--------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/tgt-vhdl/expr.cc b/tgt-vhdl/expr.cc index 7ad67c3ee..c57f951a1 100644 --- a/tgt-vhdl/expr.cc +++ b/tgt-vhdl/expr.cc @@ -106,18 +106,26 @@ static vhdl_expr *translate_ulong(ivl_expr_t e) static vhdl_expr *translate_reduction(support_function_t f, bool neg, vhdl_expr *operand) { - require_support_function(f); - vhdl_fcall *fcall = - new vhdl_fcall(support_function::function_name(f), - vhdl_type::std_logic()); - - vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR); - fcall->add_expr(operand->cast(&std_logic_vector)); + vhdl_expr *result; + if (operand->get_type()->get_name() == VHDL_TYPE_STD_LOGIC) + result = operand; + else { + require_support_function(f); + vhdl_fcall *fcall = + new vhdl_fcall(support_function::function_name(f), + vhdl_type::std_logic()); + + vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR); + fcall->add_expr(operand->cast(&std_logic_vector)); + + result = fcall; + } + if (neg) - return new vhdl_unaryop_expr(VHDL_UNARYOP_NOT, fcall, + return new vhdl_unaryop_expr(VHDL_UNARYOP_NOT, result, vhdl_type::std_logic()); else - return fcall; + return result; } static vhdl_expr *translate_unary(ivl_expr_t e) diff --git a/tgt-vhdl/lpm.cc b/tgt-vhdl/lpm.cc index b3d92b466..c13cf2cbc 100644 --- a/tgt-vhdl/lpm.cc +++ b/tgt-vhdl/lpm.cc @@ -144,22 +144,29 @@ static vhdl_expr *ufunc_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm) static vhdl_expr *reduction_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm, support_function_t f, bool invert) { - require_support_function(f); - vhdl_fcall *fcall = new vhdl_fcall(support_function::function_name(f), - vhdl_type::std_logic()); - vhdl_var_ref *ref = nexus_to_var_ref(scope, ivl_lpm_data(lpm, 0)); if (NULL == ref) return NULL; - vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR); - fcall->add_expr(ref->cast(&std_logic_vector)); - + vhdl_expr *result; + if (ref->get_type()->get_name() == VHDL_TYPE_STD_LOGIC) + result = ref; + else { + require_support_function(f); + vhdl_fcall *fcall = new vhdl_fcall(support_function::function_name(f), + vhdl_type::std_logic()); + + vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR); + fcall->add_expr(ref->cast(&std_logic_vector)); + + result = fcall; + } + if (invert) return new vhdl_unaryop_expr - (VHDL_UNARYOP_NOT, fcall, vhdl_type::std_logic()); + (VHDL_UNARYOP_NOT, result, vhdl_type::std_logic()); else - return fcall; + return result; } static vhdl_expr *sign_extend_lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)