[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master def6fa4246 2/2: Speed up string-lessp for multibyte strings

From: Stefan Monnier
Subject: Re: master def6fa4246 2/2: Speed up string-lessp for multibyte strings
Date: Sat, 08 Oct 2022 13:40:07 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

> Of course I was wrong! String data from purespace can be unaligned even for
> multibyte. Thanks for making me take another look. (Of course, angry SPARC
> users would have let me know eventually.)

[ Cue the "kill the purespace" song.  ]

> Rather than attempting to find and plug all cases where unaligned strings
> are produced, this part of the optimisation has now been restricted to
> platforms where unaligned accesses are safe using a architecture whitelist.

I haven't looked in detail at this code, but this reminds me of the code
I wrote to compute the hash of a string (`hash_string` in fns.c), where
I similarly want to use word operations rather than manipulate
individual bytes.  I ended up using `memcpy` which the compiler
helpfully turns into plain word-sized loads.  So we get code without
alignment or architecture assumptions and efficient code (even on
architectures that don't allow unaligned loads since the compiler can
still produce more efficient code than a byte-by-byte loop).

> It may still be a good idea to ensure aligned allocation since it allows for
> more vectorisation of string operations but then again, most commonly used
> architectures handle unaligned accesses well.

[ Over on comp.arch the general mood is that not supporting unaligned
  loads natively is a ridiculous mistake because it's so cheap to
  implement (and the software workarounds are much more costly in
  comparison).  ]


reply via email to

[Prev in Thread] Current Thread [Next in Thread]