Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -957,8 +957,8 @@ yield new Rebuilt(new IfElse(n.cond(), a.node(), b.node()), false,
VarkaVectorIR.CrossLane _, VarkaVectorIR.NullValue _,
VarkaVectorIR.InRanges _, VarkaVectorIR.IntArith _, IntNeg _, VarkaVectorIR.ConstDivide _,
VarkaVectorIR.BoundedDivide _, VarkaVectorIR.BitOp _, VarkaVectorIR.BitCount _,
VarkaVectorIR.MathUnary _, VarkaVectorIR.RoundToIntegral _, VarkaVectorIR.CondValue _,
VarkaVectorIR.BoolOutput _, VarkaVectorIR.CanonicalFloat _,
VarkaVectorIR.MathUnary _, VarkaVectorIR.Fma _, VarkaVectorIR.RoundToIntegral _,
VarkaVectorIR.CondValue _, VarkaVectorIR.BoolOutput _, VarkaVectorIR.CanonicalFloat _,
VarkaVectorIR.CanonicalBits _, VarkaVectorIR.HashStep _ ->
new Rebuilt(node, false, false);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.Least;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.LiteralSlot;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.MathUnary;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.Fma;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.ReinterpretLane;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.RoundToIntegral;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.MakeDate;
Expand Down Expand Up @@ -1001,6 +1002,7 @@ void collectRefusals() {
case BitOp n -> { }
case BitCount n -> { }
case MathUnary n -> { }
case Fma n -> { }
case RoundToIntegral n -> { }
case CanonicalFloat n -> { }
case CanonicalBits n -> { }
Expand Down Expand Up @@ -1101,8 +1103,8 @@ private boolean isNarrowRing(VarkaVectorIR node) {
TruncDateDynamic _, DateDiff _, Greatest _, Least _, DayOfWeek _,
WeekDay _, DayOfWeekIso _, ThursdayOf _, Year _, Month _, DayOfMonth _, Quarter _,
DayOfYear _, LastDay _, TruncDate _, WeekOfYear _, ConstDivide _, BoundedDivide _,
BitOp _, BitCount _, MathUnary _, RoundToIntegral _, Compare _, NullSafeEqual _,
BoolColumn _, CanonicalFloat _, CanonicalBits _, HashStep _,
BitOp _, BitCount _, MathUnary _, Fma _, RoundToIntegral _, Compare _,
NullSafeEqual _, BoolColumn _, CanonicalFloat _, CanonicalBits _, HashStep _,
BoolCompare _,
CondIf _, BoolNullSafeEq _, CondConst _, And _, Or _, Not _, CrossLane _, IsNotNull _,
InRanges _, CondValue _, NullValue _, BoolOutput _ -> false;
Expand Down Expand Up @@ -1451,6 +1453,7 @@ private WordOwner ownerOf(VarkaVectorIR node) {
case BitOp n -> andOwner(node, n.left(), n.right());
case BitCount n -> wordOwner.get(n.child());
case MathUnary n -> wordOwner.get(n.child());
case Fma n -> andOwner(node, andOwner(node, n.a(), n.b()), wordOwner.get(n.c()));
case RoundToIntegral n -> wordOwner.get(n.child());
case CanonicalFloat n -> wordOwner.get(n.child());
case CanonicalBits n -> wordOwner.get(n.child());
Expand Down Expand Up @@ -1484,8 +1487,14 @@ private WordOwner ownerOf(VarkaVectorIR node) {

/** {@code Slots.andRef}'s folding over owners: all-true drops out, equal operands collapse. */
private WordOwner andOwner(VarkaVectorIR node, VarkaVectorIR a, VarkaVectorIR b) {
WordOwner wa = wordOwner.get(a);
WordOwner wb = wordOwner.get(b);
return andOwner(node, wordOwner.get(a), wordOwner.get(b));
}

/**
* The fold over two owners; a three-operand node folds its first two and then the third, as
* {@code Slots.andRef} folds the refs, the node's own word standing for an AND not folded.
*/
private static WordOwner andOwner(VarkaVectorIR node, WordOwner wa, WordOwner wb) {
if (wa == WordOwner.Const.ALL_TRUE) {
return wb;
}
Expand Down Expand Up @@ -1521,6 +1530,8 @@ private WordExpr pureOf(VarkaVectorIR node) {
case BitOp n -> andExpr(pureWord.get(n.left()), pureWord.get(n.right()));
case BitCount n -> pureWord.get(n.child());
case MathUnary n -> pureWord.get(n.child());
case Fma n -> andExpr(andExpr(pureWord.get(n.a()), pureWord.get(n.b())),
pureWord.get(n.c()));
case RoundToIntegral n -> pureWord.get(n.child());
case CanonicalFloat n -> pureWord.get(n.child());
case CanonicalBits n -> pureWord.get(n.child());
Expand Down Expand Up @@ -1823,6 +1834,8 @@ private void analyze(VarkaVectorIR node) {
case BitCount n -> analyzeOp(node, false, n.child());
// A floating math function computes every lane and nulls none.
case MathUnary n -> analyzeOp(node, false, n.child());
// So does the fused multiply-add, over its three operands.
case Fma n -> analyzeOp(node, false, n.a(), n.b(), n.c());
case RoundToIntegral n -> analyzeOp(node, false, n.child());
case CanonicalFloat n -> analyzeOp(node, false, n.child());
case CanonicalBits n -> analyzeOp(node, false, n.child());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.Least;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.LiteralSlot;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.MathUnary;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.Fma;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.ReinterpretLane;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.RoundToIntegral;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.MakeDate;
Expand Down Expand Up @@ -1225,6 +1226,9 @@ private static int planWordRef(VarkaVectorIR node, Slots s) {
case BitOp n -> andRef(s.wordRef.get(n.left()), s.wordRef.get(n.right()));
case BitCount n -> s.wordRef.get(n.child());
case MathUnary n -> s.wordRef.get(n.child());
// The three operands' AND, folded as Analysis.ownerOf folds their owners.
case Fma n -> andRef(andRef(s.wordRef.get(n.a()), s.wordRef.get(n.b())),
s.wordRef.get(n.c()));
case RoundToIntegral n -> s.wordRef.get(n.child());
case CanonicalFloat n -> s.wordRef.get(n.child());
case CanonicalBits n -> s.wordRef.get(n.child());
Expand Down Expand Up @@ -1748,6 +1752,7 @@ private void visit(VarkaVectorIR n) {
case BitOp x -> { }
case BitCount x -> { }
case MathUnary x -> { }
case Fma x -> { }
case RoundToIntegral x -> { }
case CanonicalFloat x -> { }
case CanonicalBits x -> { }
Expand Down Expand Up @@ -1838,6 +1843,9 @@ private void propagate(VarkaVectorIR n) {
demand(analysis.wordOwner.get(x.right())); }
case BitCount x -> { }
case MathUnary x -> { }
case Fma x -> { demand(analysis.wordOwner.get(x.a()));
demand(analysis.wordOwner.get(x.b()));
demand(analysis.wordOwner.get(x.c())); }
case RoundToIntegral x -> { }
case CanonicalFloat x -> { }
case CanonicalBits x -> { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,8 @@ static int weightOf(VarkaVectorIR node) {
// most eight double lanes at 512 bits, the larger form as above; the scalar calls between
// them are no vector op.
case VarkaVectorIR.MathUnary n -> n.fn().laneCall() ? 16 : 1;
// The lanewise fused multiply-add: one call.
case VarkaVectorIR.Fma _ -> 1;
// The rint construction: the absolute value, the add and subtract of 2^52, the sign's AND
// and OR, the compare against 2^52 and the blend, and three reinterpretations, which the
// budget counts as calls though they emit no instruction; then the NaN's compare and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static String kindOf(VarkaVectorIR node) {
case BitOp n -> name + '/' + n.op() + '/' + n.laneType();
case BitCount n -> name + '/' + n.laneType();
case VarkaVectorIR.MathUnary n -> name + '/' + n.fn() + '/' + n.laneType();
case VarkaVectorIR.Fma n -> name + '/' + n.laneType();
case VarkaVectorIR.RoundToIntegral n -> name + '/' + n.mode() + '/' + n.laneType();
case VarkaVectorIR.CanonicalFloat n -> name + '/' + n.laneType();
case VarkaVectorIR.CanonicalBits n -> name + '/' + n.laneType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,9 @@ static LongNarrowRole longNarrowRole(VarkaVectorIR node) {
WidenLane _, VarkaVectorIR.AddDays _, VarkaVectorIR.SubDays _,
VarkaVectorIR.DateDiff _, IntArith _, VarkaVectorIR.IntNeg _,
VarkaVectorIR.ConstDivide _, VarkaVectorIR.BoundedDivide _, VarkaVectorIR.BitOp _,
VarkaVectorIR.BitCount _, VarkaVectorIR.MathUnary _, VarkaVectorIR.RoundToIntegral _,
VarkaVectorIR.CanonicalFloat _, VarkaVectorIR.CanonicalBits _,
VarkaVectorIR.HashStep _, VarkaVectorIR.IfElse _,
VarkaVectorIR.BitCount _, VarkaVectorIR.MathUnary _, VarkaVectorIR.Fma _,
VarkaVectorIR.RoundToIntegral _, VarkaVectorIR.CanonicalFloat _,
VarkaVectorIR.CanonicalBits _, VarkaVectorIR.HashStep _, VarkaVectorIR.IfElse _,
VarkaVectorIR.CondValue _, VarkaVectorIR.Greatest _, VarkaVectorIR.Least _,
VarkaVectorIR.DayOfWeek _, VarkaVectorIR.WeekDay _, VarkaVectorIR.DayOfWeekIso _,
VarkaVectorIR.NextDay _, VarkaVectorIR.ThursdayOf _, VarkaVectorIR.AddMonths _,
Expand Down Expand Up @@ -875,8 +875,8 @@ private static LongNarrowReader longNarrowReader(VarkaVectorIR node) {
VarkaVectorIR.AddDays _, VarkaVectorIR.SubDays _, VarkaVectorIR.DateDiff _,
IntArith _, VarkaVectorIR.IntNeg _, VarkaVectorIR.ConstDivide _,
VarkaVectorIR.BoundedDivide _, VarkaVectorIR.BitOp _, VarkaVectorIR.BitCount _,
VarkaVectorIR.MathUnary _, VarkaVectorIR.RoundToIntegral _, VarkaVectorIR.IfElse _,
VarkaVectorIR.CanonicalFloat _, VarkaVectorIR.CanonicalBits _,
VarkaVectorIR.MathUnary _, VarkaVectorIR.Fma _, VarkaVectorIR.RoundToIntegral _,
VarkaVectorIR.IfElse _, VarkaVectorIR.CanonicalFloat _, VarkaVectorIR.CanonicalBits _,
VarkaVectorIR.HashStep _, VarkaVectorIR.CondValue _,
VarkaVectorIR.Greatest _,
VarkaVectorIR.Least _, VarkaVectorIR.DayOfWeek _, VarkaVectorIR.WeekDay _,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public boolean admits(VarkaVectorIR node) {
};
case AddDays _, SubDays _, DateDiff _, IfElse _, Greatest _, Least _, DayOfWeek _,
WeekDay _, DayOfWeekIso _, NextDay _, ThursdayOf _, AddMonths _, MakeDate _,
ConstDivide _, BoundedDivide _, BitOp _, BitCount _, MathUnary _, RoundToIntegral _,
CanonicalFloat _, CanonicalBits _, HashStep _, GuardedDay _,
ConstDivide _, BoundedDivide _, BitOp _, BitCount _, MathUnary _, Fma _,
RoundToIntegral _, CanonicalFloat _, CanonicalBits _, HashStep _, GuardedDay _,
GuardedRange _,
ConvertLane _, ReinterpretLane _,
WidenDecimal _, Year _, Month _, DayOfMonth _, Quarter _, DayOfYear _,
Expand Down Expand Up @@ -146,8 +146,8 @@ public static List<Restricted> restrictedOperands(VarkaVectorIR node) {
Greatest _, Least _,
DayOfWeek _,
WeekDay _, DayOfWeekIso _, ThursdayOf _, MakeDate _, IntArith _, IntNeg _,
ConstDivide _, BoundedDivide _, BitOp _, BitCount _, MathUnary _, RoundToIntegral _,
CanonicalFloat _, CanonicalBits _, HashStep _, GuardedDay _,
ConstDivide _, BoundedDivide _, BitOp _, BitCount _, MathUnary _, Fma _,
RoundToIntegral _, CanonicalFloat _, CanonicalBits _, HashStep _, GuardedDay _,
GuardedRange _,
WidenLane _, ConvertLane _, ReinterpretLane _,
NarrowLane _, WidenDecimal _, Year _, Month _, DayOfMonth _, Quarter _, DayOfYear _,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.Least;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.LiteralSlot;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.MathUnary;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.Fma;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.ReinterpretLane;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.RoundToIntegral;
import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.MakeDate;
Expand Down Expand Up @@ -398,6 +399,7 @@ public static Range range(VarkaVectorIR node, Kind kind, GuardPolicy policy,
? VarkaValueRange.UNKNOWN : VarkaValueRange.of(0, Long.SIZE);
// A floating value has no integer range.
case MathUnary n -> VarkaValueRange.UNKNOWN;
case Fma n -> VarkaValueRange.UNKNOWN;
case RoundToIntegral n -> VarkaValueRange.UNKNOWN;
case CanonicalFloat n -> VarkaValueRange.UNKNOWN;
// The bits of a float and a hash step span their whole lanes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ record Other<N>(List<N> children) implements Step<N> {}
* over an open operand.
*/
record Canonical<N>() implements Step<N> {}

/**
* A node whose NaN no tier fixes, over any operands: an FMA, which {@code Math.fma} run in
* Java answers with the canonical NaN, and the instruction by its own rule, an operand's NaN
* or the host's default one ({@code VarkaVectorIR.Fma}). Every NaN of the node is open.
*/
record Unfixed<N>() implements Step<N> {}
}

/** One tree's view of a node on one row, all the rule reads. */
Expand All @@ -178,8 +185,9 @@ private interface Front<N> {
* greatest} or {@code least} its first child whose value is a NaN (Spark's fold keeps the first
* of equal values, and every NaN compares equal to every other). A {@code rint}
* ({@code RoundToIntegral} over the IR, Spark's {@code Rint} over an expression) is never
* open, whatever its operand, since it answers the canonical NaN for every NaN. Any other node
* is open where a floating child whose value is a NaN is.
* open, whatever its operand, since it answers the canonical NaN for every NaN. An FMA
* ({@code Fma} over the IR, no Catalyst expression being one) is open wherever it answers a
* NaN. Any other node is open where a floating child whose value is a NaN is.
*
* <p>The rule reads no payload it decides is open. Which values are NaNs is the same on every
* tier, and an arithmetic compares its operands' bits only once neither is open, when each is
Expand All @@ -202,6 +210,7 @@ private static <N> boolean open(N node, Front<N> front) {
yield l != null ? open(a.left(), front) : r != null && open(a.right(), front);
}
case Step.Canonical<N> _ -> false;
case Step.Unfixed<N> _ -> true;
case Step.Pass<N> p -> open(p.child(), front);
case Step.Pick<N> p ->
p.taken() != null && front.nanBits(p.taken()) != null && open(p.taken(), front);
Expand Down Expand Up @@ -265,6 +274,7 @@ public static boolean openNaN(VarkaVectorIR node, IrRow row) {
a.op() == VarkaVectorIR.IntOp.ADD || a.op() == VarkaVectorIR.IntOp.MUL);
case VarkaVectorIR.RoundToIntegral _ -> new Step.Canonical<>();
case VarkaVectorIR.CanonicalFloat _ -> new Step.Canonical<>();
case VarkaVectorIR.Fma _ -> new Step.Unfixed<>();
case VarkaVectorIR.IfElse i ->
new Step.Pick<>(row.holds(i.cond()) ? i.thenNode() : i.elseNode());
case VarkaVectorIR.Greatest g -> new Step.FirstNaN<>(List.of(g.left(), g.right()));
Expand Down
Loading