From 500a049720ef6dd43ad16f6697b682568e10c755 Mon Sep 17 00:00:00 2001 From: t Date: Fri, 20 Nov 2026 10:44:30 +0100 Subject: [PATCH 1/6] [VARKA-345] Emit fdlibm's expm1 as IR nodes in the kernel, exact to StrictMath The PORT form's second function on 345b's frame: s_expm1.c's seven forms and early returns computed in every lane and blended, node for node vfdlibm's Expm1.expm1Blended, with the C's int words in long lanes. The reduction is shared with exp. VarkaMathPortSuite runs its tests over the list of ported functions, so expm1 gets the sampled differential, the fixed vectors, the reference evaluator, the depth caps and the planted faults. Generated-by: Claude Code (Claude Opus 5.5) --- .../codegen/varka/VarkaMathPort.java | 202 +++++++++++- .../codegen/varka/VarkaMathPortSuite.java | 309 ++++++++++++------ sql/varka/plans/m8/PLAN.md | 2 +- sql/varka/plans/m8/VARKA-345.md | 46 +++ 4 files changed, 437 insertions(+), 122 deletions(-) diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java index a855d762dceb..865d7897e17f 100644 --- a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java +++ b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java @@ -17,7 +17,8 @@ package org.apache.spark.sql.catalyst.expressions.codegen.varka; /* - * The exp expansion below follows fdlibm 5.3's e_exp.c, which carries this notice: + * The exp and expm1 expansions below follow fdlibm 5.3's e_exp.c and s_expm1.c, which carry + * this notice: * * ==================================================== * Copyright (C) 2004 by Sun Microsystems, Inc. All rights reserved. @@ -71,6 +72,7 @@ * *

{@link #exp} is the template: the sequence {@code vfdlibm} proves for {@code StrictMath.exp}, * its arm with every branch blended ({@code Exp.expBlended}), so no lane is finished by a call. + * {@link #expm1} follows it, on the same reduction, from {@code Expm1.expm1Blended}. */ public final class VarkaMathPort { @@ -108,9 +110,9 @@ public long[] values() { /** * A fault an expansion can be built with, for the cross-checks to catch: {@code vfdlibm}'s own - * planted faults ({@code Exp.DROP_CORRECTION}, {@code CONSTANT_OFF_BY_ONE_ULP}, - * {@code THRESHOLD_MOVED}), here as arguments of a package-private overload, so the production - * expansion has none. + * planted faults of each function ({@code Exp.DROP_CORRECTION}, {@code CONSTANT_OFF_BY_ONE_ULP}, + * {@code THRESHOLD_MOVED}, and {@code Expm1}'s of the same names), here as arguments of a + * package-private overload, so the production expansion has none. */ enum Fault { NONE, DROP_CORRECTION, CONSTANT_OFF_BY_ONE_ULP, THRESHOLD_MOVED } @@ -277,6 +279,42 @@ VarkaVectorIR addExponent(VarkaVectorIR y, VarkaVectorIR k) { return fromBits(add(bits(y), new BitOp(BitOpKind.SHL, k, lit(52L)))); } + // ------------------------------------------------------------------------------------------- + // The reduction e_exp.c and s_expm1.c share + // ------------------------------------------------------------------------------------------- + + /** + * {@code x = k*ln2 + r}, {@code r = hi - lo}: {@code k} at the long lane, {@code t} its double, + * and {@code hi}, {@code lo} and {@code r} at the double lane. + */ + record Reduction(VarkaVectorIR k, VarkaVectorIR t, VarkaVectorIR hi, VarkaVectorIR lo, + VarkaVectorIR r) {} + + /** + * The far form of the reduction for every lane, as e_exp.c's lines 128-142 and s_expm1.c's + * lines 162-175 both write it: {@code k = (int)(invln2*x + (xsb==0 ? 0.5 : -0.5))}, + * {@code t = k}, {@code hi = x - t*ln2_hi}, {@code lo = t*ln2_lo}. A lane whose {@code |x|} is + * not above {@code 0.5 ln2} gets {@code k = 0} from the blend before the cast, so + * {@code t = +0}, {@code hi = x} and {@code lo = +0} ({@code vfdlibm}'s L1); the near band takes + * the far form's values exactly (L2, L10); and {@code (xsb==0 ? 0.5 : -0.5)} is 0.5 with + * {@code x}'s sign bit (L5). {@code D2I} truncates toward zero as the C's {@code (int)} does; a + * NaN or a huge {@code |x|} is a lane the filter answers, whose {@code k} is never kept. + * {@code k} passes through the int lane as the C's {@code int k} does, {@code D2I} then + * {@code I2D} and {@code I2L}: x86 lowers {@code D2L} only with AVX512DQ. + */ + Reduction reduce(VarkaVectorIR x, VarkaVectorIR bits, VarkaVectorIR absBits, double ln2hi) { + Cond reduced = hiAbove(absBits, HX_HALF_LN2); + VarkaVectorIR halF = fromBits(new BitOp(BitOpKind.OR, + new BitOp(BitOpKind.AND, bits, lit(Long.MIN_VALUE)), lit(HALF_BITS))); + VarkaVectorIR kArg = blend(reduced, add(mul(x, lit(INVLN2)), halF), lit(0.0)); + VarkaVectorIR kInt = new ConvertLane(kArg, LaneType.INT); + VarkaVectorIR t = new ConvertLane(kInt, LaneType.DOUBLE); + VarkaVectorIR k = new WidenLane(kInt, LaneType.LONG); + VarkaVectorIR hi = sub(x, mul(t, lit(ln2hi))); + VarkaVectorIR lo = mul(t, lit(LN2LO_0)); + return new Reduction(k, t, hi, lo, sub(hi, lo)); + } + // ------------------------------------------------------------------------------------------- // exp, from e_exp.c // ------------------------------------------------------------------------------------------- @@ -348,24 +386,16 @@ VarkaVectorIR exp(VarkaVectorIR x, Fault fault) { // Lines 117, 118, 128 and 139: the filter, the reduced lanes, the tiny ones and the // non-finite ones; the near band, line 129, needs no test (L2). Cond filter = hiAtLeast(absBits, HX_FILTER); - Cond reduced = hiAbove(absBits, HX_HALF_LN2); Cond isTiny = hiBelow(absBits, HX_TINY); Cond nonFinite = hiAtLeast(absBits, HX_NON_FINITE); - // halF[xsb]: 0.5 with x's sign bit. - VarkaVectorIR halF = fromBits(new BitOp(BitOpKind.OR, - new BitOp(BitOpKind.AND, bits, lit(Long.MIN_VALUE)), lit(HALF_BITS))); // Lines 128-142 in the far form for every lane: k = (int)(invln2*x+halF[xsb]); t = k; - // hi = x - t*ln2HI[0]; lo = t*ln2LO[0]. A lane that is not reduced gets k = 0 from the blend - // before the cast, so t = +0, hi = x, lo = +0 (L1). D2I truncates toward zero as the C's - // (int) does; a NaN or a huge |x| is a filter lane, whose k is never used. - VarkaVectorIR kArg = blend(reduced, add(mul(x, lit(INVLN2)), halF), lit(0.0)); - VarkaVectorIR kInt = new ConvertLane(kArg, LaneType.INT); - VarkaVectorIR t = new ConvertLane(kInt, LaneType.DOUBLE); - VarkaVectorIR k = new WidenLane(kInt, LaneType.LONG); - VarkaVectorIR hi = sub(x, mul(t, lit(ln2hi))); - VarkaVectorIR lo = mul(t, lit(LN2LO_0)); - VarkaVectorIR r = sub(hi, lo); + // hi = x - t*ln2HI[0]; lo = t*ln2LO[0]. + Reduction red = reduce(x, bits, absBits, ln2hi); + VarkaVectorIR k = red.k(); + VarkaVectorIR hi = red.hi(); + VarkaVectorIR lo = red.lo(); + VarkaVectorIR r = red.r(); // Lines 145-146: t = x*x; c = x - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))). VarkaVectorIR tt = mul(r, r); @@ -398,4 +428,140 @@ VarkaVectorIR exp(VarkaVectorIR x, Fault fault) { blend(new Compare(CompareOp.LT, bits, lit(0L)), lit(0.0), x)); return blend(nonFinite, special, result); } + + // ------------------------------------------------------------------------------------------- + // expm1, from s_expm1.c + // ------------------------------------------------------------------------------------------- + + // The constants of s_expm1.c, lines 115-127, that e_exp.c does not share; its o_threshold, + // ln2_hi, ln2_lo and invln2 are e_exp.c's O_THRESHOLD, LN2HI_0, LN2LO_0 and INVLN2. + static final double HUGE = 1.0e+300; + static final double TINY = 1.0e-300; + static final double Q1 = -3.33333333333331316428e-02; // BFA11111 111110F4 + static final double Q2 = 1.58730158725481460165e-03; // 3F5A01A0 19FE5585 + static final double Q3 = -7.93650757867487942473e-05; // BF14CE19 9EAADBB7 + static final double Q4 = 4.00821782732936239552e-06; // 3ED0CFCA 86E65239 + static final double Q5 = -2.01099218183624371326e-07; // BE8AFDB7 6E09C32D + + /** {@code |x| >= 56*ln2}: the filter's outer test (line 146). */ + static final int HX_56_LN2 = 0x4043687A; + /** {@code |x| < 2^-54}: the lanes whose result is {@code x} (line 177). */ + static final int HX_TINY_EXPM1 = 0x3c900000; + /** {@code k > 56}: with {@code k <= -2}, the form that returns {@code 2^k*y - 1} (line 197). */ + static final long K_FAR = 56; + /** {@code k < 20}: the form with {@code t = 1-2^-k}; from it on, {@code t = 2^-k} (line 203). */ + static final long K_SPLIT = 20; + /** {@code __HI(1.0)}, the high word of {@code t} on the lanes neither form rewrites. */ + static final long ONE_HI = 0x3ff00000L; + + /** {@code StrictMath.expm1(x)} in every lane of the double node {@code x}, bit for bit. */ + public VarkaVectorIR expm1(VarkaVectorIR x) { + return expm1(x, Fault.NONE); + } + + /** + * The expansion, node for node {@code vfdlibm}'s {@code Expm1.expm1Blended}, with its line + * references to s_expm1.c and its lemmas in {@code vfdlibm}'s {@code PROOFS.md}: the reduction is + * exp's ({@link #reduce}, L10), the {@code k == 0} return {@code x - (x*e-hxs)} is the other + * forms' {@code x - e} with {@code c = +0} on those lanes (L11), the seven forms chosen by + * {@code k} are computed in every lane and blended in the C's order, and the early returns, the + * filter and {@code |x| < 2^-54}, are blended over them last. + * + *

The library holds the C's {@code int} words in int lanes; here they are long lanes, as in + * {@link #exp}: the high-word tests are signed compares of {@code |x|}'s bits (L3), {@code k}'s + * tests are long compares of {@code k} widened, and the words {@code 0x3ff00000-(0x200000>>k)} + * and {@code (0x3ff-k)<<20} are long arithmetic, shifted by {@code k} lane by lane. On a lane + * whose form reads a word the two agree: {@code 2 <= k < 20} keeps {@code 0x200000>>k} positive, + * so the unsigned shift written here is the C's signed one, and {@code 20 <= k <= 56} keeps + * {@code (0x3ff-k)<<20} in {@code [0, 2^31)}; {@code __HI(t) = w} on a zero low word is + * {@code w << 32}, whose bits above the word shift out. A word on a lane that does not read it + * is never kept, whatever the shift count there. + * + *

A null {@code x} answers null as {@code exp}'s does: the reduction's blend makes {@code k} + * a valid 0 there, so each test of {@code k} is known and the {@code k == 0} blend takes + * {@code x - e}, which reads {@code x}; every other condition reads {@code x}, is unknown, and + * takes its {@code otherwise} arm. + */ + VarkaVectorIR expm1(VarkaVectorIR x, Fault fault) { + if (x.laneType() != LaneType.DOUBLE) { + throw VarkaErrors.illegalArgument("expm1 takes a DOUBLE operand, not " + x.laneType()); + } + double ln2hi = fault == Fault.CONSTANT_OFF_BY_ONE_ULP + ? Math.nextUp(LN2HI_0) : LN2HI_0; + long kFar = fault == Fault.THRESHOLD_MOVED ? K_FAR - 1 : K_FAR; + VarkaVectorIR bits = bits(x); + // Lines 140-143: hx = __HI(x); xsb = hx&0x80000000; hx &= 0x7fffffff. + VarkaVectorIR absBits = absBits(bits); + Cond negative = new Compare(CompareOp.LT, bits, lit(0L)); + // Lines 146, 147, 148 and 177; line 162's test is the reduction's, and line 163's near band + // needs no test of its own (L10). + Cond big = hiAtLeast(absBits, HX_56_LN2); + Cond filter = hiAtLeast(absBits, HX_FILTER); + Cond nonFinite = hiAtLeast(absBits, HX_NON_FINITE); + Cond isTiny = hiBelow(absBits, HX_TINY_EXPM1); + + // Lines 162-175: the reduction, then x = hi - lo (here r) and c = (hi-x)-lo. + Reduction red = reduce(x, bits, absBits, ln2hi); + VarkaVectorIR k = red.k(); + VarkaVectorIR r = red.r(); + VarkaVectorIR c = fault == Fault.DROP_CORRECTION + ? lit(0.0) : sub(sub(red.hi(), r), red.lo()); + + // Lines 184-188: hfx = 0.5*x; hxs = x*hfx; r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs* + // Q5)))); t = 3.0-r1*hfx; e = hxs*((r1-t)/(6.0 - x*t)), each product with the library's + // operand order, the same rounding of the same exact product. + VarkaVectorIR hfx = mul(r, lit(0.5)); + VarkaVectorIR hxs = mul(r, hfx); + VarkaVectorIR r1 = add(lit(ONE), mul(add(mul(add(mul(add(mul(add(mul(hxs, lit(Q5)), + lit(Q4)), hxs), lit(Q3)), hxs), lit(Q2)), hxs), lit(Q1)), hxs)); + VarkaVectorIR tt = sub(lit(3.0), mul(r1, hfx)); + VarkaVectorIR e = mul(hxs, div(sub(r1, tt), sub(lit(6.0), mul(r, tt)))); + // Lines 191-192: e = (x*(e-c)-c); e -= hxs; and x - e, line 189's return on k == 0 (L11). + VarkaVectorIR em = sub(sub(mul(r, sub(e, c)), c), hxs); + VarkaVectorIR rMinusE = sub(r, em); + + // The masks of k. Line 197: k <= -2 || k > 56. Line 203: k < 20, among the rest of k >= 2. + Cond far = new VarkaVectorIR.Or(new Compare(CompareOp.LE, k, lit(-2L)), + new Compare(CompareOp.GT, k, lit(kFar))); + Cond mid = new VarkaVectorIR.And(new Compare(CompareOp.GE, k, lit(2L)), + new Compare(CompareOp.LT, k, lit(K_SPLIT))); + Cond high = new VarkaVectorIR.And(new Compare(CompareOp.GE, k, lit(K_SPLIT)), new Not(far)); + // Lines 202-208: __HI(t) = 0x3ff00000 - (0x200000>>k) below k = 20, (0x3ff-k)<<20 from it + // on, and one's high word on the far lanes; t's low word is one's, 0. + VarkaVectorIR midWord = sub(lit(ONE_HI), new BitOp(BitOpKind.USHR, lit(0x200000L), k)); + VarkaVectorIR highWord = new BitOp(BitOpKind.SHL, sub(lit(0x3ffL), k), lit(20L)); + VarkaVectorIR tWord = blend(high, highWord, blend(mid, midWord, lit(ONE_HI))); + VarkaVectorIR tv = fromBits(new BitOp(BitOpKind.SHL, tWord, lit(32L))); + // Line 198, y = one-(e-x), and line 205, y = t-(e-x): one operation, t's word picked per + // lane. Lines 209-210: y = x-(e+t); y += one. + VarkaVectorIR y = blend(high, add(sub(r, add(em, tv)), lit(ONE)), sub(tv, sub(em, r))); + // Lines 199, 206 and 211: __HI(y) += (k<<20); line 200: the far lanes return y-one. + VarkaVectorIR scaled = addExponent(y, k); + VarkaVectorIR result = blend(far, sub(scaled, lit(ONE)), scaled); + // Lines 194-196, k == 1: -2.0*(e-(x+0.5)) for x < -0.25, else one+2.0*(x-e). + VarkaVectorIR kOne = blend(new Compare(CompareOp.IEEE_LT, r, lit(-0.25)), + mul(sub(em, add(r, lit(0.5))), lit(-2.0)), add(mul(rMinusE, lit(2.0)), lit(ONE))); + result = blend(new Compare(CompareOp.EQ, k, lit(1L)), kOne, result); + // Line 193, k == -1: 0.5*(x-e)-0.5. + result = blend(new Compare(CompareOp.EQ, k, lit(-1L)), + sub(mul(rMinusE, lit(0.5)), lit(0.5)), result); + // Line 189, k == 0: x - (x*e-hxs), here x-e (L11). + result = blend(new Compare(CompareOp.EQ, k, lit(0L)), rMinusE, result); + + // The early returns, lines 146-158 and 177-179, a later blend winning where two overlap, as + // the C's earlier return does. Lines 155-157: x < -56*ln2 returns tiny-one (-1.0) where + // x+tiny < 0.0, which every such finite x is. + result = blend(new VarkaVectorIR.And(at(new VarkaVectorIR.And(negative, big), + LaneType.DOUBLE), new Compare(CompareOp.IEEE_LT, add(x, lit(TINY)), lit(0.0))), + lit(TINY - ONE), result); + // Line 153: x > o_threshold returns huge*huge, +inf. + result = blend(new VarkaVectorIR.And(at(filter, LaneType.DOUBLE), + new Compare(CompareOp.IEEE_LT, lit(O_THRESHOLD), x)), lit(HUGE * HUGE), result); + // Lines 148-151: x+x for a NaN, x for +inf and -1.0 for -inf. + Cond isNaN = new Not(new Compare(CompareOp.IEEE_EQ, x, x)); + result = blend(nonFinite, blend(isNaN, add(x, x), blend(negative, lit(-1.0), x)), result); + // Lines 177-179, |x| < 2^-54: t = huge+x; return x - (t-(huge+x)). + VarkaVectorIR tinyT = add(x, lit(HUGE)); + return blend(isTiny, sub(x, sub(tinyT, add(x, lit(HUGE)))), result); + } } diff --git a/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java b/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java index 4ffee0ddf991..2b8d1654ab76 100644 --- a/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java +++ b/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java @@ -24,18 +24,23 @@ import java.lang.foreign.Arena; import java.lang.foreign.ValueLayout; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.SplittableRandom; +import java.util.function.BiFunction; +import java.util.function.DoubleUnaryOperator; import java.util.function.Function; import java.util.function.IntPredicate; import java.util.function.LongBinaryOperator; +import java.util.function.UnaryOperator; import io.github.vecbricks.vfdlibm.VFdlibm; import jdk.incubator.vector.DoubleVector; +import jdk.incubator.vector.VectorMask; import jdk.incubator.vector.VectorSpecies; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -47,17 +52,18 @@ import org.apache.spark.sql.catalyst.expressions.codegen.varka.VarkaVectorIR.LaneType; /** - * The {@code PORT} form's frame and its template (`VARKA-345.md` 2.2, 2.3, 3.2): the word helpers - * of {@link VarkaMathPort} against their definitions on the raw bits, and {@code exp}'s expansion, - * emitted as a kernel, against {@code StrictMath.exp} and against the vector fdlibm library's - * {@code VFdlibm.exp} on the same inputs, bit for bit. + * The {@code PORT} form's frame and its ports (`VARKA-345.md` 2.2, 2.3, 3.2): the word helpers + * of {@link VarkaMathPort} against their definitions on the raw bits, and each port's expansion, + * {@code exp}'s and {@code expm1}'s, emitted as a kernel, against its {@code StrictMath} method and + * against the vector fdlibm library's {@code VFdlibm} method and blended arm on the same inputs, + * bit for bit. * - *

The library is {@code io.github.vecbricks:vfdlibm}, a test-scope dependency: the reference - * and the oracle, never a kernel's run-time call. The sampled draws are 2.3's four over - * {@code varka.math.samples} inputs, 2^24 by default; the fixed vectors are every threshold of - * {@code e_exp.c} and its 64 neighbours each way, with the special values, over null patterns, - * lengths and three widths. Each of the library's planted faults, built into the expansion, fails - * the differential. + *

The library is {@code io.github.vecbricks:vfdlibm}, a test-scope dependency: the + * reference and the oracle, never a kernel's run-time call. The sampled draws are 2.3's four over + * {@code varka.math.samples} inputs a function, 2^24 by default; the fixed vectors are every + * threshold of its C file and its 64 neighbours each way, with the special values, over null + * patterns, lengths and three widths. Each of the library's planted faults, built into the + * expansion, fails the differential. */ @VarkaSuite(ownJvm = true) public final class VarkaMathPortSuite { @@ -73,10 +79,24 @@ public final class VarkaMathPortSuite { /** A port's root with its literal table. */ private record Built(VarkaVectorIR root, long[] lits) {} - private static Built exp(VarkaMathPort.Fault fault) { - var table = new VarkaMathPort.Table(); - VarkaVectorIR root = new VarkaMathPort(table).exp(X, fault); - return new Built(root, table.values()); + /** + * A ported function: its expansion, its oracles ({@code StrictMath}'s method, {@code VFdlibm}'s + * and the library's blended arm, reached by reflection since its class is package-private), its + * fixed vectors and the range of draw 1, the domain where its result is finite and not a limit. + */ + private record Fn(String name, BiFunction port, + DoubleUnaryOperator strict, UnaryOperator library, Method blended, + long[] fixed, double lowest, double highest) { + + Built build(VarkaMathPort.Fault fault) { + var table = new VarkaMathPort.Table(); + VarkaVectorIR root = port.apply(new VarkaMathPort(table), fault); + return new Built(root, table.values()); + } + + Built build() { + return build(VarkaMathPort.Fault.NONE); + } } /** @@ -93,6 +113,25 @@ private static VarkaEmitOptions portBase() { .withCse(true); } + private static Method blendedArm(String type, String method) { + try { + Method m = Class.forName("io.github.vecbricks.vfdlibm." + type) + .getDeclaredMethod(method, DoubleVector.class, VectorMask.class); + m.setAccessible(true); + return m; + } catch (ReflectiveOperationException e) { + throw new ExceptionInInitializerError(e); + } + } + + private static final Fn EXP = new Fn("exp", (p, f) -> p.exp(X, f), StrictMath::exp, + VFdlibm::exp, blendedArm("Exp", "expBlended"), expFixedVectors(), -745.2, 709.8); + + private static final Fn EXPM1 = new Fn("expm1", (p, f) -> p.expm1(X, f), StrictMath::expm1, + VFdlibm::expm1, blendedArm("Expm1", "expm1Blended"), expm1FixedVectors(), -40.0, 709.8); + + private static final List FUNCTIONS = List.of(EXP, EXPM1); + private static String hex(double v) { return String.format(Locale.ROOT, "%s (0x%016x)", v, Double.doubleToRawLongBits(v)); } @@ -144,7 +183,8 @@ private static boolean valid(Output out, int i) { // ------------------------------------------------------------------------------------------- @Test - @DisplayName("exp's constants are the doubles whose words e_exp.c's comments give") + @DisplayName("the ports' constants are the doubles whose words e_exp.c's and s_expm1.c's " + + "comments give") void constantsMatchTheirWords() { Map words = new HashMap<>(); words.put(VarkaMathPort.TWOM1000, 0x01700000_00000000L); @@ -158,6 +198,11 @@ void constantsMatchTheirWords() { words.put(VarkaMathPort.P3, 0x3F11566A_AF25DE2CL); words.put(VarkaMathPort.P4, 0xBEBBBD41_C5D26BF1L); words.put(VarkaMathPort.P5, 0x3E663769_72BEA4D0L); + words.put(VarkaMathPort.Q1, 0xBFA11111_111110F4L); + words.put(VarkaMathPort.Q2, 0x3F5A01A0_19FE5585L); + words.put(VarkaMathPort.Q3, 0xBF14CE19_9EAADBB7L); + words.put(VarkaMathPort.Q4, 0x3ED0CFCA_86E65239L); + words.put(VarkaMathPort.Q5, 0xBE8AFDB7_6E09C32DL); for (var e : words.entrySet()) { assertEquals(e.getValue(), Double.doubleToRawLongBits(e.getKey()), hex(e.getKey())); } @@ -282,10 +327,11 @@ void helpersMatchTheirDefinitions() { private static final VectorSpecies SPECIES = DoubleVector.SPECIES_PREFERRED; /** - * The two references of {@code xs}' lanes, as raw bits: {@code StrictMath.exp} and the library's - * {@code VFdlibm.exp} over {@code SPECIES}, with the tail padded by zeros. + * The three references of {@code xs}' lanes, as raw bits: {@code fn}'s {@code StrictMath} + * method, the library's {@code VFdlibm} method and its blended arm, the library over + * {@code SPECIES} with the tail padded by zeros. */ - private static long[][] references(long[] xs, int length) { + private static long[][] references(Fn fn, long[] xs, int length) { long[] strict = new long[length]; long[] library = new long[length]; double[] in = new double[SPECIES.length()]; @@ -295,23 +341,30 @@ private static long[][] references(long[] xs, int length) { in[j] = base + j < length ? Double.longBitsToDouble(xs[base + j]) : 0.0; } DoubleVector v = DoubleVector.fromArray(SPECIES, in, 0); - VFdlibm.exp(v).intoArray(out, 0); + fn.library().apply(v).intoArray(out, 0); + double[] outBlended; + try { + outBlended = ((DoubleVector) fn.blended().invoke(null, v, null)).toArray(); + } catch (ReflectiveOperationException e) { + throw new AssertionError(e); + } for (int j = 0; j < in.length && base + j < length; j++) { - strict[base + j] = Double.doubleToRawLongBits(StrictMath.exp(in[j])); + strict[base + j] = Double.doubleToRawLongBits(fn.strict().applyAsDouble(in[j])); library[base + j] = Double.doubleToRawLongBits(out[j]); } } return new long[][] {strict, library}; } - private static final String[] ORACLES = {"StrictMath.exp", "VFdlibm.exp"}; + private static final String[] ORACLES = {"StrictMath", "VFdlibm", "the blended arm"}; /** Adds a line per oracle {@code got} differs from at row {@code i}, up to ten in all. */ - private static void compare(String where, long x, long got, long[][] refs, int i, + private static void compare(Fn fn, String where, long x, long got, long[][] refs, int i, List failures) { for (int o = 0; o < refs.length; o++) { if (refs[o][i] != got && failures.size() < 10) { - failures.add(where + ": exp(" + hex(Double.longBitsToDouble(x)) + ") " + ORACLES[o] + failures.add(where + ": " + fn.name() + "(" + hex(Double.longBitsToDouble(x)) + ") " + + ORACLES[o] + " " + hex(Double.longBitsToDouble(refs[o][i])) + ", kernel " + hex(Double.longBitsToDouble(got))); } @@ -319,17 +372,17 @@ private static void compare(String where, long x, long got, long[][] refs, int i } // ------------------------------------------------------------------------------------------- - // exp: the sampled differential (2.3 test 1) + // The sampled differential (2.3 test 1) // ------------------------------------------------------------------------------------------- /** - * Draw {@code d}: uniform bit patterns; the finite-result domain, {@code [-745.2, 709.8]}; - * {@code [-2, 2]}; and magnitudes down to {@code 2^-60} in both signs. + * Draw {@code d}: uniform bit patterns; {@code fn}'s finite-result domain; {@code [-2, 2]}; and + * magnitudes down to {@code 2^-60} in both signs. */ - private static long draw(int d, SplittableRandom rnd) { + private static long draw(Fn fn, int d, SplittableRandom rnd) { return switch (d) { case 0 -> rnd.nextLong(); - case 1 -> Double.doubleToRawLongBits(rnd.nextDouble(-745.2, 709.8)); + case 1 -> Double.doubleToRawLongBits(rnd.nextDouble(fn.lowest(), fn.highest())); case 2 -> Double.doubleToRawLongBits(rnd.nextDouble(-2.0, 2.0)); case 3 -> Double.doubleToRawLongBits((rnd.nextBoolean() ? 1 : -1) * Math.scalb(1.0 + rnd.nextDouble(), -rnd.nextInt(61))); @@ -338,7 +391,7 @@ private static long draw(int d, SplittableRandom rnd) { } /** The kernel's mismatches against every oracle over the four draws, the first few listed. */ - private static long sampledMismatches(Built built, List firstFew) { + private static long sampledMismatches(Fn fn, Built built, List firstFew) { long mismatches = 0; var rnd = new SplittableRandom(0x345bL); try (Kernel k = new Kernel(built, 0); Arena arena = Arena.ofConfined()) { @@ -350,16 +403,16 @@ private static long sampledMismatches(Built built, List firstFew) { for (int d = 0; d < 4; d++) { for (int b = 0; b < perDraw; b++) { for (int i = 0; i < BATCH; i++) { - xs[i] = draw(d, rnd); + xs[i] = draw(fn, d, rnd); x.data().set(ValueLayout.JAVA_LONG, i * 8L, xs[i]); } k.run(x, y, out, BATCH); - long[][] refs = references(xs, BATCH); + long[][] refs = references(fn, xs, BATCH); for (int i = 0; i < BATCH; i++) { long got = out.data().get(ValueLayout.JAVA_LONG, i * 8L); int before = firstFew.size(); var lines = new ArrayList(); - compare("draw " + d, xs[i], got, refs, i, lines); + compare(fn, "draw " + d, xs[i], got, refs, i, lines); if (!lines.isEmpty()) { mismatches++; if (before < 5) { @@ -374,36 +427,66 @@ private static long sampledMismatches(Built built, List firstFew) { } @Test - @DisplayName("the exp port's kernel answers StrictMath.exp and vfdlibm's bits on every " - + "sampled input") - void expSampledDifferential() { - var firstFew = new ArrayList(); - long n = sampledMismatches(exp(VarkaMathPort.Fault.NONE), firstFew); - assertEquals(0L, n, n + " mismatches, " + firstFew); + @DisplayName("each port's kernel answers StrictMath's and vfdlibm's bits on every sampled input") + void sampledDifferential() { + for (Fn fn : FUNCTIONS) { + var firstFew = new ArrayList(); + long n = sampledMismatches(fn, fn.build(), firstFew); + assertEquals(0L, n, fn.name() + ": " + n + " mismatches, " + firstFew); + } } // ------------------------------------------------------------------------------------------- - // exp: the fixed vectors (2.3 test 2) + // The fixed vectors (2.3 test 2) // ------------------------------------------------------------------------------------------- + private static double fromHi(int h) { + return Double.longBitsToDouble(VarkaMathPort.fromHiBits(h)); + } + /** * Every threshold of e_exp.c in both signs with its 64 neighbours each way - the filter, the * overflow and underflow bounds, {@code 0.5 ln2} and {@code 1.5 ln2}, {@code 2^-28}, the - * subnormal scale-back's start near {@code -1021 ln2} - and SLEEF's special values with their - * neighbours: NaNs of both signs and several payloads, both infinities, {@code +-DBL_MAX}, - * {@code +-DBL_MIN}, {@code +-denorm_min}, both zeros and {@code +-1}. + * subnormal scale-back's start near {@code -1021 ln2} - with the special values. + */ + static long[] expFixedVectors() { + double ln2 = Math.log(2.0); + return fixedVectors(VarkaMathPort.O_THRESHOLD, VarkaMathPort.U_THRESHOLD, + fromHi(VarkaMathPort.HX_FILTER), fromHi(VarkaMathPort.HX_HALF_LN2), fromHi(0x3FF0A2B2), + fromHi(VarkaMathPort.HX_TINY), fromHi(VarkaMathPort.HX_NON_FINITE), -1021 * ln2, + -1021.5 * ln2, 0.5 * ln2, 1.5 * ln2); + } + + /** + * Every threshold of s_expm1.c in both signs with its 64 neighbours each way - the filter's + * {@code 56 ln2} and {@code 709.78}, {@code 0.5 ln2} and {@code 1.5 ln2}, {@code 2^-54} - and + * the edges of {@code k}'s forms: {@code k = 1}'s split at {@code r = -0.25}, and the first + * lanes of {@code k = 2}, {@code 20}, {@code 56} and {@code 57} - with the special values. */ - static long[] fixedVectors() { - double[] edges = {VarkaMathPort.O_THRESHOLD, VarkaMathPort.U_THRESHOLD, - Double.longBitsToDouble(VarkaMathPort.fromHiBits(VarkaMathPort.HX_FILTER)), - Double.longBitsToDouble(VarkaMathPort.fromHiBits(VarkaMathPort.HX_HALF_LN2)), - Double.longBitsToDouble(VarkaMathPort.fromHiBits(0x3FF0A2B2)), - Double.longBitsToDouble(VarkaMathPort.fromHiBits(VarkaMathPort.HX_TINY)), - Double.longBitsToDouble(VarkaMathPort.fromHiBits(VarkaMathPort.HX_NON_FINITE)), - -1021 * Math.log(2.0), -1021.5 * Math.log(2.0), 0.5 * Math.log(2.0), 1.5 * Math.log(2.0), - Double.MAX_VALUE, Double.MIN_NORMAL, Double.MIN_VALUE, 0.0, 1.0}; + static long[] expm1FixedVectors() { + double ln2 = Math.log(2.0); + return fixedVectors(VarkaMathPort.O_THRESHOLD, fromHi(VarkaMathPort.HX_56_LN2), + fromHi(VarkaMathPort.HX_FILTER), fromHi(VarkaMathPort.HX_HALF_LN2), fromHi(0x3FF0A2B2), + fromHi(VarkaMathPort.HX_TINY_EXPM1), fromHi(VarkaMathPort.HX_NON_FINITE), ln2 - 0.25, + 1.5 * ln2, 19.5 * ln2, 55.5 * ln2, 56.5 * ln2); + } + + /** + * {@code edges} in both signs with their 64 neighbours each way, and SLEEF's special values with + * their neighbours: NaNs of both signs and several payloads, both infinities, + * {@code +-DBL_MAX}, {@code +-DBL_MIN}, {@code +-denorm_min}, both zeros and {@code +-1}. + */ + private static long[] fixedVectors(double... thresholds) { + var all = new ArrayList(); + for (double t : thresholds) { + all.add(t); + } + for (double v : new double[] {Double.MAX_VALUE, Double.MIN_NORMAL, Double.MIN_VALUE, 0.0, + 1.0}) { + all.add(v); + } var bits = new ArrayList(); - for (double e : edges) { + for (double e : all) { for (double signed : new double[] {e, -e}) { long b = Double.doubleToRawLongBits(signed); for (int k = -64; k <= 64; k++) { @@ -423,17 +506,24 @@ static long[] fixedVectors() { i -> false, i -> i % 5 == 0, i -> i % 2 == 1, i -> true); @Test - @DisplayName("the exp port's kernel answers the oracles' bits on the fixed vectors, over nulls, " - + "lengths and three widths") - void expFixedVectors() { - long[] vectors = fixedVectors(); - long[][] refs = references(vectors, vectors.length); + @DisplayName("each port's kernel answers the oracles' bits on its fixed vectors, over nulls, " + + "lengths, three widths") + void fixedVectorsAnswerTheOracles() { var failures = new ArrayList(); + for (Fn fn : FUNCTIONS) { + fixedVectorFailures(fn, failures); + } + assertEquals(List.of(), failures); + } + + private static void fixedVectorFailures(Fn fn, List failures) { + long[] vectors = fn.fixed(); + long[][] refs = references(fn, vectors, vectors.length); var variants = List.of(portBase().withLanesOverride(2), portBase().withLanesOverride(4), portBase().withLanesOverride(8)); for (VarkaEmitOptions options : variants) { String lanes = options.canonical(); - try (Kernel k = new Kernel(exp(VarkaMathPort.Fault.NONE), options)) { + try (Kernel k = new Kernel(fn.build(), options)) { for (int length : new int[] {1, 7, 33, vectors.length}) { for (int p = 0; p < NULL_PATTERNS.size(); p++) { IntPredicate isNull = NULL_PATTERNS.get(p); @@ -450,8 +540,8 @@ void expFixedVectors() { if (valid(out, i) == isNull.test(i)) { failures.add(where + ": validity " + valid(out, i)); } else if (!isNull.test(i)) { - compare(where, vectors[i], out.data().get(ValueLayout.JAVA_LONG, i * 8L), - refs, i, failures); + compare(fn, where, vectors[i], + out.data().get(ValueLayout.JAVA_LONG, i * 8L), refs, i, failures); } } } @@ -459,7 +549,6 @@ void expFixedVectors() { } } } - assertEquals(List.of(), failures); } private static int depth(VarkaVectorIR node, Map memo) { @@ -477,21 +566,24 @@ private static int depth(VarkaVectorIR node, Map memo) { } @Test - @DisplayName("the exp port is deeper than a projection's cap, which its auto cap admits") - void expDepthIsWithinThePortCap() { - var root = exp(VarkaMathPort.Fault.NONE).root(); - int d = depth(root, new HashMap<>()); + @DisplayName("each port is deeper than a projection's cap, which its auto cap admits") + void depthIsWithinThePortCap() { var defaults = VarkaEmitOptions.DEFAULTS; - assertTrue(d > VarkaEmitBudget.MAX_CHAIN_DEPTH && d <= VarkaEmitBudget.PORT_MAX_CHAIN_DEPTH, - "the exp port's depth is " + d); - assertEquals(VarkaEmitBudget.PORT_MAX_CHAIN_DEPTH, - VarkaEmitBudget.chainDepthCap(defaults, root)); - // A tree without a port keeps the lane's cap, and an explicit cap is honoured on a port. + for (Fn fn : FUNCTIONS) { + var root = fn.build().root(); + int d = depth(root, new HashMap<>()); + assertTrue(d > VarkaEmitBudget.MAX_CHAIN_DEPTH && d <= VarkaEmitBudget.PORT_MAX_CHAIN_DEPTH, + "the " + fn.name() + " port's depth is " + d); + assertEquals(VarkaEmitBudget.PORT_MAX_CHAIN_DEPTH, + VarkaEmitBudget.chainDepthCap(defaults, root)); + assertEquals(16, VarkaEmitBudget.chainDepthCap(defaults.withMaxChainDepth(16), root)); + // The tree passes the compiler's mirror at the default and fails it at 16. + assertTrue(VarkaLoopEmitter.fitsBudgets(List.of(root), 1, defaults)); + assertFalse(VarkaLoopEmitter.fitsBudgets(List.of(root), 1, + defaults.withMaxChainDepth(16))); + } + // A tree without a port keeps the lane's cap. assertEquals(VarkaEmitBudget.MAX_CHAIN_DEPTH, VarkaEmitBudget.chainDepthCap(defaults, X)); - assertEquals(16, VarkaEmitBudget.chainDepthCap(defaults.withMaxChainDepth(16), root)); - // exp's own tree passes the compiler's mirror at the default and fails it at 16. - assertTrue(VarkaLoopEmitter.fitsBudgets(List.of(root), 1, defaults)); - assertFalse(VarkaLoopEmitter.fitsBudgets(List.of(root), 1, defaults.withMaxChainDepth(16))); } @Test @@ -526,37 +618,42 @@ void portStopsAtTheCap() { } @Test - @DisplayName("the exp port is declined, with the op cap's name, in the form without a byte " + @DisplayName("each port is declined, with the op cap's name, in the form without a byte " + "budget") - void expDeclinedWithoutAByteBudget() { + void portsDeclinedWithoutAByteBudget() { var options = portBase().withMethodByteBudget(0); - var built = exp(VarkaMathPort.Fault.NONE); - assertFalse(VarkaLoopEmitter.fitsBudgets(List.of(built.root()), 1, options)); - var e = assertThrows(IllegalArgumentException.class, - () -> VarkaEmitterFixtures.emit(List.of(built.root()), 2, built.lits().length, options)); - assertTrue(e.getMessage().contains("MAX_FUSED_NODES=64"), e.getMessage()); + for (Fn fn : FUNCTIONS) { + var built = fn.build(); + assertFalse(VarkaLoopEmitter.fitsBudgets(List.of(built.root()), 1, options), fn.name()); + var e = assertThrows(IllegalArgumentException.class, () -> VarkaEmitterFixtures.emit( + List.of(built.root()), 2, built.lits().length, options), fn.name()); + assertTrue(e.getMessage().contains("MAX_FUSED_NODES=64"), e.getMessage()); + } } @Test - @DisplayName("the reference evaluator answers StrictMath.exp's bits on the exp port's tree") - void referenceEvaluatesThePort() { - Built built = exp(VarkaMathPort.Fault.NONE); - long[] vectors = fixedVectors(); - var rnd = new SplittableRandom(0x345bL); + @DisplayName("the reference evaluator answers StrictMath's bits on each port's tree") + void referenceEvaluatesThePorts() { var failures = new ArrayList(); - for (int i = 0; i < vectors.length + 4000 && failures.size() < 10; i++) { - long x = i < vectors.length ? vectors[i] : draw(i % 4, rnd); - var got = VarkaReference.mixedValue(built.root(), new long[] {x, 0L}, - new boolean[] {false, false}, new int[0], built.lits()); - long want = Double.doubleToRawLongBits(StrictMath.exp(Double.longBitsToDouble(x))); - if (got.isEmpty() || got.getAsLong() != want) { - failures.add("exp(" + hex(Double.longBitsToDouble(x)) + "): want " - + hex(Double.longBitsToDouble(want)) + ", reference " + got); + for (Fn fn : FUNCTIONS) { + Built built = fn.build(); + long[] vectors = fn.fixed(); + var rnd = new SplittableRandom(0x345bL); + for (int i = 0; i < vectors.length + 4000 && failures.size() < 10; i++) { + long x = i < vectors.length ? vectors[i] : draw(fn, i % 4, rnd); + var got = VarkaReference.mixedValue(built.root(), new long[] {x, 0L}, + new boolean[] {false, false}, new int[0], built.lits()); + long want = Double.doubleToRawLongBits( + fn.strict().applyAsDouble(Double.longBitsToDouble(x))); + if (got.isEmpty() || got.getAsLong() != want) { + failures.add(fn.name() + "(" + hex(Double.longBitsToDouble(x)) + "): want " + + hex(Double.longBitsToDouble(want)) + ", reference " + got); + } } + var none = VarkaReference.mixedValue(built.root(), new long[] {0L, 0L}, + new boolean[] {true, false}, new int[0], built.lits()); + assertTrue(none.isEmpty(), fn.name() + " of a null is null, not " + none); } - var none = VarkaReference.mixedValue(built.root(), new long[] {0L, 0L}, - new boolean[] {true, false}, new int[0], built.lits()); - assertTrue(none.isEmpty(), "exp of a null is null, not " + none); assertEquals(List.of(), failures); } @@ -604,17 +701,23 @@ void d2iIsJavasCast() { // ------------------------------------------------------------------------------------------- @Test - @DisplayName("each of vfdlibm's planted faults, built into the expansion, fails the " + @DisplayName("each of vfdlibm's planted faults, built into each expansion, fails the " + "differential") void plantedFaultsAreCaught() { - long[] vectors = fixedVectors(); - long[][] refs = references(vectors, vectors.length); + for (Fn fn : FUNCTIONS) { + plantedFaultsAreCaught(fn); + } + } + + private static void plantedFaultsAreCaught(Fn fn) { + long[] vectors = fn.fixed(); + long[][] refs = references(fn, vectors, vectors.length); for (VarkaMathPort.Fault fault : VarkaMathPort.Fault.values()) { if (fault == VarkaMathPort.Fault.NONE) { continue; } long n = 0; - try (Kernel k = new Kernel(exp(fault), 0); Arena arena = Arena.ofConfined()) { + try (Kernel k = new Kernel(fn.build(fault), 0); Arena arena = Arena.ofConfined()) { Col x = VarkaEmitterFixtures.makeLongInput(arena, vectors.length, i -> false, i -> vectors[i], false); Col y = VarkaEmitterFixtures.makeLongInput(arena, vectors.length, i -> false, i -> 0L, @@ -628,9 +731,9 @@ void plantedFaultsAreCaught() { } } if (n == 0) { - n = sampledMismatches(exp(fault), new ArrayList<>()); + n = sampledMismatches(fn, fn.build(fault), new ArrayList<>()); } - assertTrue(n > 0, fault + " went unseen"); + assertTrue(n > 0, fn.name() + ": " + fault + " went unseen"); } } diff --git a/sql/varka/plans/m8/PLAN.md b/sql/varka/plans/m8/PLAN.md index 1dfbeeab3a0e..6fbf6295e4e2 100644 --- a/sql/varka/plans/m8/PLAN.md +++ b/sql/varka/plans/m8/PLAN.md @@ -1145,7 +1145,7 @@ catalogue keep theirs. Sizes are the house's small, medium and large. | 342 | **Started** (step 1 built, merged as #1228 on 31 October 2026, `VARKA-342.md` 5: the row path's baseline, `VarkaFloatingArithmeticBaselineBenchmark`, over the division in LEGACY and ANSI, `try_divide`, `sqrt(abs(x))`, `-x`, `signum`, `degrees` and the two interval forms, with and without nulls, its results from the EPYC runners at both widths, committed before merge and not yet run; the baselines' fuse check per section against each class's list of the sections a row has fused, `VarkaFloatingBaselineBenchmark`'s comparison and choice listed, `-Dvarka.baseline.fuseCheck=false` lifting it for the measurement; step 3 built, merged as #1248 on 1 November 2026, `VARKA-342.md` 5.1: `+`, `-`, `*`, negation and `abs` over `DOUBLE` and `FLOAT`, and `/`, `try_divide`, `sqrt`, `signum`, `degrees` and `radians` over `DOUBLE`, fuse in every mode in a new floating arithmetic family; `IntArith` and `IntNeg` at the floating lanes with an `IntOp.DIV` whose mode is the zero divisor's disposal, null under LEGACY and TRY and a declined batch under ANSI with its own refusal bit, and a `MathUnary` node for `sqrt`; `signum` built with `x` as its last arm so a null answers null; 26 coverage rows, the reference evaluator, the cells against Spark in the three modes, every `FLOAT` pattern through negation and `abs`, and the binary `FLOAT` sweeps behind `-Dvarka.sweep=true`; the two floating baselines list the sections it fuses, every `DOUBLE` section and the chains; step 4's first piece built 8 November 2026, `VARKA-342.md` 5.2: the division and the functions over a cast to double already fuse over 343's conversions, recorded as the coverage family "Floating arithmetic over other types" (`y1 / i`, `f / f2`, `sqrt(i)`, `signum(f)` and their kin, a `BIGINT` operand declining below AVX512DQ); `signum` over both interval types fuses as `(double) ((m > 0) - (m < 0))` over `CondValue`s, null for a null count and needing no `L2D`; `fp_half_up.smt2` proves 2.4's rounding and guards against Guava under both solvers ahead of its lowering; the four interval products and quotients wait for 343b2's conversions to an integral lane, and their decline says so; left: the census cells (step 2), those four forms after 343b2 (step 4's second piece), the fuzz grammar's floating sequence, the cost model's `DIV` and `SQRT` prices and the measurement). **Planned** (`VARKA-342.md`, 27 October 2026; the admission check: `+`, `-`, `*`, negation, `abs`, `sqrt`, `degrees` and `radians` have one answer in every mode, the IEEE operation `java.lang.Math` computes, and C2 contracts no vector multiply and add, so each is bit-exact by construction; `/` is `DivModLike`, null under LEGACY and TRY (`try_divide` is LEGACY's) and raised under ANSI on a `-0.0` divisor too, unless the dividend is null; `Divide` and the functions take `DOUBLE` only, so `i / j`, `f / g` and the functions over another type arrive under casts to double and fuse once 343's conversions land, as do the interval forms, whose HALF_UP is built from 343's truncation and a half-step test, not 344's `rint`; the arithmetic reuses `IntArith` and `IntNeg` at the floating lanes, with an `IntOp.DIV` whose mode is the zero divisor's disposal, and `sqrt` opens a `MathUnary` node; `signum` tests zero and NaN before the sign, Spark's order putting NaN above every number; of this row's forms, the committed baseline times only the chain `(x + y) * z - x`, so a baseline of the other forms comes first). Floating arithmetic and the exact functions: `+`, `-`, `*`, `/` (a zero divisor null or raised, Spark the ANSI oracle; an int division through its casts; never a reciprocal), negation, `abs`, `signum`, `sqrt`, `degrees`, `radians`, `try_divide`, the interval products and quotients by a floating factor, with 2.7's signed-zero and special cells. *30 October 2026, from row 103's plan (`VARKA-103.md` 0 item 13, 8 point 2):* 3.7's pinned cells for the interval forms hold the ties and the guard's ends but not the long form's `2^53` and long-edge cells of the double factor: `(2^53 + 1) * 0.5`, where the long is rounded to a double before the multiply, `+-(2^53 - 1) * 0.5`, and `MAX * 1.0`, `(MAX - 511) * 1.0` and `MIN * -1.0` raising against `(MAX - 512) * 1.0`, `MAX * -1.0` and `MIN * 1.0`, which fit, with Guava's answers (**[A, 7]** of `results/VARKA-103-admission.txt`). This row's 2.4 cells gain them, so the lowering is pinned where it lands; row 103 keeps them as its named tests over it in 103d. **Done when** each fuses, bit-identical to the row engine over sampled regions and the fuzzer | item 35 | medium | | 343 | **Started** (*3 November 2026*: split into nine pull requests of at most 1000 changed lines, 343a1 to 343a5 cut from #1303, 343a3b for the root-level crossing after 343a3, and 343b1 to 343b3 after them, `VARKA-343.md` 4; 343b1, built 8 November 2026 (`VARKA-343.md` 10): `BIGINT` to `DOUBLE` and `FLOAT` fuse below emit level 3 by exact AVX2 forms, the split for `L2D` (the bounded magic its `wideConversionForm` arm) and rounding to odd without a mask for `L2F`, proven over every long in `round_to_odd.smt2`, the split-and-add form kept as the named failing case, and the unknown level still declining; 343a1 and 343a2, merged as #1311 and #1317 on 3 November 2026; 343a3b, merged as #1338 on 4 November 2026, `VARKA-343.md` 10: conditions of two kinds meet in one kernel by a lane crossing, a filter's floating conjunct beside an integral one fuses, roots of one width share a kernel, and the long-literal check plans under the session's options; 343a5, built 6 November 2026 on 343a4 (`VARKA-343.md` 10): the fuzz grammar's conversions and crossings, the 2^32 sweeps of `INT` to `FLOAT` and `DOUBLE` and of `FLOAT` to `DOUBLE` and `BOOLEAN`, and the false-AND forms of `CAST(y1 AS DOUBLE)` and `CAST(s1 AS DOUBLE)` freed by admitting a narrow column's null test under a double kernel; 343a4, built 6 November 2026 (`VARKA-343.md` 10): `BIGINT` to `FLOAT` and `DOUBLE` fuse where the emit level assures AVX512DQ, level 3 from an x86 host that has it, and the unknown level declines them; 343a3, merged as #1328 on 4 November 2026, `VARKA-343.md` 10: kernels of two lane counts, `INT`, the narrow types and `BOOLEAN` to both floating types and `FLOAT` with `DOUBLE`, the same-count mask crossing `VARKA-341.md` 5.1 left owed, and the three failures of #1303's last option matrix fixed; step 1 built, merged as #1242 on 1 November 2026, `VARKA-343.md` 5: the row path's baseline, `VarkaFloatingCastBaselineBenchmark`, over `BIGINT` to `FLOAT` and `DOUBLE`, `INT` to `DOUBLE`, `DOUBLE` to `INT` in LEGACY past the int range and with NaN and the infinities and in ANSI, `try_cast` to `BIGINT` with one row in a hundred past the long range, `DOUBLE` to `FLOAT`, `DOUBLE` to `BOOLEAN` as a filter under `coalesce` and `time_from_seconds`, with and without nulls, its results from the EPYC runners at both widths, committed before merge and not yet run; its fuse check per section is row 342's baseline's, which `VarkaFloatingBaselineBenchmark` already has; no section listed as fusing, the `coalesce` keeping the optimizer from inferring an `IS NOT NULL` that would fuse under Spark's `Filter` while the cast declines). **Planned** (`VARKA-343.md`, 27 October 2026; the admission check: every floating cast declines by name and 26 pairs of `m8/casts.tsv` are this row's; no node converts between the kinds and no kernel holds two lane counts across them, so the row adds one conversion node and turns the kernel plan's lane rules into width rules; `GuardedRange` only declines, so TRY's nulls need a null disposal, which row 332 shares; C2's `L2F` on aarch64 rounds once, so round-to-odd is the AVX2 form only; the magic number rounds where the cast truncates, so the AVX2 `D2L` truncates first; on AVX2 an exact split for `L2D` and an exponent assembly for `D2L` cover the whole range, against the row's bounded form as an option arm; `time_from_seconds` needs row 342's floating multiply; the committed baseline times two of the pairs, so a baseline for the rest comes first; large, against the medium first set, and in two pull requests after the baseline, the conversions to a floating type first; two open questions). The floating casts: integral to floating (rounding as the JVM does; `BIGINT` to `FLOAT` rounded once, by round-to-odd on AVX2 and NEON), `FLOAT` and `DOUBLE` to each other, floating to integral (LEGACY's saturation with no detection, ANSI's two range compares and NaN, TRY's nulls, the mapping table of 2.7 with its boundary cells; `D2L` and its kin under AVX512DQ, the magic-number form below `2^51` on AVX2, the host named), to and from `BOOLEAN`, `time_from_seconds` over a double. **Done when** every such pair of `m8/casts.tsv` fuses in the three modes, a `FLOAT` source proven over all 2^32 bit patterns, the round-to-odd truncation stated as an SMT bit-vector claim and exhausted through `binary16`, and a split-and-add conversion kept as a named failing case (it misrounds 16.5% of random unsigned 32-bit inputs above `2^31`; 4275361147 gives 4275361280 against 4275361024, `READING_0X80.md`) | this plan, 2.2 | large | | 344 | **Started** (step 1 built, merged as #1257 on 2 November 2026, `VARKA-344.md` 5: the row path's baseline, `VarkaRoundingBaselineBenchmark`, over `rint(x)` in the session's default mode, `floor(x)`, `ceil(x)`, `floor(i)`, `round(i, -2)`, `bround(i, -2)` and `truncate(l, -3)` each in LEGACY and ANSI, `round(l, -3)` in ANSI, `factorial` over `[-2, 22]` and `width_bucket` with literal bounds, with and without nulls, `x` inside `2^51` so that 344b's `MAGIC` arm declines no batch, and `floor` and `ceil` under LEGACY over a wide column `xw` (one row in four wide, mostly past `2^51` and half of those past the long range, with NaN and infinities), on which every batch declines, added by the owner's word on 1 November 2026, and under ANSI over `xwf`, the same wide share inside `2^62.2` with NaN and no infinity, so no ANSI section raises, 40 sections, its results from the EPYC runners at both widths committed on 5 November 2026, merged as #1350 (benchmark runs 41939401101 at 256 bits and 41939588739 at 128 bits, on master 50b4fe96125); under the shared fuse check, no section listed as fusing; 344a1 built 7 November 2026, `VARKA-344.md` 10: `rint` over a double fuses in every mode as a new `RoundToIntegral` node, the `2^52` construction with the sign restored and one blend under `|x| < 2^52`, proven equal to `fp.roundToIntegral RNE` at binary32 and binary64 in `fp_round.smt2`, and `floor`, `ceil` and `ceiling` over a `BIGINT` (the operand) and over an `INT` (its widening) fuse in a new rounding family; 344a2 built 8 November 2026: `round`, `bround` and `truncate` over `TINYINT`, `SMALLINT` and `INT` at a constant scale fuse as the signed remainder of the truncating quotient by `10^k` on the int lane, ANSI's overflowing tails declined by a guard bisected over `BigDecimal`, proven in `int_round.smt2`, and `BIGINT` at a scale of 0 or more as the operand; split by the cap, so left: 344a3, `BIGINT` at a negative scale with the pre-shift, then 344b and 344c, the `rint(-NaN)` probe on the runners and the measurement against the baseline). **Planned** (`VARKA-344.md`, 30 October 2026; the admission check: no rounding operator is reachable from the Vector API on any host - `RoundDoubleModeV` is made only by SuperWord from the scalar intrinsics - so the `2^52` construction is the form everywhere, with its sign restored on the long view since the bitwise operators refuse a floating lane; every form is exact, so none is under the ULP contract, and question 2 concerns a contracted child under them, a check for 345; ANSI `floor` and `ceil` raise at `2^63`, where the ANSI cast passes it, and pass NaN to 0, so the guard reads the operand with NaN blended to `0.0`; on AVX2 the whole-range form over 343's exponent assembly is the default and the fused magic form, declining above `2^51`, the `wideConversionForm` reference arm, by 343's answered question 1; the integral rounding is the signed remainder of `ConstDivide`'s truncating quotient, its ANSI overflow two compile-time tails under a guard since a checked multiply is refused, `BIGINT` taking 2.8's pre-shift for `k >= 12` and declining beyond a guard below, the full range being row 360's widening multiply by a constant; `floor(i)` over an `INT` is the operand widened, without 343, the narrow types waiting for row 332's narrow load in a `BIGINT` kernel; a baseline first; large, in three pull requests by dependency: 344a after 341, 344b after 343b, 344c after 342 and 343; three open points for the lead). The rounding functions: `floor`, `ceil`, `rint` over a double by the `2^52` construction with its conditions written out (2.7), `floor` and `ceil` to `BIGINT` (on AVX2 through `rint`, the correction and the magic conversion, declining above `2^51`), `round`, `bround` (the Lemire, Bartlett and Kaser section 7 form) and `truncate` over integral types, `factorial`, `width_bucket`, the `rint(-NaN)` probe. **Done when** each fuses, the double forms checked over every boundary region, `rint(-0.3)` giving `-0.0`, and the integral ones by exhaustion at 32 bits | items 35, 36 | medium | -| 345 | **Started** (*21 November 2026*: 345b1 built on 345a2, `VARKA-345.md` 10.2: the `PORT` frame, the bit-view node `ReinterpretLane` and `VarkaMathPort`'s word helpers, each held to its definition on the raw bits; 345b2 on it (`VARKA-345.md` 10.2): `exp` on the frame, bit for bit `StrictMath.exp` and `VFdlibm.exp`, the auto chain cap of a tree holding a port, and `vfdlibm` 0.1.0 as the test-scope oracle; step 1 merged as #1414 on 9 November 2026, `VARKA-345.md` 4 and 5: the row path's baseline, `VarkaMathBaselineBenchmark`, over `sin(x)`, `tan(x)`, `cbrt(x)`, `exp(x)`, `log(p)`, `log10(p)`, `pow(p, y)`, `atan2(y, x)`, `sinh(x)`, `hypot(x, y)`, `sec(x)` and `exp(x) * 2 + 1`, with and without nulls, `x` and `y` in `[-10, 10)` and `p` positive in `[1e-6, 1e6)` so the logarithms and `pow` take their ordinary path, 24 sections, its results from the EPYC runners at both widths, runs 42527097690 and 42537748319; under the shared fuse check, no section listed as fusing; *9 November 2026*: part 345a1 built, `VARKA-345.md` 10: the configuration, off by default, its emit option `mathUlpContract` of the new reason `CONTRACT`, the math family with every function declining by its row, `VarkaMathBound`, the docs entry and the dated corrections, merged as #1428; *21 November 2026*: 345a2 on it, the binding, the contract table and the coverage column, merged with master, the trigonometric rows of #1567 now naming their exact forms, merged as #1604). **Planned** (`VARKA-345.md`, 30 October 2026, reworked the same day after the owner's and the lead's settlements; the admission check: Spark calls `StrictMath` for `exp`, `expm1`, `log`, `log10`, `log1p`, `pow` and the two-argument `log`, and `Math` for the rest, of which `asin`, `acos`, `atan`, `atan2`, `sinh`, `cosh` and `hypot` are fdlibm on every host and `sin`, `cos`, `tan`, `tanh` and `cbrt` the host's stub, called alike by the interpreter, C1 and C2, so a per-lane call in a kernel is exact and costs the scalar call; a lane-wise copy of fdlibm's `exp` matched `StrictMath.exp` on every one of 16777216 sampled inputs and 3640 fixed vectors at both widths, while its laptop timing is provisional and says nothing about fdlibm in lanes: why it was not faster is unexplained; the timed runs forced inlining by CompileCommand, a run without it showed the 601-bytecode method refused ("hot method too big") at three call sites, so whether boxing explains the timing is not established; the IR-emitted port's run decides; the JDK's `FdLibm.java` and HotSpot's x86 stubs are GPLv2, so a port is written from Sun's fdlibm 5.3 C sources, fetched only with the owner's yes, and the JDK file is the test oracle only; outside C2 a Vector API math operator is `Math.` per lane, a masked one computes every lane, and a dead lane at `1e300` or NaN made SVML's `SIN` about six times slower until blended to `0.5`; the probe's step distance overflows for opposite signs; `results/VARKA-345-admission.txt`, `results/VARKA-345-exact-admission.txt`). The math family's exact default and its opt-in ULP contract (2.7.1; *30 October 2026, by the owner's word:* exact by default, the contract an opt-in mode off by default). **The exact default**: the thirteen fdlibm functions fuse first as a per-lane `StrictMath.` call inside the kernel, exact, the work around it vectorised; a lane-wise port of fdlibm 5.3 is a measured option arm per function (`mathPort`), kept either way, and the default only where it measures faster on the EPYC runners (the lead, 30 October 2026); the port is emitted by Varka as IR nodes in its own kernels, never called, with the standalone vector fdlibm library `vfdlibm` (https://github.com/vecbricks/vfdlibm, its own repository, filled one function at a time as Varka needs it, each function ported there from fdlibm 5.3's C sources and cross-checked bit for bit with Varka's emitted kernel, both checked against `StrictMath`) as its reference and test oracle and no runtime dependency (the owner, 30 October 2026: C2 inlines a hot callee only up to 325 bytecodes, `@ForceInline` is dropped outside the JDK, and a refused call boxes its vectors, `VARKA-345.md` 2.2); the host-dependent `sin`, `cos`, `tan`, `tanh` and `cbrt` by a per-lane `Math.` call; the compositions as Spark writes them; three bit-identity tests per form (a sampled differential of at least 2^24 inputs a function, the fixed vectors, the engine's own differentials), seeded with SLEEF's special-value list - NaN, both infinities, `+-DBL_MAX`, `+-DBL_MIN`, `+-denorm_min`, both zeros, `+-1` and their neighbours (`READING_SLEEF.md` 6.3; *27 October 2026, from `READING_TRACE.md` 2 item 6*). 345 builds the forms and their lowerings, the port's IR helpers and `exp` as the template in the library and as an IR expansion, after the owner's yes on fetching the C sources; each function is its row's (356 to 358). **The opt-in mode**, `spark.sql.codegen.varka.math.ulpContract.enabled`, off by default, its emit option in the shape key: a function may take the Vector API's library operator where its binding has a contract entry; the bound a count of representable doubles from the row engine's double (`VarkaMathBound.steps`, which 367's probe also measures with), keyed by the full JDK build, library and CPU, contracted and measured bounds kept apart, the contracted value at least every measured line and its suite failing when one exceeds it; the binding verified once per JDK build under `-Djdk.incubator.vector.DEBUG=true` and by the C2 compile itself (`dev/varka_emit.sh --asm` showing the call to the library's symbol, since the DEBUG line proves the symbol and not the call, `READING_JDK.md` 2.6); SLEEF's stated tier beside each measured bound (`READING_SLEEF.md` 6.5); null and masked-off lanes blended to a harmless argument before the library call, since a masked math operator computes every lane and blends after (`READING_JDK.md` 2.7); the oracle and fuzzers comparing a contracted value within the bound, a NaN never passing against a number, and a composition bit for bit against a C2-warmed library reference; the differential suites' configuration-on arm; question 2 applies to this mode only, does not block 356 to 358, and stays the owner's; `SCOPE_STANDARD_MODE.md` 3.4 becomes the mode's entry. Census reading (`VARKA-376.md` 9, 20 October 2026, laptop): every `Double` math operator is intrinsic and allocation-free at 512 bits; at 256 and 128 bits `POW` has no vector stub, so the loop never reaches the library call and runs the Java fallback (the canary's finding), which is the form of `pow` at those species in the opt-in mode until a host shows otherwise. **Done when** with the configuration off no kernel holds a library call and every exact form admitted through the test hook is bit-identical to Spark by the three tests; with it on, the library operator appears only on a binding with a contract entry; a test shows a within-bound comparison catches a lane two steps further out and refuses every pair of opposite signs; the binding check passes on the x86 and Arm runners; and the dated corrections of `SCOPE_FUNCTIONS.md` 3, item 36 and `SCOPE_STANDARD_MODE.md` 3.4 record the exact default (*until 30 October 2026 the done-when asked for the configuration to decline the family when off, a test showing a within-bound comparison catches a lane two steps further out, and the dated corrections of `SCOPE_FUNCTIONS.md` 3 and item 36*) | item 36; owner's decision, 14 October 2026, superseded by the owner's decision of 30 October 2026 | medium | +| 345 | **Started** (*22 November 2026*: 345c1 built on 345b2, not merged, `VARKA-345.md` (345c): `expm1`'s `PORT` expansion on the reduction it shares with `exp`, bit for bit `StrictMath.expm1` and `VFdlibm.expm1` of `vfdlibm` 0.2.0, paired with `vfdlibm` branch `varka-expm1-long-words` (lemma L15); left: the log family's ports; *21 November 2026*: 345b1 built on 345a2, `VARKA-345.md` 10.2: the `PORT` frame, the bit-view node `ReinterpretLane` and `VarkaMathPort`'s word helpers, each held to its definition on the raw bits; 345b2 on it (`VARKA-345.md` 10.2): `exp` on the frame, bit for bit `StrictMath.exp` and `VFdlibm.exp`, the auto chain cap of a tree holding a port, and `vfdlibm` 0.1.0 as the test-scope oracle; step 1 merged as #1414 on 9 November 2026, `VARKA-345.md` 4 and 5: the row path's baseline, `VarkaMathBaselineBenchmark`, over `sin(x)`, `tan(x)`, `cbrt(x)`, `exp(x)`, `log(p)`, `log10(p)`, `pow(p, y)`, `atan2(y, x)`, `sinh(x)`, `hypot(x, y)`, `sec(x)` and `exp(x) * 2 + 1`, with and without nulls, `x` and `y` in `[-10, 10)` and `p` positive in `[1e-6, 1e6)` so the logarithms and `pow` take their ordinary path, 24 sections, its results from the EPYC runners at both widths, runs 42527097690 and 42537748319; under the shared fuse check, no section listed as fusing; *9 November 2026*: part 345a1 built, `VARKA-345.md` 10: the configuration, off by default, its emit option `mathUlpContract` of the new reason `CONTRACT`, the math family with every function declining by its row, `VarkaMathBound`, the docs entry and the dated corrections, merged as #1428; *21 November 2026*: 345a2 on it, the binding, the contract table and the coverage column, merged with master, the trigonometric rows of #1567 now naming their exact forms, merged as #1604). **Planned** (`VARKA-345.md`, 30 October 2026, reworked the same day after the owner's and the lead's settlements; the admission check: Spark calls `StrictMath` for `exp`, `expm1`, `log`, `log10`, `log1p`, `pow` and the two-argument `log`, and `Math` for the rest, of which `asin`, `acos`, `atan`, `atan2`, `sinh`, `cosh` and `hypot` are fdlibm on every host and `sin`, `cos`, `tan`, `tanh` and `cbrt` the host's stub, called alike by the interpreter, C1 and C2, so a per-lane call in a kernel is exact and costs the scalar call; a lane-wise copy of fdlibm's `exp` matched `StrictMath.exp` on every one of 16777216 sampled inputs and 3640 fixed vectors at both widths, while its laptop timing is provisional and says nothing about fdlibm in lanes: why it was not faster is unexplained; the timed runs forced inlining by CompileCommand, a run without it showed the 601-bytecode method refused ("hot method too big") at three call sites, so whether boxing explains the timing is not established; the IR-emitted port's run decides; the JDK's `FdLibm.java` and HotSpot's x86 stubs are GPLv2, so a port is written from Sun's fdlibm 5.3 C sources, fetched only with the owner's yes, and the JDK file is the test oracle only; outside C2 a Vector API math operator is `Math.` per lane, a masked one computes every lane, and a dead lane at `1e300` or NaN made SVML's `SIN` about six times slower until blended to `0.5`; the probe's step distance overflows for opposite signs; `results/VARKA-345-admission.txt`, `results/VARKA-345-exact-admission.txt`). The math family's exact default and its opt-in ULP contract (2.7.1; *30 October 2026, by the owner's word:* exact by default, the contract an opt-in mode off by default). **The exact default**: the thirteen fdlibm functions fuse first as a per-lane `StrictMath.` call inside the kernel, exact, the work around it vectorised; a lane-wise port of fdlibm 5.3 is a measured option arm per function (`mathPort`), kept either way, and the default only where it measures faster on the EPYC runners (the lead, 30 October 2026); the port is emitted by Varka as IR nodes in its own kernels, never called, with the standalone vector fdlibm library `vfdlibm` (https://github.com/vecbricks/vfdlibm, its own repository, filled one function at a time as Varka needs it, each function ported there from fdlibm 5.3's C sources and cross-checked bit for bit with Varka's emitted kernel, both checked against `StrictMath`) as its reference and test oracle and no runtime dependency (the owner, 30 October 2026: C2 inlines a hot callee only up to 325 bytecodes, `@ForceInline` is dropped outside the JDK, and a refused call boxes its vectors, `VARKA-345.md` 2.2); the host-dependent `sin`, `cos`, `tan`, `tanh` and `cbrt` by a per-lane `Math.` call; the compositions as Spark writes them; three bit-identity tests per form (a sampled differential of at least 2^24 inputs a function, the fixed vectors, the engine's own differentials), seeded with SLEEF's special-value list - NaN, both infinities, `+-DBL_MAX`, `+-DBL_MIN`, `+-denorm_min`, both zeros, `+-1` and their neighbours (`READING_SLEEF.md` 6.3; *27 October 2026, from `READING_TRACE.md` 2 item 6*). 345 builds the forms and their lowerings, the port's IR helpers and `exp` as the template in the library and as an IR expansion, after the owner's yes on fetching the C sources; each function is its row's (356 to 358). **The opt-in mode**, `spark.sql.codegen.varka.math.ulpContract.enabled`, off by default, its emit option in the shape key: a function may take the Vector API's library operator where its binding has a contract entry; the bound a count of representable doubles from the row engine's double (`VarkaMathBound.steps`, which 367's probe also measures with), keyed by the full JDK build, library and CPU, contracted and measured bounds kept apart, the contracted value at least every measured line and its suite failing when one exceeds it; the binding verified once per JDK build under `-Djdk.incubator.vector.DEBUG=true` and by the C2 compile itself (`dev/varka_emit.sh --asm` showing the call to the library's symbol, since the DEBUG line proves the symbol and not the call, `READING_JDK.md` 2.6); SLEEF's stated tier beside each measured bound (`READING_SLEEF.md` 6.5); null and masked-off lanes blended to a harmless argument before the library call, since a masked math operator computes every lane and blends after (`READING_JDK.md` 2.7); the oracle and fuzzers comparing a contracted value within the bound, a NaN never passing against a number, and a composition bit for bit against a C2-warmed library reference; the differential suites' configuration-on arm; question 2 applies to this mode only, does not block 356 to 358, and stays the owner's; `SCOPE_STANDARD_MODE.md` 3.4 becomes the mode's entry. Census reading (`VARKA-376.md` 9, 20 October 2026, laptop): every `Double` math operator is intrinsic and allocation-free at 512 bits; at 256 and 128 bits `POW` has no vector stub, so the loop never reaches the library call and runs the Java fallback (the canary's finding), which is the form of `pow` at those species in the opt-in mode until a host shows otherwise. **Done when** with the configuration off no kernel holds a library call and every exact form admitted through the test hook is bit-identical to Spark by the three tests; with it on, the library operator appears only on a binding with a contract entry; a test shows a within-bound comparison catches a lane two steps further out and refuses every pair of opposite signs; the binding check passes on the x86 and Arm runners; and the dated corrections of `SCOPE_FUNCTIONS.md` 3, item 36 and `SCOPE_STANDARD_MODE.md` 3.4 record the exact default (*until 30 October 2026 the done-when asked for the configuration to decline the family when off, a test showing a within-bound comparison catches a lane two steps further out, and the dated corrections of `SCOPE_FUNCTIONS.md` 3 and item 36*) | item 36; owner's decision, 14 October 2026, superseded by the owner's decision of 30 October 2026 | medium | | 356 | **Started** (*20 November 2026*, built while the owner was away, not merged, `VARKA-356.md` 10, part 356a1 on `varka-356-trig`, ahead of 345b and 358a by the decisions recorded there; `sin`, `cos`, `tan`, `asin`, `acos`, `atan`, `sec`, `csc` and `cot` fuse over `DOUBLE` bit for bit, each lane passed to the method Spark's code calls (`Math` for the first three, `StrictMath` for the inverse three) by an unrolled extract, call and insert, the reciprocals Java's `/` over the call; a kernel with no baked lane count declines by name; `VarkaMathExactSuite` holds them to Spark's code over 2^24 sampled inputs and the fixed vectors, with the planted call of the other class caught on x86 and no allocation a batch; 12 coverage rows and the nine census lines; left: `atan2` (356a2, a `MathBinary` node), the fuzz productions, the live-word narrowing, the vectors files, the ports of `atan`, `atan2`, `asin` and `acos`, the opt-in entries, and the runner measurement against the baseline, owed). **Planned** (`VARKA-356.md`, 30 October 2026, with 357 and 358; the admission check: Spark's code calls `Math` for every function of the row, which on this x86 host differs from `StrictMath` for `sin`, `cos` and `tan` and agrees for `asin`, `acos`, `atan` and `atan2`, so the first form is a per-lane call of the method Spark's code reaches; `atan2`'s `+ 0.0` and the zero divisors of `csc` and `cot` change answers and are kept operation for operation; `results/VARKA-356-admission.txt`; the ports of `atan`, `atan2`, `asin` and `acos` are measured option arms after `exp`'s; 356a and two port pull request pairs). The trigonometric functions, exact by default, the opt-in contract as a second form (*30 October 2026, by the owner's word*, `VARKA-345.md` 2.1): `sin`, `cos` and `tan` by a per-lane `Math` call (`LANE_CALL`), and `sec`, `csc` and `cot` as `1.0 / LANE_CALL` of `Math.cos`, `sin` and `tan`, the divide a lane `DIV` (342); `asin`, `acos`, `atan` and `atan2` first by a per-lane `StrictMath` call, each with its fdlibm `PORT` arm, the default where it measures faster on the EPYC runners. **The opt-in form**, under `spark.sql.codegen.varka.math.ulpContract.enabled`: a function may take the library operator where its binding has a contract entry, each only after 367 has measured it. **Done when** each fuses bit for bit by `VARKA-345.md` 2.3's tests with a coverage row, and within its bound in the opt-in mode with a coverage row per host library, its exact values bit for bit (*until 30 October 2026 the row read "under the contract", each function "only after 367 has measured it", and the done-when asked for each to fuse within its stated bound with a coverage row per host library*) | items 35, 36 | medium | | 357 | **Started** (the baseline's nineteen sections are built and open as a pull request of 20 November 2026; `VARKA-356.md`, 30 October 2026, with 356 and 358; the admission check: `asinh` and `acosh` are Spark's own branches in `ExpressionImplUtils`, fused with one call a lane, each branch's `log` or `log1p` made only on the lanes that take it; `atanh` calls the bare `log1p`, with no null; `sinh` and `cosh` are fdlibm on every host and their ports reuse `exp`'s and `expm1`'s sequences; `tanh` is a per-lane `Math.tanh`; `results/VARKA-356-admission.txt`; 357a after 358a, and one port pull request pair). The hyperbolic functions, exact by default, the opt-in contract as a second form (*30 October 2026, by the owner's word*, `VARKA-345.md` 2.1): `sinh` and `cosh` first by a per-lane `StrictMath` call with their fdlibm `PORT` arms, the default where it measures faster on the EPYC runners; `tanh` by a per-lane `Math.tanh` call on every host; `asinh` and `acosh` as `ExpressionImplUtils`' branches, blended over the `log` and `log1p` nodes and the lane `SQRT` (342), and `atanh` as `0.5 * (LOG1P(x) - LOG1P(-x))`, Spark's compositions over those nodes in whichever exact form they take. **The opt-in form**, under `spark.sql.codegen.varka.math.ulpContract.enabled`: a function may take the library operator where its binding has a contract entry, each only after 367 has measured it; SLEEF binds no `TANH`, so on SLEEF hosts `tanh` keeps its exact form in the mode too (`READING_JDK.md` 2.5). **Done when** each fuses bit for bit by `VARKA-345.md` 2.3's tests, the compositions reproduced branch by branch, `tanh`'s saturation bit for bit, and within its bound in the opt-in mode (*until 30 October 2026 the row read "under the contract", `asinh`, `acosh` and `atanh` "as fdlibm's branch blends of three math calls per lane", each "only after 367 has measured it", and `tanh` on Arm a per-lane `Math.tanh` loop declined on SLEEF hosts unless measured faster; the done-when asked for each to fuse within its stated bound*) | items 35, 36 | medium | | 358 | **Planned** (`VARKA-356.md`, 30 October 2026, with 356 and 357; the admission check: the log family's null at `<= 0` (`<= -1` for `log1p`) is value-dependent and IEEE, null at `-0.0`, not at NaN, carried by the call node, which skips those lanes; `log(x)` with one argument never divides; `log2` divides by the folded bits of `StrictMath.log(2)`; `e_exp.c` was fetched with the owner's approval and its branches laid out for 345's template, every finite lane in `(-708.0498449419841, fromHi(0x40862E42))` computed in the vector body and the rest finished per lane, as the plan's admission results file records; 358a first, then 358b's measurement of `exp`'s port, then five port pull request pairs). The exponential, logarithmic, power and root functions, exact by default, the opt-in contract as a second form (*30 October 2026, by the owner's word*, `VARKA-345.md` 2.1): `exp`, `expm1`, `log`, `ln`, `log10`, `log1p`, `pow` and `hypot` first by a per-lane `StrictMath` call, each with its fdlibm `PORT` arm (`exp`'s template built by 345), the default where it measures faster on the EPYC runners; `log2` and the two-argument `log` as Spark's compositions over the `log` node (`LOG(x) / c` with `c = StrictMath.log(2.0)` folded at compile time, and `LOG(x) / LOG(b)`); `cbrt` by a per-lane `Math.cbrt` call. The exact `pow` is `StrictMath`'s, reproducing fdlibm `e_pow.c`'s weak branch in either exact form, so owner's decision A3's 636-ulp concern does not arise by default. **The opt-in form**, under `spark.sql.codegen.varka.math.ulpContract.enabled`, where a binding has a contract entry: `pow` by owner's decision A3, behind the guard on fdlibm's weak branch (`|y| > 2^31` and `||x| - 1| <= 2^-20` declines the batch; the branch's own thresholds are `0x1.00000_ffff_ffffp31`, `0x1.fffff_0000_0000p-1` and `0x1.00000_ffff_ffffp0`), its general-exponent kernel enabled on a host only after 367 has measured the guarded domain there, and fdlibm's exact exponents as exact nodes (`y == 2` as `x * x`; `y == 0.5` as `Math.sqrt(x + 0.0)` for `x >= -Double.MAX_VALUE`; `y == +-1` as `x` and `1.0 / x`), with Java's `pow(1, NaN)` and `pow(+-1, +-inf)` as NaN against C99's 1 in the exact table; on SLEEF hosts an output guard, a lane that comes back infinite from finite inputs declining the batch, because SLEEF 3.6.1, which the JDK bundles, sends `exp` and `pow` to infinity above 709.78271114955742909, below the true overflow point (section 10.1 item 1). **Done when** each fuses bit for bit by `VARKA-345.md` 2.3's tests, `log10` included, and in the opt-in mode within its bound, the `pow` guard's decline, the exact nodes and the SLEEF overflow band's decline tested bit for bit (*until 30 October 2026 the row read "under the contract" throughout, and the done-when asked for each to fuse within its stated bound, `log10` at its two steps*). Census reading (`VARKA-376.md` 9, 20 October 2026, laptop): `exp`, `log`, `log10`, `expm1`, `log1p`, `cbrt` and `sqrt` are intrinsic at every width; `pow` has no vector stub at 256 and 128 bits and runs the Java fallback there, which concerns the opt-in form only. | items 35, 36; owner's decision A3 | medium | diff --git a/sql/varka/plans/m8/VARKA-345.md b/sql/varka/plans/m8/VARKA-345.md index 44941bb6aa66..ba8496bb5483 100644 --- a/sql/varka/plans/m8/VARKA-345.md +++ b/sql/varka/plans/m8/VARKA-345.md @@ -1103,3 +1103,49 @@ format under `sql/varka/math/`, question 2's classification (3.8), the `--asm` h *Corrected 21 November 2026 (review of this part): the frame's tests run each helper over the double and long views at the base lane count and over null lanes at two and four lanes; the `FLOAT` and `INT` views are lowered and registered, and no kernel runs them yet.* + +### 10.3 345c: the ports after `exp`, one stacked part each (22 November 2026) + +Built in the owner's absence, as the brief named it: the next `PORT` arms the plan sequences +after `exp` on 345b's frame, the ones rows 357 (`sinh` and `cosh` reuse `exp`'s and `expm1`'s +sequences) and 358 (the log family) wait on. Each is a stacked part with a paired `vfdlibm` +branch, prepared locally and not pushed. Nothing here is a compiler arm: no SQL shape fuses a +port yet, which stays rows 357 and 358's (2.1's rule and the `mathPort` option, decision 6 of +10.2). + +**345c1, `expm1` (branch `varka-345c-expm1-r`, on master after #1609).** + +- `VarkaMathPort.expm1`, node for node `vfdlibm`'s `Expm1.expm1Blended`: every one of + s_expm1.c's seven forms chosen by `k` and its early returns computed in every lane and + blended, so no lane is finished by a call. The reduction is shared with `exp` + (`VarkaMathPort.reduce`, the library's L10), and `exp`'s expansion now builds through it with + the same nodes. +- The library holds the C's `int` words in int lanes; the port holds them in long lanes, as + `exp`'s port holds its high-word tests: `k`'s tests are long compares of `k` widened, and the + words `0x3ff00000-(0x200000>>k)` and `(0x3ff-k)<<20` are long arithmetic, the first by a + logical shift (AVX2 has no 64-bit arithmetic shift). That they are the C's words on the lanes + that read them is the paired `vfdlibm` change's lemma. +- `VarkaMathPortSuite` takes its tests over a list of ported functions, each with its + expansion, its three oracles (`StrictMath`, `VFdlibm` and the library's blended arm, read by reflection), its fixed + vectors and its draw range: `exp`'s tests are unchanged in what they check, and `expm1` gets the + same four (the sampled differential, the fixed vectors over nulls, lengths, three widths and no + byte budget, the reference evaluator, the depth caps) and its three planted faults + (`DROP_CORRECTION` drops `c`, `CONSTANT_OFF_BY_ONE_ULP` moves `ln2_hi` up, `THRESHOLD_MOVED` + moves `k > 56` to `k > 55`, as the library's are). Its fixed vectors are s_expm1.c's thresholds + and the edges of `k`'s forms (`k = 1`'s split at `r = -0.25`, and the first lanes of `k = 2`, + `20`, `56` and `57`), each with 64 neighbours each way in both signs, and the special values. +- Paired `vfdlibm` change: branch `varka-expm1-long-words` (worktree + `/home/max/proj/vfdlibm-345c2w`), `PROOFS.md` L15 "expm1's words in long lanes, as Varka emits + them" and its hinge test `ProofsTest.l15LongWordsAreExpm1sInts` (every `k` from -1100 to 1100); + the library's code does not move, so Varka's test-scope copy and its manifest do not either. + +Predictions (written before the run): the suite passes with every `expm1` lane bit-identical to +the three oracles; `expm1`'s expansion is deeper than `exp`'s 36 and within the port cap of 64. + +Measured (laptop, 20 November 2026, one targeted run): the suite passes, 9 tests, every `exp` and +`expm1` lane bit-identical to the three oracles on 2^24 sampled inputs a function and on the +fixed vectors at 2, 4 and 8 lanes and without a byte budget, NaN payloads included; each planted +fault caught. `expm1`'s expansion is 49 deep (`exp`'s 36). Both predictions held. The run took +about 457 seconds, against 46.9 s for `exp` alone in 10.2; the laptop was shared with other agents' JVMs +in this window and the run was not repeated, so the suite's cost is not established by it and is +owed a timing on an idle machine or CI. From 8050155af7bed784664ab9af766b4053325d89ed Mon Sep 17 00:00:00 2001 From: t Date: Sun, 22 Nov 2026 14:51:56 +0100 Subject: [PATCH 2/6] [VARKA-345] Run the port oracle against vfdlibm 0.2.0 The test-scope oracle moves from 0.1.0 to 0.2.0. VFdlibm.expm1 and the Expm1 blended arm the port suite reads give the same bits; 0.2.0 adds sinh, cosh and the inverse trigonometric ports and splits expm1 into a core and a rare mask without moving a result. Generated-by: Claude Code (Claude Sonnet 5.5) --- sql/catalyst/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/catalyst/pom.xml b/sql/catalyst/pom.xml index ec97520fb9ac..f880cac46e7e 100644 --- a/sql/catalyst/pom.xml +++ b/sql/catalyst/pom.xml @@ -173,7 +173,7 @@ io.github.vecbricks vfdlibm - 0.1.0 + 0.2.0 test From 657a739688d477e3e29d88862e0777af72e01f60 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 22 Nov 2026 14:56:19 +0100 Subject: [PATCH 3/6] [VARKA-345] Throw no Error from the port suite's reflection helpers Generated-by: Claude Code (Claude Sonnet 5.5) --- .../expressions/codegen/varka/VarkaMathPortSuite.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java b/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java index 2b8d1654ab76..601382e382be 100644 --- a/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java +++ b/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java @@ -120,7 +120,7 @@ private static Method blendedArm(String type, String method) { m.setAccessible(true); return m; } catch (ReflectiveOperationException e) { - throw new ExceptionInInitializerError(e); + throw new IllegalStateException(e); } } @@ -346,7 +346,7 @@ private static long[][] references(Fn fn, long[] xs, int length) { try { outBlended = ((DoubleVector) fn.blended().invoke(null, v, null)).toArray(); } catch (ReflectiveOperationException e) { - throw new AssertionError(e); + throw new IllegalStateException(e); } for (int j = 0; j < in.length && base + j < length; j++) { strict[base + j] = Double.doubleToRawLongBits(fn.strict().applyAsDouble(in[j])); From 3a18c3401e9446a36696074ced04c8dc10204324 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 22 Nov 2026 15:28:32 +0100 Subject: [PATCH 4/6] [VARKA-345] Compare the expm1 port to the blended arm, and draw its range by k's forms The port suite computed the library's blended arm and dropped its result, so the third oracle was never checked. The suite now returns it, and the sampled range of expm1 covers the forms of k. The plan names the 0.2.0 oracle. Generated-by: Claude Code (Claude Sonnet 5.5) --- .../codegen/varka/VarkaMathPortSuite.java | 9 ++++--- sql/varka/plans/m8/VARKA-345.md | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java b/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java index 601382e382be..2220356b13a0 100644 --- a/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java +++ b/sql/catalyst/src/test/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPortSuite.java @@ -82,7 +82,8 @@ private record Built(VarkaVectorIR root, long[] lits) {} /** * A ported function: its expansion, its oracles ({@code StrictMath}'s method, {@code VFdlibm}'s * and the library's blended arm, reached by reflection since its class is package-private), its - * fixed vectors and the range of draw 1, the domain where its result is finite and not a limit. + * fixed vectors and the range of draw 1, the domain where its result is finite and not a limit + * and, for {@code expm1}, where {@code k} takes each of its forms ({@code |x|} up to 56 ln 2). */ private record Fn(String name, BiFunction port, DoubleUnaryOperator strict, UnaryOperator library, Method blended, @@ -128,7 +129,7 @@ private static Method blendedArm(String type, String method) { VFdlibm::exp, blendedArm("Exp", "expBlended"), expFixedVectors(), -745.2, 709.8); private static final Fn EXPM1 = new Fn("expm1", (p, f) -> p.expm1(X, f), StrictMath::expm1, - VFdlibm::expm1, blendedArm("Expm1", "expm1Blended"), expm1FixedVectors(), -40.0, 709.8); + VFdlibm::expm1, blendedArm("Expm1", "expm1Blended"), expm1FixedVectors(), -38.8, 38.8); private static final List FUNCTIONS = List.of(EXP, EXPM1); @@ -334,6 +335,7 @@ void helpersMatchTheirDefinitions() { private static long[][] references(Fn fn, long[] xs, int length) { long[] strict = new long[length]; long[] library = new long[length]; + long[] blended = new long[length]; double[] in = new double[SPECIES.length()]; double[] out = new double[SPECIES.length()]; for (int base = 0; base < length; base += in.length) { @@ -351,9 +353,10 @@ private static long[][] references(Fn fn, long[] xs, int length) { for (int j = 0; j < in.length && base + j < length; j++) { strict[base + j] = Double.doubleToRawLongBits(fn.strict().applyAsDouble(in[j])); library[base + j] = Double.doubleToRawLongBits(out[j]); + blended[base + j] = Double.doubleToRawLongBits(outBlended[j]); } } - return new long[][] {strict, library}; + return new long[][] {strict, library, blended}; } private static final String[] ORACLES = {"StrictMath", "VFdlibm", "the blended arm"}; diff --git a/sql/varka/plans/m8/VARKA-345.md b/sql/varka/plans/m8/VARKA-345.md index ba8496bb5483..c537773140ba 100644 --- a/sql/varka/plans/m8/VARKA-345.md +++ b/sql/varka/plans/m8/VARKA-345.md @@ -1137,15 +1137,20 @@ port yet, which stays rows 357 and 358's (2.1's rule and the `mathPort` option, - Paired `vfdlibm` change: branch `varka-expm1-long-words` (worktree `/home/max/proj/vfdlibm-345c2w`), `PROOFS.md` L15 "expm1's words in long lanes, as Varka emits them" and its hinge test `ProofsTest.l15LongWordsAreExpm1sInts` (every `k` from -1100 to 1100); - the library's code does not move, so Varka's test-scope copy and its manifest do not either. + the library's code does not move. Varka's test-scope oracle is `vfdlibm` 0.2.0 from Maven + Central (0.2.0 adds `sinh`, `cosh` and the inverse trigonometric ports and splits `expm1` into + a core and a rare mask; `VFdlibm.expm1` and `Expm1.expm1Blended` give the same bits), so this + part moves the test-scope dependency from 0.1.0 and nothing else of the build. Predictions (written before the run): the suite passes with every `expm1` lane bit-identical to -the three oracles; `expm1`'s expansion is deeper than `exp`'s 36 and within the port cap of 64. - -Measured (laptop, 20 November 2026, one targeted run): the suite passes, 9 tests, every `exp` and -`expm1` lane bit-identical to the three oracles on 2^24 sampled inputs a function and on the -fixed vectors at 2, 4 and 8 lanes and without a byte budget, NaN payloads included; each planted -fault caught. `expm1`'s expansion is 49 deep (`exp`'s 36). Both predictions held. The run took -about 457 seconds, against 46.9 s for `exp` alone in 10.2; the laptop was shared with other agents' JVMs -in this window and the run was not repeated, so the suite's cost is not established by it and is -owed a timing on an idle machine or CI. +the three oracles; `expm1`'s expansion is deeper than `exp`'s 36 and within the port cap of 64; +the suite's cost on a quiet machine is under 3 times `exp`'s alone (10.2: 46.9 s), the second +function adding its own 2^24 samples and the blended arm's call a batch. + +Measured (laptop, 22 November 2026, on master after #1609 with `vfdlibm` 0.2.0, one run): the +suite passes, 11 tests, every `exp` and `expm1` lane bit-identical to `StrictMath` and `VFdlibm` +and to the blended arm on 2^24 sampled inputs a function and on the fixed vectors at 2, 4 and 8 +lanes, NaN payloads included; each planted fault caught. `expm1`'s expansion is 49 deep as measured on 20 November, and the suite holds it within the port cap (`exp`'s +36), so the first two predictions held. The earlier run of 20 November (457 s on a shared +laptop, before the review's changes to `exp`) is not a timing; the third prediction is scored +from the run's log in the pull request body. From e86bf16955b98541dd12a0f3ed6605715982cc76 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 22 Nov 2026 16:16:45 +0100 Subject: [PATCH 5/6] [VARKA-345] Score the port suite's time prediction Generated-by: Claude Code (Claude Sonnet 5.5) --- sql/varka/plans/m8/VARKA-345.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/varka/plans/m8/VARKA-345.md b/sql/varka/plans/m8/VARKA-345.md index c537773140ba..d2f628afdc3b 100644 --- a/sql/varka/plans/m8/VARKA-345.md +++ b/sql/varka/plans/m8/VARKA-345.md @@ -1152,5 +1152,6 @@ suite passes, 11 tests, every `exp` and `expm1` lane bit-identical to `StrictMat and to the blended arm on 2^24 sampled inputs a function and on the fixed vectors at 2, 4 and 8 lanes, NaN payloads included; each planted fault caught. `expm1`'s expansion is 49 deep as measured on 20 November, and the suite holds it within the port cap (`exp`'s 36), so the first two predictions held. The earlier run of 20 November (457 s on a shared -laptop, before the review's changes to `exp`) is not a timing; the third prediction is scored -from the run's log in the pull request body. +laptop, before the review's changes to `exp`) is not a timing; the third prediction held in one run (86.5 s, under the 141 s limit) and failed in the +next (175.1 s, the laptop shared), so the suite's cost is not established and is owed a timing +on an idle machine or the runners. From 0f6d7fe20117f6de89fdf637f5d1eddb2a5763a2 Mon Sep 17 00:00:00 2001 From: t Date: Sun, 22 Nov 2026 19:22:49 +0100 Subject: [PATCH 6/6] [VARKA-345] Write expm1's Q1 to Q5 with the shortest digits of their bits Error Prone's FloatingPointLiteralPrecision fails on the C's 21-digit literals, which carry more digits than a double holds. Each new literal names the same bits, given in the comment as in the exp constants. Generated-by: Claude Code (Claude Opus 5.5) --- .../expressions/codegen/varka/VarkaMathPort.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java index 865d7897e17f..7ddf1ff48441 100644 --- a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java +++ b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/codegen/varka/VarkaMathPort.java @@ -437,11 +437,11 @@ VarkaVectorIR exp(VarkaVectorIR x, Fault fault) { // ln2_hi, ln2_lo and invln2 are e_exp.c's O_THRESHOLD, LN2HI_0, LN2LO_0 and INVLN2. static final double HUGE = 1.0e+300; static final double TINY = 1.0e-300; - static final double Q1 = -3.33333333333331316428e-02; // BFA11111 111110F4 - static final double Q2 = 1.58730158725481460165e-03; // 3F5A01A0 19FE5585 - static final double Q3 = -7.93650757867487942473e-05; // BF14CE19 9EAADBB7 - static final double Q4 = 4.00821782732936239552e-06; // 3ED0CFCA 86E65239 - static final double Q5 = -2.01099218183624371326e-07; // BE8AFDB7 6E09C32D + static final double Q1 = -0.03333333333333313; // 0xBFA11111, 0x111110F4 + static final double Q2 = 0.0015873015872548146; // 0x3F5A01A0, 0x19FE5585 + static final double Q3 = -7.93650757867488e-05; // 0xBF14CE19, 0x9EAADBB7 + static final double Q4 = 4.008217827329362e-06; // 0x3ED0CFCA, 0x86E65239 + static final double Q5 = -2.0109921818362437e-07; // 0xBE8AFDB7, 0x6E09C32D /** {@code |x| >= 56*ln2}: the filter's outer test (line 146). */ static final int HX_56_LN2 = 0x4043687A;