-1

I am trying to print out the value of an __m256i variable but I get a run-time error (file.exe has stopped working!). My CPU is Intel and supports AVX instructions. When I comment the cout line, the code runs. I am using Intel C++ compiler. what is the problem? Is there any other way to show the contents of __m256i variable. My code is as follows:

#include <iostream>
#include <iomanip>
#include "immintrin.h"

using namespace std;

int main()
{
    __m256i a;
    int i;

    a = _mm256_set_epi64x(1, 2, 3, 4);

    cout << setfill('0'); // fill with 0s

    for (i = 0; i < 4; i++) {

        cout << hex << setw(16) << _mm256_extract_epi64(a, i);

    }

    cout << endl;

    cin.get();

    return 0;
}
Paul R
  • 208,748
  • 37
  • 389
  • 560
Farhad
  • 29
  • 1
  • 6
  • 1
    What was it actually compiled to? Especially that extract, which is impossible without unrolling the loop – harold Mar 07 '18 at 13:46
  • Yes, It is compiled without any problem. By the way, the problem is with the cout not the extract instruction. The code does not work without the loop either (e.g. i = 0). – Farhad Mar 07 '18 at 14:00
  • Intel ICC (17 or 18) does not even compile this (on Linux at least). clang is the only compiler I have found that will unroll the loop to get compile-time constants for the extract index. What version of ICC are you using ? – Paul R Mar 07 '18 at 14:03
  • I use nodepad to type the code and then I use the ICC 18 to compile it (e.g. icl test.cpp) and then I run the exe file. My OS is windows 10 64bit. Anyway, is there any other way to show the content of the variable a? – Farhad Mar 07 '18 at 14:23
  • 3
    If you are using the [G2020 the spec sheet](https://ark.intel.com/products/71070/Intel-Pentium-Processor-G2020-3M-Cache-2_90-GHz) shows it doesn't support AVX. It only supports Intel® SSE4.1, Intel® SSE4.2 extensions. – Michael Petch Mar 07 '18 at 15:39
  • Maybe you are right. I used coreinfo.exe and it says it supports AVX. Perhaps this is the reason of the run-time error. I will run my code on my friend's computer on saturday and I will update the question. – Farhad Mar 07 '18 at 17:30
  • UPDATE: my code runs correctly on my friend's computer. The CPU of his computer is Intel Core i5 3570. I wonder why coreinfo.exe reports that my CPU (Intel G2020) supports AVX. Thank you all for the comments anyway. – Farhad Mar 10 '18 at 11:35
  • I have just found a code at https://msdn.microsoft.com/en-us/library/hskdteyh.aspx which reports the supported CPU instruction sets. – Farhad Mar 12 '18 at 13:36

1 Answers1

1

You can try to use next function to print content of __m256i vector:

#include <immintrin.h>
#include <iostream>
#include <iomanip>    

template<class T> inline void Log(const __m256i & value)
{
    const size_t n = sizeof(__m256i) / sizeof(T);
    T buffer[n];
    _mm256_storeu_si256((__m256i*)buffer, value);
    for (int i = 0; i < n; i++)
        std::cout << buffer[i] << " ";
}

int main()
{
    __m256i a = _mm256_set_epi64x(1, 2, 3, 4);
    Log<long>(a);
    return 0;
}
y.selivonchyk
  • 8,987
  • 8
  • 54
  • 77
ErmIg
  • 3,980
  • 1
  • 27
  • 40