locked
Limiting <intrin.h> from including AVX/SSE5/4.1/4/3 intrinsics RRS feed

  • Question

  • <intrin.h> is used by the <xmemory0> header to get at InterlockedIncrement/Decrement.  On x64, the <intrin.h> header includes <immintrin.h> which defines AVX/SSE5/SSE4.1/SSE4/SSE3 headers.  That means that my fellow programmers can accidentally call into these routines and cause the app to crash on systems that don't support these instructions.  Our application only requires SSE2 or below.  How do I limit or eliminate this.  Most usage of intrin.h is to get at the atomics, but forcing the SSE intrinsics wholesale seems like a bad idea.

    <intrin.h>

    #if defined(_M_IX86) || defined(_M_X64)

    #include <immintrin.h>

    #include <ammintrin.h>

    #endif /* _M_IX86 || _M_X64 */

    <xmemory0>

    // ATOMIC REFERENCE COUNTING PRIMITIVES

     #ifndef _USE_ATOMIC_OPS

     #define _USE_ATOMIC_OPS (_HAS_CPP0X && _MULTI_THREAD)

     #endif /* _USE_ATOMIC_OPS */

      #if defined(_M_IX86) || defined(_M_X64) || defined(_M_CEE_PURE)

       #include <xatomic0.h>

       #include <intrin.h>

       #define _MT_INCR(mtx, x) _InterlockedIncrement(reinterpret_cast<volatile long *>(&x))

       #define _MT_DECR(mtx, x) _InterlockedDecrement(reinterpret_cast<volatile long *>(&x))

      #else /* defined(_M_IX86) || defined(_M_X64) || defined(_M_CEE_PURE) */

       #include <xatomic.h>

       #define _MT_INCR(mtx, x) _Inc_atomic_counter_explicit(x, memory_order_relaxed)

       #define _MT_DECR(mtx, x) _Dec_atomic_counter_explicit(x, memory_order_release)

      #endif /* defined(_M_IX86) || defined(_M_X64) || defined(_M_CEE_PURE) */

    • Moved by DavidLambMicrosoft employee Tuesday, August 28, 2012 11:36 PM Not a Win8 Store app topic (From:Building Metro style apps with C++ )
    • Moved by Jesse Jiang Wednesday, August 29, 2012 2:46 AM (From:Visual C++ General)
    Tuesday, August 28, 2012 7:05 AM

All replies

  • On 8/28/2012 3:05 AM, Alecazam wrote:

    <intrin.h> is used by the <xmemory0> header to get at InterlockedIncrement/Decrement.  On x64, the <intrin.h> header includes <immintrin.h> which defines AVX/SSE5/SSE4.1/SSE4/SSE3 headers.  That means that my fellow programmers can accidentally call into these routines and cause the app to crash on systems that don't support these instructions.  Our application only requires SSE2 or below.  How do I limit or eliminate this.

    I suppose you could define _INCLUDED_IMM and _INCLUDED_AMM in your project settings. That would effectively skip immintrin.h and ammintrin.h, correspondingly.


    Igor Tandetnik

    Tuesday, August 28, 2012 11:44 PM
  • Hi ,

     

    I think your issue should be raised in the Application Security for Windows Desktop  I believe they will know more information of this issue than us, and I will move this one to that forum.

     

    Thanks for your understanding,

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, August 29, 2012 2:46 AM
  • That blocks out those particular includes, but the file still defines all of the intrinsics below that.  That also doesn't let you include them later (or know if they were previously included).  The problem is that the file defines all intrinsics for all SSE/AVX versions.  At least on GCC, you control what SSE version you compile to, and then can include headers specifically for higher level SSE calls.

    These are SSE4.1 intrinsics right here from <intrin.h> itself.  Call these on a SSE4 machine or lower, and kaboom.  Win8 only requires SSE2.

    __MACHINEX86_X64(__m128i _mm_max_epi32(__m128i, __m128i))

    __MACHINEX86_X64(__m128i _mm_max_epi8(__m128i, __m128i))

    Wednesday, August 29, 2012 5:49 AM
  • I would also add that it's pretty easy to get the <intrin.h> on Win 8, since <string> includes <xmemory>.   

    Wednesday, August 29, 2012 5:50 AM