Skip to content

Commit

Permalink
use LLVM for ^^ if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
9il committed Feb 20, 2018
1 parent 365c33c commit 6dbe393
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
20 changes: 18 additions & 2 deletions source/mir/ndslice/internal.d
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,15 @@ struct RightOp(string op, T)
this()(T v) { value = v; }
auto ref opCall(F)(auto ref F right)
{
return mixin("value " ~ op ~ " right");
static if (op == "^^" && isNumeric!T && isFloatingPoint!F)
{
import mir.math.common: pow;
return pow(value, right);
}
else
{
return mixin("value " ~ op ~ " right");
}
}
}

Expand All @@ -73,7 +81,15 @@ struct LeftOp(string op, T)
this()(T v) { value = v; }
auto ref opCall(F)(auto ref F left)
{
return mixin("left " ~ op ~ " value");
static if (op == "^^" && isFloatingPoint!T && isNumeric!F)
{
import mir.math.common: pow;
return pow(left, value);
}
else
{
return mixin("left " ~ op ~ " value");
}
}
}

Expand Down
29 changes: 26 additions & 3 deletions source/mir/ndslice/slice.d
Original file line number Diff line number Diff line change
Expand Up @@ -2125,7 +2125,15 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
else
{
static if (ls.N == 1)
mixin("ls.front " ~ op ~ "= value.front;");
{
static if (op == "^^" && isFloatingPoint!(typeof(ls.front)) && isFloatingPoint!(typeof(value.front)))
{
import mir.math.common: pow;
ls.front = pow(ls.front, value.front);
}
else
mixin("ls.front " ~ op ~ "= value.front;");
}
else
static if (rpacks == [1])
ls.front.opIndexOpAssignImplValue!op(value.front);
Expand Down Expand Up @@ -2217,7 +2225,15 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
do
{
static if (ls.N == 1)
mixin("ls.front " ~ op ~ "= value[0];");
{
static if (op == "^^" && isFloatingPoint!(typeof(ls.front)) && isFloatingPoint!(typeof(value[0])))
{
import mir.math.common: pow;
ls.front = pow(ls.front, value[0]);
}
else
mixin("ls.front " ~ op ~ "= value[0];");
}
else
mixin("ls.front[] " ~ op ~ "= value[0];");
value = value[1 .. $];
Expand Down Expand Up @@ -2449,7 +2465,14 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
{
return mixin(`t` ~ op ~ `= v`);
}
return mixin (`_iterator[indexStride(_indexes)] ` ~ op ~ `= value`);
auto str = indexStride(_indexes);
static if (op == "^^" && isFloatingPoint!DeepElemType && isFloatingPoint!(typeof(value)))
{
import mir.math.common: pow;
_iterator[str] = pow(_iterator[str], value);
}
else
return mixin (`_iterator[str] ` ~ op ~ `= value`);
}

static if (doUnittest)
Expand Down

0 comments on commit 6dbe393

Please sign in to comment.