If I use the -mavx
flag with GCC (to use AVX instructions), but then run on a CPU that doesn't support AVX, what is the behavior? Does the program crash, produce undefined behavior, or something else?
Asked
Active
Viewed 719 times
2

jhourback
- 4,381
- 4
- 26
- 31
-
2Unsupported AVX instructions will generate and #UD (undefined) exception, crashing your program (if you don't handle the exception). – Margaret Bloom Mar 15 '21 at 20:40
-
It will crash, unless your code does not actually produce AVX code (e.g., if you don't do any floating point math and no vectorized integer math). – chtz Mar 15 '21 at 21:04
-
1@chtz: Another case when GCC will use `movdqa` or `movaps` (or `vmovdqa` with `-mavx`) is inline expansion of small or medium memset or memcpy, or copying a struct, or initializing an array or struct. This can easily happen even with `-O2` (no autovectorization) in pure integer code. – Peter Cordes Mar 16 '21 at 00:44
-
1If you compile in a way that actually makes AVX instructions execute, duplicate of [Illegal instruction from VS C++ on Windows](https://stackoverflow.com/q/59584105). But it sounds like you're really asking what if you compile with `-mavx`, in which case it's not *guaranteed* to use any SIMD at all. – Peter Cordes Mar 16 '21 at 00:47