diff --git a/tgt-vhdl/expr.cc b/tgt-vhdl/expr.cc index 10465684c..0bf7d7991 100644 --- a/tgt-vhdl/expr.cc +++ b/tgt-vhdl/expr.cc @@ -180,6 +180,10 @@ static vhdl_expr *translate_unary(ivl_expr_t e) return translate_reduction(SF_REDUCE_AND, true, operand); case '&': return translate_reduction(SF_REDUCE_AND, false, operand); + case '^': // XOR + return translate_reduction(SF_REDUCE_XOR, false, operand); + case 'X': // XNOR + return translate_reduction(SF_REDUCE_XNOR, false, operand); default: error("No translation for unary opcode '%c'\n", ivl_expr_opcode(e)); diff --git a/tgt-vhdl/support.cc b/tgt-vhdl/support.cc index 9ad74a3ca..b299aa486 100644 --- a/tgt-vhdl/support.cc +++ b/tgt-vhdl/support.cc @@ -40,6 +40,7 @@ const char *support_function::function_name(support_function_t type) case SF_REDUCE_OR: return "Reduce_OR"; case SF_REDUCE_AND: return "Reduce_AND"; case SF_REDUCE_XOR: return "Reduce_XOR"; + case SF_REDUCE_XNOR: return "Reduce_XNOR"; case SF_TERNARY_LOGIC: return "Ternary_Logic"; case SF_TERNARY_UNSIGNED: return "Ternary_Unsigned"; case SF_TERNARY_SIGNED: return "Ternary_Signed"; @@ -61,6 +62,7 @@ vhdl_type *support_function::function_type(support_function_t type) case SF_REDUCE_OR: case SF_REDUCE_AND: case SF_REDUCE_XOR: + case SF_REDUCE_XNOR: case SF_TERNARY_LOGIC: case SF_SIGNED_TO_LOGIC: case SF_UNSIGNED_TO_LOGIC: @@ -146,6 +148,16 @@ void support_function::emit(std::ostream &of, int level) const << "end loop;" << nl_string(indent(level)) << "return R;"; break; + case SF_REDUCE_XNOR: + of << "(X : std_logic_vector) return std_logic is" + << nl_string(indent(level)) + << "variable R : std_logic := '0';" << nl_string(level) + << "begin" << nl_string(indent(level)) + << "for I in X'Range loop" << nl_string(indent(indent(level))) + << "R := X(I) xnor R;" << nl_string(indent(level)) + << "end loop;" << nl_string(indent(level)) + << "return R;"; + break; case SF_TERNARY_LOGIC: of << "(T : Boolean; X, Y : std_logic) return std_logic is"; emit_ternary(of, level); diff --git a/tgt-vhdl/support.hh b/tgt-vhdl/support.hh index 234831c24..a738b0691 100644 --- a/tgt-vhdl/support.hh +++ b/tgt-vhdl/support.hh @@ -30,6 +30,7 @@ enum support_function_t { SF_REDUCE_OR, SF_REDUCE_AND, SF_REDUCE_XOR, + SF_REDUCE_XNOR, SF_TERNARY_LOGIC, SF_TERNARY_UNSIGNED, SF_TERNARY_SIGNED,