Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAKbZUD2XSZ4MdoS0JoyhJU=1yxVQywqzpRTuLrMPusKtYgOoSA@mail.gmail.com>
Date: Thu, 29 Feb 2024 00:02:04 +0000
From: Pedro Falcato <pedro.falcato@...il.com>
To: musl@...ts.openwall.com
Cc: James Tirta Halim <tirtajames45@...il.com>
Subject: Re: [PATCH] add memcmpeq: memcmp that returns length of first mismatch

On Wed, Feb 28, 2024 at 11:18 PM Thorsten Glaser <tg@...bsd.de> wrote:
>
> Markus Wichmann dixit:
>
> >> > > +        for (; n >= sizeof(word) && *(word *)p1 == *(word *)p2; p1+=sizeof(word), p2+=sizeof(word), n-=sizeof(word));
>
> Very much UB.
>
> >4. All the other musl C code avoids misaligned word access. I don't know
> >which architecture/ABI doesn't allow it, but it is nevertheless the
>
> Almost all of them. i386/amd64 penalise it heavily and it can cause

Small note: This isn't quite true for remotely modern x86, unaligned
accesses are pretty cheap compared to extra branches, and this fact is
abused very frequently in optimized stringops implementations (see
every optimized memcpy - which use overlapping loads and stores,
effectively abusing unaligned mem ops).

-- 
Pedro

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.