From 92a9b195fad3d2b1072cdc7f92d966a8325fdec0 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Thu, 25 Jul 2024 22:24:35 +0800 Subject: [PATCH] memcmp: Compress lines (cherry picked from commit f90d5d009687168f77779a3efced672a807f0f05) Signed-off-by: LIU Hao --- mcfgthread/memcmp.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mcfgthread/memcmp.c b/mcfgthread/memcmp.c index 1799f6817..3a795b795 100644 --- a/mcfgthread/memcmp.c +++ b/mcfgthread/memcmp.c @@ -17,10 +17,10 @@ int __cdecl memcmp(const void* src, const void* cmp, size_t size) { - int diff = 0; + int diff; const uint8_t* psrc = src; const uint8_t* pcmp = cmp; - size_t dp = size; + size_t t = size; #if defined __i386__ || defined __amd64__ /* Perform string comparison with hardware. */ @@ -30,14 +30,13 @@ memcmp(const void* src, const void* cmp, size_t size) "setnz al; " /* EAX = 0 if equal, 1 if less or greater */ "sbb ecx, ecx; " /* ECX = 0 if equal or greater, -1 if less */ "or eax, ecx; " - : "=a"(diff), "+S"(psrc), "+D"(pcmp), "+c"(dp) : + : "=a"(diff), "+S"(psrc), "+D"(pcmp), "+c"(t) : : "memory"); #else /* Get the number of matching bytes. If there is a mismatch, get the * difference between the first pair of mismatching bytes. */ - dp = RtlCompareMemory(psrc, pcmp, dp); - if(dp != size) - diff = psrc[dp] - pcmp[dp]; + t = RtlCompareMemory(psrc, pcmp, t); + diff = (t == size) ? 0 : (psrc[t] - pcmp[t]); #endif return diff; }