0
在我學習彙編(在x86_64上使用GCC)的過程中,我遇到了一些SSE示例,其中不是將C變量複製到寄存器中,而是將地址複製到EAX中。爲什麼這樣做時,你可以這樣做:爲什麼在ASM中指定變量的地址而不是將其複製到寄存器中?
typedef float v4sf __attribute__((vector_size(16)));
typedef union {
v4sf v;
float f[4];
} Vec4;
Vec4 vector.v = (v4sf){ 64.1,128.2,256.3,512.4 };
float blah = 2.2;
__asm__("movups %0, %%xmm0 \n\t"
"movups %1, %%xmm1 \n\t"
"shufps $0x00, %%xmm1, %%xmm1 \n\t"
"mulps %%xmm1, %%xmm0 \n\t"
"movups %%xmm0, %0 \n\t"
: "+m"(vector)
: "m"(blah)
: "%xmm0","%xmm1"
);
是否複製載體導入XMM0(而不是保持它在內存中)造成的性能損失?
以下是我在談論的一個例子(這是英特爾的語法):
void powf_schlickSSE(const float * a, const float b, float * result){
__asm {
mov eax, a //load address of vector
movss xmm0, dword ptr [b] //load exponent into SSE register
movups xmm1, [eax] //load vector into SSE register
shufps xmm0, xmm0, 0 //shuffle b into all floats
movaps xmm2, xmm1 //duplicate vector
mov eax, result //load address of result
mulps xmm1, xmm0 //xmm1 = a*b
subps xmm0, xmm1 //xmm0 = b-a*b
addps xmm0, xmm2 //xmm2 = b-a*b+a
rcpps xmm0, xmm0 //xmm1 = 1/(b-a*b+a)
mulps xmm2, xmm0 //xmm0 = a * (1/(b-a*b+a))
movups [eax], xmm2 //store result
}
}
你能告訴我們原始的代碼/程序集有你描述的行爲嗎?很難確切地說出你在問什麼。 – Mysticial
當然,我在英特爾語法中添加了一個示例。 – Synthetix
該組件絕對不是最佳選擇。現在,除非確定可以擊敗編譯器,否則只能使用內在函數。 – Mysticial