Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Date: Wed, 22 Jan 2020 18:12:28 +0100
From: Petr Skocik <>
Subject: faster memcmp


I've noticed musl's implementation of memcmp was about way over times
slower than glibc's, which made memcpy-based comparisons of e.g.,
definitely contiguous structs actually quite a bit slower than applying
memcmp on them.

I've put together a memcmp that compares memory word by word if the
operands are aligned or identically misaligned (I figure the comparisons
of differently aligned objects is rare in real code).

It's still pretty compact, both in C (~40 LOC) and assembly (126 B @
x86_64 gcc -Os) and much closer to gcc's performance (less than twice
slower for comparison of 128B objects vs musl's 13 times).

If you like it, take it.

Petr Skocik

View attachment "my_memcmp.c" of type "text/x-csrc" (1599 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.