Skip to content

Commit

Permalink
memcmp: Compress lines
Browse files Browse the repository at this point in the history
(cherry picked from commit f90d5d0)
Signed-off-by: LIU Hao <[email protected]>
  • Loading branch information
lhmouse committed Aug 1, 2024
1 parent a04fdbd commit 92a9b19
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions mcfgthread/memcmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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;
}

0 comments on commit 92a9b19

Please sign in to comment.