When should I use __forceinline instead of inline?

前端 未结 12 1416
旧巷少年郎
旧巷少年郎 2021-01-01 09:34

Visual Studio includes support for __forceinline. The Microsoft Visual Studio 2005 documentation states:

The __forceinline keyword overrides the co

12条回答
  •  星月不相逢
    2021-01-01 09:48

    For SIMD code.

    SIMD code often uses constants/magic numbers. In a regular function, every const __m128 c = _mm_setr_ps(1,2,3,4); becomes a memory reference.

    With __forceinline, compiler can load it once and reuse the value, unless your code exhausts registers (usually 16).

    CPU caches are great but registers are still faster.

    P.S. Just got 12% performance improvement by __forceinline alone.

提交回复
热议问题