Reduction OR operator
This commit is contained in:
parent
38de6ebf3a
commit
77508b9afa
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "vhdl_target.h"
|
||||
#include "support.hh"
|
||||
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
|
@ -132,7 +133,10 @@ static vhdl_expr *translate_unary(ivl_expr_t e)
|
|||
case 'N': // NOR
|
||||
case '|':
|
||||
{
|
||||
vhdl_fcall *f = new vhdl_fcall("Reduce_OR", vhdl_type::std_logic());
|
||||
require_support_function(SF_REDUCE_OR);
|
||||
vhdl_fcall *f =
|
||||
new vhdl_fcall(support_function::function_name(SF_REDUCE_OR),
|
||||
vhdl_type::std_logic());
|
||||
f->add_expr(operand);
|
||||
if ('N' == opcode)
|
||||
return new vhdl_unaryop_expr(VHDL_UNARYOP_NOT, f, vhdl_type::std_logic());
|
||||
|
|
|
|||
|
|
@ -170,15 +170,18 @@ 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,
|
||||
const char *rfunc, bool invert)
|
||||
support_function_t f, bool invert)
|
||||
{
|
||||
vhdl_fcall *fcall = new vhdl_fcall(rfunc, vhdl_type::std_logic());
|
||||
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;
|
||||
|
||||
fcall->add_expr(ref);
|
||||
|
||||
vhdl_type std_logic_vector(VHDL_TYPE_STD_LOGIC_VECTOR);
|
||||
fcall->add_expr(ref->cast(&std_logic_vector));
|
||||
|
||||
if (invert)
|
||||
return new vhdl_unaryop_expr
|
||||
|
|
@ -258,18 +261,18 @@ static vhdl_expr *lpm_to_expr(vhdl_scope *scope, ivl_lpm_t lpm)
|
|||
return part_select_pv_lpm_to_expr(scope, lpm);
|
||||
case IVL_LPM_UFUNC:
|
||||
return ufunc_lpm_to_expr(scope, lpm);
|
||||
case IVL_LPM_RE_AND:
|
||||
/*case IVL_LPM_RE_AND:
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_AND", false);
|
||||
case IVL_LPM_RE_NAND:
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_AND", true);
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_AND", true);*/
|
||||
case IVL_LPM_RE_NOR:
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_OR", true);
|
||||
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_OR, true);
|
||||
case IVL_LPM_RE_OR:
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_OR", false);
|
||||
case IVL_LPM_RE_XOR:
|
||||
return reduction_lpm_to_expr(scope, lpm, SF_REDUCE_OR, false);
|
||||
/*case IVL_LPM_RE_XOR:
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_XOR", false);
|
||||
case IVL_LPM_RE_XNOR:
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_XNOR", false);
|
||||
return reduction_lpm_to_expr(scope, lpm, "Reduce_XNOR", false);*/
|
||||
case IVL_LPM_SIGN_EXT:
|
||||
return sign_extend_lpm_to_expr(scope, lpm);
|
||||
case IVL_LPM_ARRAY:
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "support.hh"
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
void require_support_function(support_function_t f)
|
||||
{
|
||||
|
|
@ -39,6 +40,8 @@ const char *support_function::function_name(support_function_t type)
|
|||
return "Signed_To_Boolean";
|
||||
case SF_BOOLEAN_TO_LOGIC:
|
||||
return "Boolean_To_Logic";
|
||||
case SF_REDUCE_OR:
|
||||
return "Reduce_OR";
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
|
@ -48,10 +51,10 @@ vhdl_type *support_function::function_type(support_function_t type)
|
|||
{
|
||||
switch (type) {
|
||||
case SF_UNSIGNED_TO_BOOLEAN:
|
||||
return vhdl_type::boolean();
|
||||
case SF_SIGNED_TO_BOOLEAN:
|
||||
return vhdl_type::boolean();
|
||||
case SF_BOOLEAN_TO_LOGIC:
|
||||
case SF_REDUCE_OR:
|
||||
return vhdl_type::std_logic();
|
||||
default:
|
||||
assert(false);
|
||||
|
|
@ -82,6 +85,16 @@ void support_function::emit(std::ostream &of, int level) const
|
|||
<< "return '0'" << nl_string(indent(level))
|
||||
<< "end if;" << nl_string(level);
|
||||
break;
|
||||
case SF_REDUCE_OR:
|
||||
of << "(X : std_logic_vector) return std_logic is" << nl_string(level)
|
||||
<< "begin" << nl_string(indent(level))
|
||||
<< "for I in X'Range loop" << nl_string(indent(indent(level)))
|
||||
<< "if X(I) = '1' then" << nl_string(indent(indent(indent(level))))
|
||||
<< "return '1';" << nl_string(indent(indent(level)))
|
||||
<< "end if;" << nl_string(indent(level))
|
||||
<< "end loop;" << nl_string(indent(level))
|
||||
<< "return '0';" << nl_string(level);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ enum support_function_t {
|
|||
SF_UNSIGNED_TO_BOOLEAN,
|
||||
SF_SIGNED_TO_BOOLEAN,
|
||||
SF_BOOLEAN_TO_LOGIC,
|
||||
SF_REDUCE_OR,
|
||||
};
|
||||
|
||||
class support_function : public vhdl_function {
|
||||
|
|
|
|||
Loading…
Reference in New Issue