如何從 SSE 中獲得最大速度? (How do you get maximal speed out of SSE?)


問題描述

如何從 SSE 中獲得最大速度? (How do you get maximal speed out of SSE?)

What are the best settings for stuff like MXCSR? Which rounding mode is fastest? On what processors? Is it faster to enable signalling NaNs so I get informed when a computation results in a nan, or does this cause slowdowns in non‑NaN computations?

In summary, how do you get the maximum of speed out of tight inner SSE loops?

Any related x87 floating‑point speed advice also welcome.

‑‑‑‑‑

參考解法

方法 1:

Use Flush‑to‑zero and Denormals‑are‑zero modes: they are intended for speed at a precision cost that you probably won't notice.

I doubt that different rounding modes have different costs. Round‑to‑nearest is hardest in theory, but in a hardware implementation, I would guess the additional transistors to do it in the same number of cycles are probably there anyway, and are just unused for directed rounding.

Signaling NaNs do not slow down non‑NaN computations.

Set the control flags word only once before your computation: changing it during the computation will dwarf any savings you achieve.

方法 2:

If you computation is likely to encounter denormals, and accuracy of very small values is not important to your computation, then by all means turn on FZ and DAZ (once, at the start of your computation; don't touch the MXCSR more than necessary).  They won't make any difference if your computation doesn't involve denormal values, but if it does, the difference can be quite significant.

None of the other MXCSR bits have any effect on performance at all.

The only x87‑related performance advice is: don't use the x87 unit. Do your computations in SSE instead whenever possible.

(by FeepingCreaturePascal CuoqStephen Canon)

參考文件

  1. How do you get maximal speed out of SSE? (CC BY‑SA 3.0/4.0)

#sse #assembly #x87 #x86 #optimization






相關問題

SSE:如果不為零則倒數 (SSE: reciprocal if not zero)

使用 SSE2 模擬 packusdw 功能 (Simulating packusdw functionality with SSE2)

什麼會導致 _mm_setzero_si128() 到 SIGSEGV? (What would cause _mm_setzero_si128() to SIGSEGV?)

ARM NEON 的 SSE _mm_movemask_epi8 等效方法 (SSE _mm_movemask_epi8 equivalent method for ARM NEON)

使用 simd 指令時,32 位圖像處理是否比 24 位圖像處理快? (Is 32 bit image processing faster than 24 bit image processing when simd instructions are used?)

điều phối cpu cho studio trực quan cho AVX và SSE (cpu dispatcher for visual studio for AVX and SSE)

如何將內存中的 96 位加載到 XMM 寄存器中? (How to load 96 bits from memory into an XMM register?)

x86中“非臨時”內存訪問的含義是什麼 (What is the meaning of "non temporal" memory accesses in x86)

現代編譯器如何使用 mmx/3dnow/sse 指令? (How do modern compilers use mmx/3dnow/sse instructions?)

如何讓 ICC 編譯器在內循環中生成 SSE 指令? (How do you get the ICC compiler to generate SSE instructions within an inner loop?)

如何從 SSE 中獲得最大速度? (How do you get maximal speed out of SSE?)

XMM 寄存器可以用來做任何 128 位整數數學嗎? (Can XMM registers be used to do any 128 bit integer math?)







留言討論