|
[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 2026-07-22 23:59, Jan Beulich wrote:
>>
>> Also, this is silly. Instead of adding a whole separate test, just do "test
>> %3,%3" before the repe to set ZF and let the REPE skip.
>
> Besides this, isn't the function effectively returning bool wrong anyway? This
> way you can use it for equal / not-equal comparisons, but not for sorting and
> alike.
>
There is no use case in the early code for sorting, and it seems rather broken
to burden the code with that.
That being said it probably should return bool explicitly (it makes no sense
for the prototype to be different than the internal variable.)
We could call it memneq() if someone really, really cares, I guess.
The early code is very size-sensitive, so I'm really not fond of the idea of
burdening it further. Perhaps something like:
A memory clobber is ugly here since no memory is actually modified, although
it probably doesn't affect code; "cc" is completely redundant with condition
code output operand.
static __always_inline bool
__inline_memcmp(const void *s1, const void *s2, size_t len)
{
bool diff;
if (__builtin_constant_p(len == 0)) {
if (!len)
return false;
asm volatile("repe cmpsb"
: "=@ccnz" (diff),
"+D" (s1), "+S" (s2), "+c" (len)
: : "memory");
} else {
/* Clear ZF beforehand in case len == 0 */
asm volatile("test %3,%3; repe cmpsb"
: "=@ccnz" (diff),
"+D" (s1), "+S" (s2), "+c" (len)
: : "memory");
}
return diff;
}
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |