emacs-devel
[Top][All Lists]
Advanced

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

Re: HAVE_FAST_UNALIGNED_ACCESS


From: Eli Zaretskii
Subject: Re: HAVE_FAST_UNALIGNED_ACCESS
Date: Thu, 30 Mar 2023 13:26:58 +0300

> From: Robert Pluim <rpluim@gmail.com>
> Cc: Po Lu <luangruo@yahoo.com>
> Date: Thu, 30 Mar 2023 11:34:42 +0200
> 
> Fstring_lessp has:
> 
> /* Check whether the platform allows access to unaligned addresses for
>    size_t integers without trapping or undue penalty (a few cycles is OK).
> 
>    This whitelist is incomplete but since it is only used to improve
>    performance, omitting cases is safe.  */
> #if defined __x86_64__|| defined __amd64__    \
>     || defined __i386__ || defined __i386     \
>     || defined __arm64__ || defined __aarch64__       \
>     || defined __powerpc__ || defined __powerpc       \
>     || defined __ppc__ || defined __ppc               \
>     || defined __s390__ || defined __s390x__
> #define HAVE_FAST_UNALIGNED_ACCESS 1
> #else
> #define HAVE_FAST_UNALIGNED_ACCESS 0
> #endif
> 
> but even if unaligned access is normally permitted by a machine, it is
> still undefined behavior to dereference an unaligned pointer.

This is incorrect.  There's nothing undefined about x86 unaligned
accesses.  C standards can regard this as UB, but we are using
machine-specific knowledge here (and Emacs cannot be built with a
strict adherence to C standards anyway).

> Instead, HAVE_FAST_UNALIGNED_ACCESS and UNALIGNED_LOAD_SIZE should be
> removed and memcpy used instead:
> 
>   word_t a, c;
> 
>   memcpy (&a, w1 + b / ws, sizeof a);
>   memcpy (&c, w2 + b / ws, sizeof c);
> 
> doing so will make the compiler itself generate the right sequence of
> instructions for performing unaligned accesses, normally with only a few
> cycles penalty.

We don't want that penalty here, that's all.

> I would like to install such a change on emacs-29.

No, please don't.

> Emacs currently crashes when built with various compilers performing
> pointer alignment checks.

Details, please.  Which compilers, on what platforms, for what target
architectures, etc.  Unconditionally removing the fast copy there is a
non-starter.



reply via email to

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