Perf: tighter pldexp 4-way split (tree multiply, vpmovsxdq expansion, drop pnegate)

libeigen/eigen!2527

Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
Rasmus Munk Larsen
2026-05-10 16:45:48 -07:00
co-authored by Rasmus Munk Larsen
parent 9046e3c38a
commit fddb6dcd3d
5 changed files with 77 additions and 62 deletions
+11
View File
@@ -1031,6 +1031,17 @@ void packetmath_real() {
data1[0] = Scalar(std::ldexp(Scalar(1.0), NumTraits<Scalar>::max_exponent() - 1));
data1[PacketSize] = Scalar(+NumTraits<Scalar>::min_exponent() - NumTraits<Scalar>::max_exponent());
CHECK_CWISE2_IF(PacketTraits::HasExp, REF_LDEXP, internal::pldexp);
// Near-max magnitude with small negative exponents. Regression guard for
// the 4-way scale-factor split: the remainder factor c2 = 2^(e-3*floor(e/4))
// is > 1 for e in {-1, -2, -5, -6, ...}, so the multiply tree must apply
// the downscale c1 before c2 -- otherwise (numext::abs(a)) * c2 spuriously
// overflows to inf for finite results like ldexp((numext::numeric_limits)
// <Scalar>::max(), -1).
for (int i = 0; i < PacketSize; ++i) {
data1[i] = (numext::numeric_limits<Scalar>::max)();
data1[i + PacketSize] = Scalar(-1 - (i % 8)); // -1, -2, ..., -8
}
CHECK_CWISE2_IF(PacketTraits::HasExp, REF_LDEXP, internal::pldexp);
}
for (int i = 0; i < size; ++i) {