Skip to content

Commit 6dbe393

Browse files
committed
use LLVM for ^^ if possible
1 parent 365c33c commit 6dbe393

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

source/mir/ndslice/internal.d

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,15 @@ struct RightOp(string op, T)
4949
this()(T v) { value = v; }
5050
auto ref opCall(F)(auto ref F right)
5151
{
52-
return mixin("value " ~ op ~ " right");
52+
static if (op == "^^" && isNumeric!T && isFloatingPoint!F)
53+
{
54+
import mir.math.common: pow;
55+
return pow(value, right);
56+
}
57+
else
58+
{
59+
return mixin("value " ~ op ~ " right");
60+
}
5361
}
5462
}
5563

@@ -73,7 +81,15 @@ struct LeftOp(string op, T)
7381
this()(T v) { value = v; }
7482
auto ref opCall(F)(auto ref F left)
7583
{
76-
return mixin("left " ~ op ~ " value");
84+
static if (op == "^^" && isFloatingPoint!T && isNumeric!F)
85+
{
86+
import mir.math.common: pow;
87+
return pow(left, value);
88+
}
89+
else
90+
{
91+
return mixin("left " ~ op ~ " value");
92+
}
7793
}
7894
}
7995

source/mir/ndslice/slice.d

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,15 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
21252125
else
21262126
{
21272127
static if (ls.N == 1)
2128-
mixin("ls.front " ~ op ~ "= value.front;");
2128+
{
2129+
static if (op == "^^" && isFloatingPoint!(typeof(ls.front)) && isFloatingPoint!(typeof(value.front)))
2130+
{
2131+
import mir.math.common: pow;
2132+
ls.front = pow(ls.front, value.front);
2133+
}
2134+
else
2135+
mixin("ls.front " ~ op ~ "= value.front;");
2136+
}
21292137
else
21302138
static if (rpacks == [1])
21312139
ls.front.opIndexOpAssignImplValue!op(value.front);
@@ -2217,7 +2225,15 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
22172225
do
22182226
{
22192227
static if (ls.N == 1)
2220-
mixin("ls.front " ~ op ~ "= value[0];");
2228+
{
2229+
static if (op == "^^" && isFloatingPoint!(typeof(ls.front)) && isFloatingPoint!(typeof(value[0])))
2230+
{
2231+
import mir.math.common: pow;
2232+
ls.front = pow(ls.front, value[0]);
2233+
}
2234+
else
2235+
mixin("ls.front " ~ op ~ "= value[0];");
2236+
}
22212237
else
22222238
mixin("ls.front[] " ~ op ~ "= value[0];");
22232239
value = value[1 .. $];
@@ -2449,7 +2465,14 @@ struct Slice(SliceKind kind, size_t[] packs, Iterator)
24492465
{
24502466
return mixin(`t` ~ op ~ `= v`);
24512467
}
2452-
return mixin (`_iterator[indexStride(_indexes)] ` ~ op ~ `= value`);
2468+
auto str = indexStride(_indexes);
2469+
static if (op == "^^" && isFloatingPoint!DeepElemType && isFloatingPoint!(typeof(value)))
2470+
{
2471+
import mir.math.common: pow;
2472+
_iterator[str] = pow(_iterator[str], value);
2473+
}
2474+
else
2475+
return mixin (`_iterator[str] ` ~ op ~ `= value`);
24532476
}
24542477

24552478
static if (doUnittest)

0 commit comments

Comments
 (0)