Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

SIMD data and std::vector

$
0
0

With the Microsoft compiler, compiling in C++ standard compliance mode of 2017 or later, I can use SIMD data types for example in std::vector without custom allocators. When trying to use Intel compiler from Visual Studio this does not seem to work. (I am new to using the Intel compiler, so I may just be missing some option, but I think I have tried the standard version settings etc)

I have attached example code at the bottom of this message. The memory allocations of course vary, and often produce aligned results, even if not set really set up correctly. The define (commented out) on the first line seems to be the one controlling the behavior in Microsoft header files, if it is used, then the code works also with Intel compilers. As the defined symbol is in"compiler namespace", I guess defining it as a user is not a clean solution.

There are some compatibility issues between Visual Studio 2019 and Intel compiler, so I have done my testing with Visual Studio 2017.

 Eero

//#define __cpp_aligned_new 1
#include <stdio.h>
#include <xmmintrin.h>
#include <vector>

struct Test_S{
  __m128 v;
  float b;
};

int main(){
  fprintf(stderr,"Alignment requirement = %d\n",alignof(Test_S));
#ifdef __cpp_aligned_new
  fprintf(stderr,"__cpp_aligned_new defined\n");
#else
  fprintf(stderr,"__cpp_aligned_new not defined\n");
#endif
  std::vector<Test_S> a;
  a.push_back(Test_S());
  fprintf(stderr,"addr=%p\n",&(a[0].v));
  std::vector<Test_S> b;
  b.push_back(Test_S());
  fprintf(stderr,"addr=%p\n",&(b[0].v));
  std::vector<Test_S> c;
  c.push_back(Test_S());
  fprintf(stderr,"addr=%p\n",&(c[0].v));
}

 

TCE Level: 

TCE Open Date: 

Monday, January 20, 2020 - 21:07

Viewing all articles
Browse latest Browse all 1175

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>