psadbw 这条指令,把两个向量寄存器按单个字节差值,然后相加。
高8个字节和低8个字节是分开的。
一 汇编代码
global sum
global sum256
sum:
xorpd xmm0, xmm0
movdqa xmm1, [rdi];//装载第一个参数
;vmovdqa [rsi], xmm1
psadbw xmm1, xmm0;//第一个参数和0x00000000 做sad
;movd [rsi], xmm1
vmovdqa [rsi], xmm1;//存储到内存
ret
2 C语言代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern void sum(unsigned char *buf, unsigned char *sum);
int main()
{
unsigned char data[16], dst[16];
memset(data, 0x02, 16);
memset(dst, 0x0, 16);
int ret = 0;
sum(data, dst);
fprintf(stderr, "ret ## \n");
for (int i = 0; i < 16; i++)
printf("%d ", dst[i]);
return 0;
}
三 执行输出
16 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0