Intel® ISA Extensions
Use hardware-based isolation and memory encryption to provide more code protection in your solutions.

Disabling AVX

emmanuel_attia
Beginner
7,459 Views

Hi all,

Is there a way (under Windows 7) to disable the support of AVX.
I wan't to make sure that on a pre-SB machine I don't get "Illegal Instruction exception".
Currently I have to use another machine and it's a bit annoying.

I don't use the /QaXXX flags because the code is already taking very long to compile (so it's taken care of manually) and I want it to work on Microsoft compiler too (even if performances would be degraded of course ;) ).

So if there is some global flag to change to disable it (even if i need to reboot the computer), the information would be more than welcomed.

Thanks in advance !

0 Kudos
20 Replies
TimP
Honored Contributor III
7,346 Views

If you want your .exe to run on an earlier architecture than the one you build on, and don't need AVX, you should simply build with an appropriate value for /arch, e.g. /arch:SSE4.1  Microsoft gives you only the option /arch:SSE2 (default for X64 and also, for Intel, for 32-bit mode), even though all CPUs made in the last 10 years would support /arch:SSE3.

Running on Windows 7 without the AVX service pack doesn't guarantee to show problems with AVX instructions.

0 Kudos
Bernard
Valued Contributor I
7,346 Views

VS 2013 supports AVX  with /arch:AVX  option.

0 Kudos
emmanuel_attia
Beginner
7,346 Views

Hi guys,

So i think i was not clear.

I have an exe (we don't care what produced it). It has AVX code path and SSE4 code path and it's not supposed to run any AVX code when it's not supported.
I want to fully test my exe on my Ivy bridge, so I need to find a way to disable AVX (in the OS ? in the BIOS ?) so I'm sure in the SSE4 code path, there is only SSE4 code as expected.

Off-topic answers make all this thread confusing and reduce the probability that I eventually get an answer, if you don't understand the point of what I am doing, no one is forcing you to answer.

Best Regards

0 Kudos
TimP
Honored Contributor III
7,346 Views

iliyapolak wrote:

VS 2013 supports AVX  with /arch:AVX  option.

As does VS2012.  I meant the only non-AVX option would be SSE2.

0 Kudos
McCalpinJohn
Honored Contributor III
7,346 Views

I don't believe that it is possible to disable AVX support in the processor.  

To test your non-AVX code path on a machine that supports AVX, you will need to patch the run-time checks so that AVX *appears* to be unsupported.   Based on earlier experience with patching binaries, I think there is a good chance that all of the checks for AVX support will be identical code fragments, so it should be possible to build a script to patch your binary.  

This has been done before with checks for "Genuine Intel" in the string returned by the CPUID instruction, so it should be possible.  All you need to do is reverse the sense of the conditional branch instruction following the CPUID check for AVX support, which should be a simple overwrite of some bits with no change to the file size.   The project may or may not be easy, depending on whether the compiler inserts the check once or many times, and whether the checks are identical in every occurrence.

0 Kudos
emmanuel_attia
Beginner
7,346 Views

I already have what you describe (i use an env variable next to my cpuid wrapper)
Actually what i want exactly is to make sure that there is no AVX at all in the "non AVX" code path.
Some poor optimisation or symbol conflicts can lead to these issue and i need to track them.

In the meantime, i will use an "old" Xeon without AVX to make sure this hybrid binary works like a charm on a simple SSE4.2 machine :)

Thanks for the answer

0 Kudos
emmanuel_attia
Beginner
7,346 Views

Apparently the right way is to launch as admin:

bcdedit /set xsavedisable 1

Then reboot of course

I hope this thread will help ...

0 Kudos
Bernard
Valued Contributor I
7,346 Views

Tim Prince wrote:

Quote:

iliyapolak wrote:

VS 2013 supports AVX  with /arch:AVX  option.

 

As does VS2012.  I meant the only non-AVX option would be SSE2.

