1

I'm using AVX intrinsics, but since for everything other than _mm256 based intrinsics MSVC generates non-vex instructions, I need to compiler the whole source code with /arch:AVX. The rest of the project is compiled with /arch:SSE2, so that it works on older CPUs and I'm manually checking if AVX is available.

The source containing AVX code (compiled for AVX) includes a huge library of templates and other stuff, just to have the definitions. Is there a possibility that the compiler/linker decides to instantiate some template with AVX instructions, just because it has been included in this source as well? In that case it would make it crash on non-AVX processors

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
mrzacek mrzacek
  • 308
  • 2
  • 12
  • You'd better not share C++-ish stuff between modules with different compile options, lest you violate the one-definition rule. Treat it like you would a DLL, using plain C interfaces to cross the boundary, except that the various modules don't have their own namespaces for extern linkage, so your ability to use C++ inside is also constrained. – Ben Voigt Mar 31 '15 at 00:28
  • I created a test project hoping to answer your question, but it's not behaving as I'd expected (templates seems to be instantiated thought they don't need to)... I should answer this in a few hours, OR maybe open a new (bit different) question about it... – Marc.2377 Mar 31 '15 at 01:34
  • Thank you folks. The thing is, I'd do the classic "C" thingy if it would be possible/easy, but it's just dependent on lots of definitions and stuff, so it's quite problematic. And all that mess just because the compiler doesn't have any way to specify that I want "vex" instructions... @Marc.2377 please let me know what you find out. – mrzacek mrzacek Mar 31 '15 at 11:39
  • Of course. Btw, are you compiling via command line, or using Visual Studio? – Marc.2377 Mar 31 '15 at 12:09
  • Both. And also on Mac via LLVM, and also trying Intel Compiler. – mrzacek mrzacek Mar 31 '15 at 17:12

1 Answers1

0

Is there a possibility that the compiler/linker decides to instantiate some template with AVX instructions, just because it has been included in this source as well?

Yes, it may happen, as seen in my linked question. Check out the (other) good answers given there.

My preferred workaround was to modify the template to include a discriminative parameter, but it may be too much of a hassle if it's really a "huge library", just like using global definitions as you mentioned in your own answer.

Marc.2377
  • 7,807
  • 7
  • 51
  • 95