[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline memcmp



On Thu, Jul 23, 2026 at 08:49:13PM -0400, Brian Gerst wrote:
> Your suggestion is good, but should have a comment explaining why it's there
> to someone reading the code in the future.

I have this there now:

diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 6827551720dd..7bc34f9272fb 100644
--- a/arch/x86/boot/string.c
+++ b/arch/x86/boot/string.c
@@ -32,6 +32,11 @@
 int memcmp(const void *s1, const void *s2, size_t len)
 {
        bool diff;
+
+       /*
+        * Make sure ZF is properly set in the len==0 case because in it,
+        * RCX==0 and the REPE; CMPSB won't get executed.
+        */
        asm volatile("test %3, %3\n\t"
                     "repe cmpsb"
                     : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)


-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.