gpt4 book ai didi

从 SIMD SSE 内部指令转换为等效的 C 代码

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:38 25 4
gpt4 key购买 nike

我得到了将 SIMD SSE 指令转换为等效 C 代码的任务...代码是这样的(I1_block_addr-- 是一个 uint8_t,esc_offset_1 是一个 32 位整数。)

      __m128i xmm1 = _mm_load_si128((__m128i*)(I1_block_addr+desc_offset_1));
__m128i xmm6 = _mm_load_si128((__m128i*)(I2_block_addr+desc_offset_1));

xmm6 = _mm_sad_epu8(xmm1,xmm6);

我做的是

 char *c1;
char xmm1[16],xmm6[16];
short xmm6s[16]

//for loding 16 byte
c1=( char* )( I1_block_addr + desc_offset_1 );
memcpy( xmm1 , c1 , 16 );

c1=( char* )( I2_block_addr + desc_offset_1 );
memcpy( xmm6 , c1 , 16 );

xmm6s[0] = (short) ( abs(xmm1[0]-xmm6[0]) + abs(xmm1[1]-xmm6[1]) + abs(xmm1[2]-xmm6[2]) + abs(xmm1[3]-xmm6[3]) + abs(xmm1[4]-xmm6[4]) + abs(xmm1[5]-xmm6[5]) +
abs(xmm1[6]-xmm6[6]) + abs(xmm1[7]-xmm6[7]) );

xmm6s[1] = 0; xmm6s[2] = 0; xmm6s[3] = 0;

xmm6s[4] = (short) ( abs(xmm1[8]-xmm6[8]) + abs(xmm1[9]-xmm6[9]) + abs(xmm1[10]-xmm6[10]) + abs(xmm1[11]-xmm6[11]) + abs(xmm1[12]-xmm6[12]) +
abs(xmm1[13]-xmm6[13]) + abs(xmm1[14]-xmm6[14]) + abs(xmm1[15]-xmm6[15]) );

xmm6s[5] = 0; xmm6s[6] = 0; xmm6s[7] = 0;

我没有收到任何错误,但图像质量正在下降。请指出代码的哪一部分是错误的以及如何更正它。

最佳答案

代码看起来或多或少没问题 - 我认为您只需要将 char/short 类型更改为适当的无符号类型:

#include <stdint.h>

uint8_t *c1;
uint8_t xmm1[16], xmm6[16];
uint16_t xmm6s[8];

c1 = I1_block_addr + desc_offset_1;
memcpy(xmm1, c1, 16);

c1 = I2_block_addr + desc_offset_1;
memcpy(xmm6, c1, 16);

xmm6s[0] = (uint16_t) ( abs(xmm1[0]-xmm6[0]) + abs(xmm1[1]-xmm6[1]) + abs(xmm1[2]-xmm6[2]) + abs(xmm1[3]-xmm6[3]) +
abs(xmm1[4]-xmm6[4]) + abs(xmm1[5]-xmm6[5]) + abs(xmm1[6]-xmm6[6]) + abs(xmm1[7]-xmm6[7]) );

xmm6s[1] = xmm6s[2] = xmm6s[3] = 0;

xmm6s[4] = (uint16_t) ( abs(xmm1[8]-xmm6[8]) + abs(xmm1[9]-xmm6[9]) + abs(xmm1[10]-xmm6[10]) + abs(xmm1[11]-xmm6[11]) +
abs(xmm1[12]-xmm6[12]) + abs(xmm1[13]-xmm6[13]) + abs(xmm1[14]-xmm6[14]) + abs(xmm1[15]-xmm6[15]) );

xmm6s[5] = xmm6s[6] = xmm6s[7] = 0;

关于从 SIMD SSE 内部指令转换为等效的 C 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12048499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com