# C++ Visual Studio 2013 missing some AVX instructions

## Recommended Posts

Hey guys,

I've been coding a project using AVX and I got to a point where I needed to use the _mm256_cvtss_f32() instruction. I have AVX2 checked off in my compile commands and other AVX instructions compile and run correctly, but when I write _mm256_cvtss_f32(), the compiler tells me the function cannot be found. I made sure I included immintrin.h and when I go to immintrin.h, the function isn't defined there, but online, it says Visual Studio 2013 supports AVX2. Below I put the build commands I use for my project, does anyone know how to make Visual Studio 2013 have all of the AVX instructions? Thanks in advance.

@echo off

set CodeDir=..\code
set OutputDir=..\build_win32

set CommonCompilerFlags=-Od -arch:AVX2 -MTd -nologo -fp:fast -fp:except- -Gm- -GR- -EHa- -Zo -Oi -WX -W4 -wd4127 -wd4201 -wd4100 -wd4189 -wd4505 -wd4324 -Z7 -FC
set CommonCompilerFlags=-DOCTREE_DEBUG=1 -DOCTREE_WIN32=1 %CommonCompilerFlags%
set CommonLinkerFlags=-incremental:no -opt:ref user32.lib gdi32.lib Winmm.lib opengl32.lib

IF NOT EXIST %OutputDir% mkdir %OutputDir%

pushd %OutputDir%

del *.pdb > NUL 2> NUL

REM Asset File Builder

REM For VS 2017, for some reason it needs a path to gl even tho it knows where it is...

REM 64-bit build
echo WAITING FOR PDB > lock.tmp
cl %CommonCompilerFlags% %CodeDir%\octree.cpp -Fmoctree.map -LD /link %CommonLinkerFlags% -incremental:no -opt:ref -PDB:octree_%random%.pdb -EXPORT:GameInit -EXPORT:GameUpdateAndRender -EXPORT:GameProcessDebugData -EXPORT:GameSyncDebugStatePtrs
del lock.tmp

popd

##### Share on other sites
On 5/9/2018 at 5:53 PM, D.V.D said:

how to make Visual Studio 2013 have all of the AVX instructions?

Do you have this defined?

#if defined(_MSC_VER) && _MSC_VER >= 1700 //Visual Studio 2013
#define AVX2_ENABLE
#endif

Also, you should know the compiler doesn't support every CPU instruction through intrinsics. You should check the list before doing this type of thing.

While it can be fun to experiment and learn about those tools and CPU-specific operations, be wary about using them for commercial projects. They are disastrous to get wrong and they have many subtle issues you might not know about. It is easy to write code that happens to work for your own computer but is buggy for the general case across all different CPUs.

##### Share on other sites

That link is what I was looking for, looks like visual studio 2013 just doesn't support that instruction.

Out of interest, what do you mean they can be disastrous? If a CPU doesn't support some x86 instruction, the program just crashes but all CPU's that support AVX should work fine right?

##### Share on other sites

Yes, it crashes. It'd consider a 100% crash situation with no workaround (apart from running on a different computer) disastrous.

And all of them should work fine if you wrote all the code correctly, and if the compiler handled everything around it correctly.

Just be aware of that for broad release. The original AVX has been around for a decade and still isn't supported by about one in five game machines. AVX2 is probably closer to 50% adoption rate, although they don't have the number specifically on the Steam survey.

## Create an account

Register a new account

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634151
• Total Posts
3015827
×