Skip to content

Commit

Permalink
- Fixed codegen for some reductions
Browse files Browse the repository at this point in the history
- ExpressionSimplify:
  + min/max({exp}) => exp
  + min/max({exp1,exp2}) => min/max(exp1,exp2)


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7804 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 28, 2011
1 parent df8e10c commit 5951d7e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
14 changes: 13 additions & 1 deletion Compiler/FrontEnd/ExpressionSimplify.mo
Expand Up @@ -529,14 +529,26 @@ algorithm
outExp := match(exp)
local
list<DAE.Exp> expl;
DAE.Exp e,len_exp,just_exp;
DAE.Exp e,len_exp,just_exp,e1,e2;
DAE.ExpType tp;
list<DAE.Exp> v1, v2;
Boolean scalar;
list<Values.Value> valueLst;
Integer i;
String str;

// min/max function on arrays of only 1 element
case (DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ARRAY(array={e})})) then simplify1(e);
case (DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ARRAY(array={e})})) then simplify1(e);
case (DAE.CALL(path=Absyn.IDENT("min"),ty=DAE.ET_ARRAY(tp,{_}),expLst={DAE.ARRAY(array={e1,e2})}))
equation
e = Expression.makeBuiltinCall("min",{e1,e2},tp);
then simplify1(e);
case (DAE.CALL(path=Absyn.IDENT("max"),ty=DAE.ET_ARRAY(tp,{_}),expLst={DAE.ARRAY(array={e1,e2})}))
equation
e = Expression.makeBuiltinCall("max",{e1,e2},tp);
then simplify1(e);

// cross
case (e as DAE.CALL(path = Absyn.IDENT("cross"), builtin = true, expLst = expl))
equation
Expand Down
8 changes: 4 additions & 4 deletions Compiler/susan_codegen/SimCode/SimCodeC.tpl
Expand Up @@ -5638,14 +5638,14 @@ template daeExpReductionFnName(String reduction_op, String type)
match reduction_op
case "sum" then
match type
case "modelica_integer" then "intAdd"
case "modelica_real" then "realAdd"
case "modelica_integer" then "reduction_sum"
case "modelica_real" then "reduction_sum"
else "INVALID_TYPE"
end match
case "product" then
match type
case "modelica_integer" then "intMul"
case "modelica_real" then "realMul"
case "modelica_integer" then "reduction_product"
case "modelica_real" then "reduction_product"
else "INVALID_TYPE"
end match
else reduction_op
Expand Down
3 changes: 3 additions & 0 deletions c_runtime/utility.h
Expand Up @@ -53,4 +53,7 @@ modelica_integer modelica_mod_integer(modelica_integer x, modelica_integer y);
modelica_real modelica_rem_real(modelica_real x, modelica_real y);
modelica_integer modelica_rem_integer(modelica_integer x, modelica_integer y);

#define reduction_sum(X,Y) ((X)+(Y))
#define reduction_product(X,Y) ((X)*(Y))

#endif

0 comments on commit 5951d7e

Please sign in to comment.