优化图像校验

This commit is contained in:
SummerTail 2024-04-14 14:40:42 +08:00
parent 8ce49390b0
commit 86903c93aa

View File

@ -160,6 +160,7 @@
#include "sup.h" #include "sup.h"
#include "ass.h" #include "ass.h"
#include "abstract_lists.h" #include "abstract_lists.h"
#include <emmintrin.h> // 包含SSE指令集的头文件
/* AVIS input code taken from muxers.c from the x264 project (GPLv2 or later). /* AVIS input code taken from muxers.c from the x264 project (GPLv2 or later).
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@ -545,10 +546,33 @@ int detect_sse2 ()
int is_identical (stream_info_t *s_info, char *img, char *img_old) int is_identical (stream_info_t *s_info, char *img, char *img_old)
{ {
if (detect_sse2())
return asm_is_identical_sse2(s_info, img, img_old); // 按128位加载两个图像数据
else __m128i* ptr1 = (__m128i*)img1;
return is_identical_c(s_info, img, img_old); __m128i* ptr2 = (__m128i*)img2;
// 计算比较的次数以128位为单位
int num_iterations = size / 16;
// 逐一比较图像数据使用SSE指令进行并行比较
for (int i = 0; i < num_iterations; ++i) {
__m128i xmm1 = _mm_load_si128(ptr1 + i); // 加载128位数据
__m128i xmm2 = _mm_load_si128(ptr2 + i); // 加载128位数据
// 比较两个128位数据是否相等
__m128i cmp_result = _mm_cmpeq_epi8(xmm1, xmm2);
// 判断比较结果是否全为1
int result_mask = _mm_movemask_epi8(cmp_result);
// 如果存在不相等的元素返回0
if (result_mask != 0xFFFF) {
return 0;
}
}
// 如果所有元素都相等返回1
return 1;
} }
int is_empty (stream_info_t *s_info, char *img) int is_empty (stream_info_t *s_info, char *img)