Advertisement Jump to content
Sign in to follow this  

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
cl %CommonCompilerFlags% -D_CRT_SECURE_NO_WARNINGS %CodeDir%\octree_asset_builder.cpp /link %CommonLinkerFlags%

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 -LD /link %CommonLinkerFlags% -incremental:no -opt:ref -PDB:octree_%random%.pdb -EXPORT:GameInit -EXPORT:GameUpdateAndRender -EXPORT:GameProcessDebugData -EXPORT:GameSyncDebugStatePtrs
del lock.tmp
cl %CommonCompilerFlags% %CodeDir%\win32_octree.cpp /link %CommonLinkerFlags%



Share this post

Link to post
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

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 this post

Link to post
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 this post

Link to post
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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!