all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattias.engdegard@gmail.com>
To: Vibhav Pant <vibhavp@gmail.com>
Cc: Robert Pluim <rpluim@gmail.com>, Eli Zaretskii <eliz@gnu.org>,
	emacs-devel <emacs-devel@gnu.org>, Po Lu <luangruo@yahoo.com>
Subject: Re: HAVE_FAST_UNALIGNED_ACCESS
Date: Fri, 31 Mar 2023 18:57:41 +0200	[thread overview]
Message-ID: <F61281DA-2631-41DE-8006-BC13653BC7A2@gmail.com> (raw)
In-Reply-To: <94d3de92c50a96d9172f88462bf3bc9c2792600c.camel@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 829 bytes --]

30 mars 2023 kl. 13.38 skrev Vibhav Pant <vibhavp@gmail.com>:

> I had recently made a few modifications to this on master. There,
> Fstring_lessp in uses the macro UNALIGNED_LOAD_SIZE instead, which is
> defined to __sanitizer_unaligned_loadXX in lisp.h if:
> 
> * We're building with AddressSaniziter,
> * <sanitizer/common_interface_defs.h> is available, and
> * USE_SANITIZER_UNALIGNED_LOAD is defined.

Thank you for making this improvement earlier -- I think using memcpy would subsume __sanitizer_unaligned_loadXX, so I'm going with that in my patch.
Another approach would be to disable this poor man's vectorisation when the sanitiser is enabled but that shouldn't be necessary.

The vectorisation is still only made on specific platforms, of course.

Eli, would this patch be acceptable for emacs-29?


[-- Attachment #2: string-lessp-uni-multi.diff --]
[-- Type: application/octet-stream, Size: 942 bytes --]

diff --git a/src/fns.c b/src/fns.c
index f5f222c39c..292d6fc405 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -514,7 +514,23 @@ DEFUN ("string-lessp", Fstring_lessp, Sstring_lessp, 2, 2, 0,
   else
     {
       /* string1 unibyte, string2 multibyte */
-      ptrdiff_t i1 = 0, i2 = 0, i2_byte = 0;
+
+      ptrdiff_t nb1 = n;
+      ptrdiff_t nb2 = SBYTES (string2);
+      ptrdiff_t nb = min (nb1, nb2);
+
+      /* Skip identical ASCII-only prefixes, a word at a time.  */
+      typedef size_t word_t;
+      int ws = sizeof (word_t);
+      word_t msbits = (word_t)0x8080808080808080;
+      const word_t *w1 = (const word_t *) SDATA (string1);
+      const word_t *w2 = (const word_t *) SDATA (string2);
+      ptrdiff_t b = 0;
+      while (b < nb - ws + 1 && w1[b / ws] == w2[b / ws]
+	     && !(w1[b / ws] & msbits))
+	b += ws;
+
+      ptrdiff_t i1 = b, i2 = b, i2_byte = b;
       while (i1 < n)
 	{
 	  int c1 = SREF (string1, i1++);

  reply	other threads:[~2023-03-31 16:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30  9:34 HAVE_FAST_UNALIGNED_ACCESS Robert Pluim
2023-03-30 10:26 ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-03-30 11:09   ` HAVE_FAST_UNALIGNED_ACCESS Sam James
2023-03-30 12:18   ` HAVE_FAST_UNALIGNED_ACCESS Arsen Arsenović
     [not found]     ` <87v8ihu3t8.fsf@yahoo.com>
2023-03-31  7:15       ` HAVE_FAST_UNALIGNED_ACCESS Robert Pluim
2023-03-31  7:45       ` HAVE_FAST_UNALIGNED_ACCESS Arsen Arsenović
2023-03-31 17:29     ` HAVE_FAST_UNALIGNED_ACCESS Mattias Engdegård
2023-03-31 20:13       ` HAVE_FAST_UNALIGNED_ACCESS Arsen Arsenović
2023-03-30 10:28 ` HAVE_FAST_UNALIGNED_ACCESS Mattias Engdegård
2023-03-30 11:38 ` HAVE_FAST_UNALIGNED_ACCESS Vibhav Pant
2023-03-31 16:57   ` Mattias Engdegård [this message]
2023-03-31 17:59     ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-03-31 18:03       ` HAVE_FAST_UNALIGNED_ACCESS Mattias Engdegård
2023-03-31 18:12         ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-01  0:45         ` HAVE_FAST_UNALIGNED_ACCESS Po Lu
2023-04-01  5:43           ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-01  6:31             ` HAVE_FAST_UNALIGNED_ACCESS Po Lu
2023-04-01  6:39               ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-01  7:42                 ` HAVE_FAST_UNALIGNED_ACCESS Mattias Engdegård
2023-04-01  8:19                   ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-01  9:17                     ` HAVE_FAST_UNALIGNED_ACCESS Po Lu
2023-04-01 11:25                       ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-01 12:59                         ` HAVE_FAST_UNALIGNED_ACCESS Arsen Arsenović
2023-04-01 13:33                           ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-01 15:22                             ` HAVE_FAST_UNALIGNED_ACCESS Arsen Arsenović
2023-04-01 16:22                               ` HAVE_FAST_UNALIGNED_ACCESS Eli Zaretskii
2023-04-02  0:50                                 ` HAVE_FAST_UNALIGNED_ACCESS Po Lu
2023-04-02  0:48                             ` HAVE_FAST_UNALIGNED_ACCESS Po Lu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F61281DA-2631-41DE-8006-BC13653BC7A2@gmail.com \
    --to=mattias.engdegard@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=luangruo@yahoo.com \
    --cc=rpluim@gmail.com \
    --cc=vibhavp@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.