[PATCH] elf: Replace memcmp with __memcmpeq for variable size

Wilco Dijkstra Wilco.Dijkstra@arm.com
Wed Feb 9 01:42:26 GMT 2022


Hi,

> I think the I-cache usage increase is only when '__memcmpeq' is
> partially implemented.
> In many applications 'memcmp' can be entirely replaced with
> '__memcmpeq' and '__memcmpeq'
> has a lower I-cache footprint than 'memcmp'. Although agree its best
> to get this into GCC.

Even in the best case, the savings are really marginal. On AArch64 it would
save about 56 bytes. For the most common sizes it will not make a difference
at all since caches work on whole cachelines.

To check performance I ran a __memcmpeq through the strstr benchmark
(since that stresses memcmp), and that only gave minor differences. So there
isn't a clear performance benefit either.

It gets worse for the other proposals, like resurrecting bzero. This was great in
the 80's and 90's when we had basic in-order cores without branch prediction
and every instruction avoided was a big win. But is trying to save one instruction
per memset call really a useful optimization on wide OoO cores?

Cheers,
Wilco


More information about the Libc-alpha mailing list