I misunderstood your post:)

0 Kudos
Bernard
Valued Contributor I
7,346 Views

For patching you can use IDA freeware version which will recompile the patched exe.

 

 

0 Kudos
Bernard
Valued Contributor I
7,346 Views

Beside reversing conditional statement you can also insert unconditional jump to non AVX code target.

0 Kudos
andysem
New Contributor III
7,346 Views

I think you could use SDE (http://software.intel.com/en-us/articles/intel-software-development-emulator) to lower capabilities of your CPU. I haven't tried it though.

0 Kudos
emmanuel_attia
Beginner
7,346 Views

@iliyapolak: offtopic ... again

@andysem: Good idea, I will give it a try
In the future it might be a much better and finer solution than bcdedit that, in my understanding, would disable every AVX instruction set.

0 Kudos
Bernard
Valued Contributor I
7,346 Views

>>>@iliyapolak: offtopic ... again>>>

Why do you think so?

Are not you trying to disable AVX code path execution in that exe?

>>>I have an exe (we don't care what produced it). It has AVX code path and SSE4 code path and it's not supposed to run any AVX code when it's not supported>>>

0 Kudos
emmanuel_attia
Beginner
7,346 Views

iliyapolak wrote:

>>>@iliyapolak: offtopic ... again>>>

Why do you think so?

Are not you trying to disable AVX code path execution in that exe?

>>>I have an exe (we don't care what produced it). It has AVX code path and SSE4 code path and it's not supposed to run any AVX code when it's not supported>>>

Because i'm trying to make sure that my exe works perfectly on a SSE4 machine even if there is an AVX code path into it. If i alter the exe, there is nothing to test. I need to deploy the same binary for 2 generation of machines.

SDE was exactly what i was looking for actually.

0 Kudos
Bernard
Valued Contributor I
7,346 Views

@emmanuel

Next time please express your intention more clearly.Btw , I thought that patching or reversing some cmp jmp instruction will suite your needs.

0 Kudos
emmanuel_attia
Beginner
7,346 Views

I'm sorry if i wasn't clear.
Thank you for spending time answering anyway.

Kind regards

0 Kudos
Bernard
Valued Contributor I
7,346 Views

It's ok.

You are welcome.

0 Kudos
Muharrem_G_
Beginner
7,346 Views

It is interesting to see how easily you've got misunderstood and I see you expressed what you ask crystal-clear even in the begining.  I needed exact same thing and desperately read all replies. Is so uncommon what you (and I) need???

0 Kudos
jimdempseyatthecove
Honored Contributor III
7,346 Views

Emmanuel, Muharrem,

Both of you are clear on your requests. You not only wish to generate non-AVX code, but you also need to verify that the generated code together with any 3rd party object codes, libraries, DLLs/.so, do not contain non-conforming code, and do so on a machine that supports AVX code.

One way to do this would be through use of an emulator. See: https://sourceforge.net/projects/ia32/

You may need to tweak the emulator to permit your test to run.

Also note, that this may not test all code paths through the application, which may be difficult to do.

A second alternative is to modify a Linker, possibly by modifying: https://android.googlesource.com/platform/bionic/+/android-4.2_r1/linker/linker.cpp

To perform a pseudo link, whilst verifying no instructions beyond those desired. The modified linker would not be able to scan code that is not in object form (e.g. self modifying code). However, the modified linker will examine all object code as opposed to the emulator only testing code that is executed under the test conditions.

Jim Dempsey

0 Kudos
jimdempseyatthecove
Honored Contributor III
5,571 Views

One further comment.

The emulator is not (necessarily) going to emulate the operating system. To do this, you might want to emulate a complete system. For this, consider looking at: https://github.com/unicorn-engine/unicorn

This will then require you to build a virtual hard disk containing the O/S and utilities desired for your target system (or attach a physical HD from your target system).

Jim Dempsey

0 Kudos
Reply