diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2011-05-27 16:06:06 +0200 |
---|---|---|
committer | Ian Hinder <ian.hinder@aei.mpg.de> | 2011-05-27 16:15:06 +0200 |
commit | 431c5d7df8af4fcde2821987b69479ad6cdf1303 (patch) | |
tree | b3cf9c7b2994200463a8bfda34baae5639654d6d /Tools/CodeGen/CodeGen.m | |
parent | ce3f98a21a00360edd3e0714e283abb2b321448b (diff) |
Correct vectorisation errors recently introduced
(1) vec_load cannot be used on constants, it can only be used to
access array elements. Replacing UseVectors by False is just a band
aid. vec_load was attached to a routine defining and setting a
variable; really, it should be attached to a routine accessing array
elements, but Kranc doesn't use such an abstraction yet.(2) ToReal is
introduced, but must be removed again for integer expressions such as
the conditions controlling if statements. I added band-aid code to
Conditional[] to remove it. The vectorization routines already handle
IfThen, Pow etc., but Conditional isn't visible to them.
Diffstat (limited to 'Tools/CodeGen/CodeGen.m')
-rw-r--r-- | Tools/CodeGen/CodeGen.m | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/Tools/CodeGen/CodeGen.m b/Tools/CodeGen/CodeGen.m index fccdb41..5e8cd6a 100644 --- a/Tools/CodeGen/CodeGen.m +++ b/Tools/CodeGen/CodeGen.m @@ -774,12 +774,24 @@ BoundaryWithGhostsLoop[block_] := ]} ]]]}; +(* Remove call to ToReal from condtion. This should really instead be + done much earlier. Sometimes Conditional is called with a + conditional that is an expression, sometimes it is a list of + strings, so we need to handle both cases. *) +(* One approach to remove calls to ToReal is to wrap the condition + into a function call, such as e.g. Cond[x], which is then handled by + the vectorisation code in the same way the IfThen[x,y,z] expression + is handled there. *) +removeToRealFunc[condition_] := Replace[condition, {ToReal[x_] -> x}] +removeToRealString[condition_] := If[StringQ[condition], StringReplace[condition, "ToReal(" ~~ x__ ~~ ")" :> x], condition] +removeToReal[condition_] := Map[removeToRealString, removeToRealFunc[condition]] + Conditional[condition_, block_] := - {"if (", condition, ")\n", + {"if (", removeToReal[condition], ")\n", CBlock[block]}; Conditional[condition_, block1_, block2_] := - {"if (", condition, ")\n", + {"if (", removeToReal[condition], ")\n", CBlock[block1], "else\n", CBlock[block2]}; onceInGridLoop[block_] := |