emacs-devel
[Top][All Lists]
Advanced

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

HAVE_FAST_UNALIGNED_ACCESS


From: Robert Pluim
Subject: HAVE_FAST_UNALIGNED_ACCESS
Date: Thu, 30 Mar 2023 11:34:42 +0200

Sending this on behalf of Po Lu, whoʼs still having email problems:

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.

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.  Some RISCs have explicit ``load unaligned''
instructions, and others (such as MIPS and the Alpha) need special
sequences of instructions to perform such loads, and the compiler will
DTRT.

I would like to install such a change on emacs-29.  Emacs currently
crashes when built with various compilers performing pointer alignment
checks.



reply via email to

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