4
GCC下面生成此代碼爲隨機播放():GCC擴展ASM語法:負載128位內存位置作爲源
movaps xmm0,XMMWORD PTR [rip+0x125]
pshufb xmm4,xmm0
在理想情況下,這應該是:
pshufb xmm4,XMMWORD PTR [rip+0x125]
什麼是擴展ASM語法來生成這個單一指令?
非常感謝, 亞當
PS:該註釋固有產生用於該實施例中的最佳代碼。這通常不起作用(GCC可能會在全局寄存器變量的情況下生成不必要的寄存器副本)。
#include <stdint.h>
typedef int8_t xmm_t __attribute__ ((vector_size (16)));
const xmm_t xmm_shuf={128, 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15};
register xmm_t xmm __asm__("xmm4");
#define NTL ".intel_syntax noprefix\n"
#define ATT ".att_syntax\n"
void shuffle() {
//xmm=__builtin_ia32_pshufb128(xmm, xmm_shuf);
__asm__(NTL"pshufb %0, %1\n"ATT : "=x" (xmm) : "x" (xmm_shuf));
}
int main() {
}
$ GCC -Os -std = gnu99 -msse4.1 -flax-矢量轉換pshufb_128bit_constant.c & & objdump的-d -m I386:X86-64:英特爾的a.out |更少
0000000000400494 <shuffle>:
400494: 0f 28 05 25 01 00 00 movaps xmm0,XMMWORD PTR [rip+0x125] # 4005c0 <xmm_shuf+0x10>
40049b: 66 0f 38 00 e0 pshufb xmm4,xmm0
4004a0: c3 ret
非常感謝克里斯!我被英特爾語法難倒了。非常感謝您的幫助。 – 2010-02-02 04:06:19