Why does gcc add this movss command only with _mm_set_ss?

Consider these two functions using SSE:

#include <xmmintrin.h>

int ftrunc1(float f) {
    return _mm_cvttss_si32(_mm_set1_ps(f));
}

int ftrunc2(float f) {
    return _mm_cvttss_si32(_mm_set_ss(f));
}

Both are the same in behavior for any input. But assembler output is different:

ftrunc1:
    pushl   %ebp
    movl    %esp, %ebp
    cvttss2si   8(%ebp), %eax
    leave
    ret

ftrunc2:
    pushl   %ebp
    movl    %esp, %ebp
    movss   8(%ebp), %xmm0
    cvttss2si   %xmm0, %eax
    leave
    ret

That is, it ftrunc2uses one movssextra command !

This is normal? Does it matter? If _mm_set1_psalways preferred _mm_set_ss, when you only need to set the bottom element?


The compiler used was GCC 4.5.2 s -O3 -msse.

+5
source share
2 answers

_mm_set_ssdisplayed directly in assembly instructions ( movss). But _mm_set1_psdoes not.

From what I saw in GCC, MSVC and ICC:

SSE, , " " - . , , . - , / .

_mm_set1_ps _mm_set_ps . , , , , .


, movss, , 3 . ( "" _mm_set_ss.)

+4

. - , mov cvttss2si, . , ? - ​​ 4 , / ( ). 4 ifetch, ftrunc1 10 , ftrunc2 14, , . % ebp cruft ( -fno-omit-frame-pointer?), -O3 -fomit-frame-pointer). , , , , , , ( , ) - .

, - ...

0

All Articles