Re: [PATCH v7 2/5] x86/asm: add volatile, clobbers and zero-length check in inline memcmp
From: H. Peter Anvin
Date: Sat Jul 25 2026 - 22:58:35 EST
On July 25, 2026 3:34:45 AM PDT, David Laight <david.laight.linux@xxxxxxxxx> wrote:
>On Thu, 23 Jul 2026 20:49:13 -0400
>Brian Gerst <brgerst@xxxxxxxxx> wrote:
>
>...
>> I had originally thought that the test for RCX==0 was also at the end
>> of the loop, after the decrement. But a closer look at the
>> pseudo-code in the SDM does show that the test is at the start of the
>> loop. Starting with RCX==0 does indeed skip the comparison and does
>> not touch ZF. Your suggestion is good, but should have a comment
>> explaining why it's there to someone reading the code in the future.
>
>I have a feeling that was a change between the 8086 and 80286.
>I don't have an 8086 book (any more) but I'm sure I remember fixing
>bugs where %cx of zero caused 65536 iterations.
>(Fun to find because the vector table is 'first in the line to be
>overwritten.)
>
> David
No, but on the Z80 0 meant 64K.