1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| #include <stdio.h>
/** GCC -o ins inlinemmx.c **/
int main(int argc,char *argv[])
{
int i;
int result;
short a[] = {1, 2, 3, 4, 5, 6, 7, 8};
short b[] = {1, 1, 1, 1, 1, 1, 1, 1};
printf("...with MMX instructions...\n");
/*首先,将点积合累积寄存器清零,实际缺省就为0?*/
asm("pandn %%mm5,%%mm5;":;
/*读入a, b,每四对数相乘后分两组相加,形成两组和*/
/*这里的循环控制是C在做*/
for(i = 0; i < sizeof(a)/sizeof(short); i += 4){
asm("movq %0,%%mm0;\
movq %1,%%mm1;\
pmaddwd %%mm1,%%mm0;\
paddd %%mm0,%%mm5; #相乘后相加 "
:
: "m" (a), "m" (b));
}
/*将两组和分离,并相加*/
asm("movq %%mm5, %%mm0;\
psrlq $32,%%mm5;\
paddd %%mm0, %%mm5;\
movd %%mm5,%0;\
emms"
:"=r" (result)
;
printf("result: 0x%x\n", result);
//这里结果为0x24
return(0);
}
|