Skip to content

AVX512 implementation of Packet8d pldexp is wrong but never used

Summary

AVX512/PacketMath.h implements own vectorized version of std::ldexp called pldexp for Packet8d but packet_traits<double> are missing HasExp flag so in fact this implementation is never used. I tried it and it produces wrong results in 3rd, 4th, 5th and 6th entry of the output vector.

Environment

  • Operating System : Linux
  • Architecture : x64
  • Eigen Version : 69adf26a
  • Compiler Version : 9.3.0
  • Compile Flags : -mfma -mavx512f -mavx512dq
  • Vector Extension : AVX512

Minimal Example

// g++ -I path/to/eigen -mfma -mavx512f -mavx512dq example.cpp 
#include <immintrin.h>
#include <string>
#include <Eigen/Core>
#include <cmath>
#include <iostream>

using namespace std;
using namespace Eigen::internal;

template<typename Packet, typename ElemTy>
void print(string msg, Packet v) {
  ElemTy dest[8];
  memcpy(dest, &v, sizeof(dest));
  cout << msg << "[";
  for (int i = 0; i < 7; i++)
    cout << dest[i] << ", ";
  cout << dest[7] << "]\n";
}

int main() {
  Packet8d a = _mm512_set_pd(-0.858243, -0.7827334, 0.266292, 0.525552, -0.618294, -0.717659, 0.498003, 0.822796);
  Packet8d exp = _mm512_set_pd(0, -3, -2, 1, -1, -4, -3, -3);
  print<Packet8d, double>("result:", pldexp(a, exp));
  cout << "ref: [";
  for (int i = 0; i < 7; i++)
    cout << std::ldexp(a[i], exp[i]) << ", ";
  cout << std::ldexp(a[7], exp[7]) << endl;
  return 0;
}

Steps to reproduce

  1. compile and execute code above

What is the current bug behavior?

Nothing as it is not used.

What is the expected correct behavior?

pldexp from AVX512 PacketMath should be used and it's implementation fixed

Relevant logs

  • Have a plan to fix this issue.