How to utilize the CVTDQ2PD instruction?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello!

If I understand the Intel reference correctly, the CVTDQ2PD should allow
me to convert two 64 bit integers into two 64 bit doubles in one blow.
How should I write this in gcc C/C++?

Program 1 uses casting to illustrate the point, it outputs 0 and 1. 
Program 2 was my naive attempt to use vectorization, it outputs 0 and
4.94066e-324, which is _not_ what I intended.

Best regards,
Henrik Mannerström


Program 1:

#include <iostream>

typedef union {
  int long long i[2];
  double d[2];
} v_t;

int main(void) {
  v_t a;
 
  for (int k=0;k!=2;k+=1) {
        a.i[k] = k;
  }

  for (int k=0;k!=2;k+=1) {
    a.d[k] = double(a.i[k]);
  }

  for (int k=0;k!=2;k+=1) {
    std::cout << a.d[k] << std::endl;
  }

  return 0;
}


Program 2:

extern "C" {
#include <immintrin.h>
}
#include <iostream>

typedef union {
  __v2df vd;
  __v2di vi;
  int long long i[2];
  double d[2];
} v_t;

int main(void) {
  v_t a;
 
  for (int k=0;k!=2;k+=1) {
        a.i[k] = k;
  }

  a.vd = __v2df(a.vi);

  for (int k=0;k!=2;k+=1) {
    std::cout << a.d[k] << std::endl;
  }

  return 0;
}



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux