Skip to content

Commit

Permalink
Remove more code related to algebraic macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhinder committed Mar 17, 2014
1 parent 3f8d36d commit bc9d2a5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
26 changes: 2 additions & 24 deletions Tools/CodeGen/CodeGenKranc.m
Expand Up @@ -192,23 +192,7 @@
ProcessExpression[expr_, vectorise:Boolean, noSimplify:Boolean : False] :=
Module[
{rhs},
rhs = expr (*/. Power[xx_, -1] -> INV[xx];
rhs = rhs //. Power[xx_, 2 ] -> SQR[xx];
rhs = rhs //. Power[xx_, 3 ] -> CUB[xx];
rhs = rhs //. Power[xx_, 4 ] -> QAD[xx];
rhs = rhs //. Power[xx_, -2 ] -> INV[SQR[xx]];
rhs = rhs //. Power[xx_, -3 ] -> INV[CUB[xx]];
rhs = rhs //. Power[xx_, -4 ] -> INV[QAD[xx]];
rhs = rhs //. Power[xx_, 1/2] -> sqrt[xx];
rhs = rhs //. Power[xx_, -1/2] -> INV[sqrt[xx]];
rhs = rhs //. Power[xx_, 0.5] -> sqrt[xx];
rhs = rhs //. Power[xx_, -0.5] -> INV[sqrt[xx]];
rhs = rhs //. SQR[x_] SQR[y_] -> SQR[x y];
rhs = rhs //. CUB[x_] CUB[y_] -> CUB[x y];
rhs = rhs //. QAD[x_] QAD[y_] -> QAD[x y];
rhs = rhs //. INV[x_] INV[y_] -> INV[x y];
rhs = rhs //. sqrt[x_] sqrt[y_] -> sqrt[x y];
rhs = rhs //. INV[sqrt[x_]] sqrt[y_] -> sqrt[INV[x] y] *);
rhs = expr;

(* Handle Piecewise function *)
rhs = rhs /. Piecewise -> piecewise1
Expand Down Expand Up @@ -278,9 +262,6 @@
rhs = rhs //. ArcSech[x_] -> acosh[1/x];
rhs = rhs //. ArcCsch[x_] -> asinh[1/x];
rhs = rhs //. ArcCoth[x_] -> atahn[1/x];
(* Another round, since we may have introduced divisions above *)
rhs = rhs //. 1 / x_ -> INV[x];
rhs = rhs //. INV[INV[x_]] -> x;

(* there have been some problems doing the Max/Min
replacement via the preprocessor for C, so we do it
Expand All @@ -305,10 +286,7 @@
{"INITVALUE (42)"} ~Join~
If[vectorise,
VectorisationMacros[],
{"INV(x) ((CCTK_REAL)1.0 / (x))",
"SQR(x) ((x) * (x))",
"CUB(x) ((x) * SQR(x))",
"QAD(x) (SQR(SQR(x)))"}]
{}]
]];


Expand Down
10 changes: 3 additions & 7 deletions Tools/CodeGen/Vectorisation.m
Expand Up @@ -38,13 +38,6 @@
Module[
{expr, vectoriseRules, scalarRules},
expr = exprp;

(* Remove SQR etc. *)
expr = expr //. {ToReal[x_] -> ToReal[x],
SQR[x_] -> x^2,
CUB[x_] -> x^3,
QAD[x_] -> x^4,
INV[x_] -> 1/x};

expr = expr //. Power[x_,y_] -> pow[x,y];

Expand Down Expand Up @@ -110,6 +103,9 @@
kmul[x_,kpow[y_,-1]] -> kdiv[x,y],
kmul[x_,kpow[y_,-2]] -> kdiv[x,kmul[y,y]],

kpow[x_,(1/2)|0.5] -> ksqrt[x],
kpow[x_,(-1/2)|(-0.5)] -> kdiv[ToReal[1],ksqrt[x]],

kneg[ToReal[a_]] -> ToReal[-a],
kmul[ToReal[-1],x_] -> kneg[x],
kmul[ToReal[-1.0],x_] -> kneg[x],
Expand Down

0 comments on commit bc9d2a5

Please sign in to comment.