Re: How to utilize the CVTDQ2PD instruction?

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

 



On Fri, Sep 7, 2012 at 5:05 AM, Henrik Mannerström
<henrik.mannerstrom@xxxxxxxxx> wrote:
>
> 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.

>   a.vd = __v2df(a.vi);

This is just a type cast of the vector as a whole.  It doesn't convert
the individual vector elements.

This program does what you want.

Ian

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 = _mm_cvtepi32_pd(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