From: "H.J. Lu" <hjl.tools@gmail.com>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>,
"Carlos O'Donell" <carlos@systemhalted.org>
Subject: Re: [PATCH v8 1/3] String: Add support for __memcmpeq() ABI on all targets
Date: Thu, 21 Oct 2021 19:38:12 -0700 [thread overview]
Message-ID: <CAMe9rOqzVYmj7M7-h_OYiVP006M-+AC21f5zigs8rPegB6oyqA@mail.gmail.com> (raw)
In-Reply-To: <CAFUsyf+CpheC-93b8p-Afn_6vJVkqdh-rjSx429LrxXmKebqKA@mail.gmail.com>
On Thu, Oct 21, 2021 at 4:42 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Thu, Oct 21, 2021 at 5:50 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Thu, Oct 21, 2021 at 3:38 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >
> > > No bug.
> > >
> > > This commit adds support for __memcmpeq() as a new ABI for all
> > > targets. In this commit __memcmpeq() is implemented only as an alias
> > > to the corresponding targets memcmp() implementation. __memcmpeq() is
> > > added as a new symbol starting with GLIBC_2.35 and defined in string.h
> > > with comments explaining its behavior. Basic tests that it is callable
> > > and works where added in string/tester.c
> > >
> > > As discussed in the proposal "Add new ABI '__memcmpeq()' to libc"
> > > __memcmpeq() is essentially a reserved namespace for bcmp(). The means
> > > is shares the same specifications as memcmp() except the return value
> > > for non-equal byte sequences is any non-zero value. This is less
> > > strict than memcmp()'s return value specification and can be better
> > > optimized when a boolean return is all that is needed.
> > >
> > > __memcmpeq() is meant to only be called by compilers if they can prove
> > > that the return value of a memcmp() call is only used for its boolean
> > > value.
> > >
> > > All tests in string/tester.c passed. As well build succeeds on
> > > x86_64-linux-gnu target.
> > > ---
> > > string/Versions | 3 +++
> > > string/memcmp.c | 2 ++
> > > string/string.h | 16 ++++++++++++++++
> > > string/tester.c | 16 ++++++++++++++++
> > > sysdeps/aarch64/memcmp.S | 2 ++
> > > sysdeps/csky/abiv2/memcmp.S | 1 +
> > > sysdeps/i386/i686/memcmp.S | 2 ++
> > > sysdeps/i386/i686/multiarch/memcmp.c | 1 +
> > > sysdeps/i386/memcmp.S | 2 ++
> > > sysdeps/ia64/memcmp.S | 1 +
> > > sysdeps/mach/hurd/i386/libc.abilist | 1 +
> > > sysdeps/powerpc/powerpc32/405/memcmp.S | 1 +
> > > sysdeps/powerpc/powerpc32/power4/memcmp.S | 1 +
> > > sysdeps/powerpc/powerpc32/power7/memcmp.S | 1 +
> > > sysdeps/powerpc/powerpc64/le/power10/memcmp.S | 1 +
> > > sysdeps/powerpc/powerpc64/power4/memcmp.S | 1 +
> > > sysdeps/powerpc/powerpc64/power7/memcmp.S | 1 +
> > > sysdeps/powerpc/powerpc64/power8/memcmp.S | 1 +
> > > sysdeps/s390/memcmp-z900.S | 1 +
> > > sysdeps/s390/memcmp.c | 1 +
> > > sysdeps/sparc/sparc64/memcmp.S | 2 ++
> > > sysdeps/unix/sysv/linux/aarch64/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/alpha/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/arc/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/arm/be/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/arm/le/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/csky/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/hppa/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/i386/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/ia64/libc.abilist | 1 +
> > > .../unix/sysv/linux/m68k/coldfire/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist | 1 +
> > > .../unix/sysv/linux/microblaze/be/libc.abilist | 1 +
> > > .../unix/sysv/linux/microblaze/le/libc.abilist | 1 +
> > > .../unix/sysv/linux/mips/mips32/fpu/libc.abilist | 1 +
> > > .../sysv/linux/mips/mips32/nofpu/libc.abilist | 1 +
> > > .../unix/sysv/linux/mips/mips64/n32/libc.abilist | 1 +
> > > .../unix/sysv/linux/mips/mips64/n64/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/nios2/libc.abilist | 1 +
> > > .../linux/powerpc/powerpc32/fpu/libc.abilist | 1 +
> > > .../linux/powerpc/powerpc32/nofpu/libc.abilist | 1 +
> > > .../sysv/linux/powerpc/powerpc64/be/libc.abilist | 1 +
> > > .../sysv/linux/powerpc/powerpc64/le/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist | 1 +
> > > .../unix/sysv/linux/s390/s390-32/libc.abilist | 1 +
> > > .../unix/sysv/linux/s390/s390-64/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/sh/be/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/sh/le/libc.abilist | 1 +
> > > .../unix/sysv/linux/sparc/sparc32/libc.abilist | 1 +
> > > .../unix/sysv/linux/sparc/sparc64/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/x86_64/64/libc.abilist | 1 +
> > > sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist | 1 +
> > > sysdeps/x86_64/memcmp.S | 2 ++
> > > sysdeps/x86_64/multiarch/memcmp.c | 2 ++
> > > 55 files changed, 94 insertions(+)
> > >
> > > diff --git a/string/Versions b/string/Versions
> > > index 298ecd401a..864c4cf7a4 100644
> > > --- a/string/Versions
> > > +++ b/string/Versions
> > > @@ -89,4 +89,7 @@ libc {
> > > sigdescr_np; sigabbrev_np;
> > > strerrordesc_np; strerrorname_np;
> > > }
> > > + GLIBC_2.35 {
> > > + __memcmpeq;
> > > + }
> > > }
> > > diff --git a/string/memcmp.c b/string/memcmp.c
> > > index 9b46d7a905..5020be00e0 100644
> > > --- a/string/memcmp.c
> > > +++ b/string/memcmp.c
> > > @@ -358,4 +358,6 @@ libc_hidden_builtin_def(memcmp)
> > > #ifdef weak_alias
> > > # undef bcmp
> > > weak_alias (memcmp, bcmp)
> > > +# undef __memcmpeq
> > > +weak_alias (memcmp, __memcmpeq)
> > > #endif
> > > diff --git a/string/string.h b/string/string.h
> > > index b1b083edce..e70feeaeea 100644
> > > --- a/string/string.h
> > > +++ b/string/string.h
> > > @@ -64,6 +64,22 @@ extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
> > > extern int memcmp (const void *__s1, const void *__s2, size_t __n)
> > > __THROW __attribute_pure__ __nonnull ((1, 2));
> > >
> > > +/* Compare N bytes of S1 and S2. Return zero if S1 and S2 are equal.
> > > + Return some non-zero value otherwise.
> > > +
> > > + Essentially __memcmpeq has the exact same semantics as memcmp
> > > + except the return value is less constrained. memcmp is always a
> > > + correct implementation of __memcmpeq. As well !!memcmp, -memcmp,
> > > + or bcmp are correct implementations.
> > > +
> > > + __memcmpeq is meant to be used by compilers when memcmp return is
> > > + only used for its bolean value.
> > > +
> > > + __memcmpeq is declared only for use by compilers. Programs should
> > > + continue to use memcmp. */
> > > +extern int __memcmpeq (const void *__s1, const void *__s2, size_t __n)
> > > + __THROW __attribute_pure__ __nonnull ((1, 2));
> > > +
> > > /* Search N bytes of S for C. */
> > > #ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
> > > extern "C++"
> > > diff --git a/string/tester.c b/string/tester.c
> > > index 778160ae6e..605b3f00f9 100644
> > > --- a/string/tester.c
> > > +++ b/string/tester.c
> > > @@ -1449,6 +1449,19 @@ test_bcmp (void)
> > > check(bcmp("abc", "def", 0) == 0, 8); /* Zero count. */
> > > }
> > >
> > > +static void
> > > +test_memcmpeq (void)
> > > +{
> > > + it = "__memcmpeq";
> > > + check (__memcmpeq ("a", "a", 1) == 0, 1); /* Identity. */
> > > + check (__memcmpeq ("abc", "abc", 3) == 0, 2); /* Multicharacter. */
> > > + check (__memcmpeq ("abcd", "abce", 4) != 0, 3); /* Honestly unequal. */
> > > + check (__memcmpeq ("abce", "abcd", 4) != 0, 4);
> > > + check (__memcmpeq ("alph", "beta", 4) != 0, 5);
> > > + check (__memcmpeq ("abce", "abcd", 3) == 0, 6); /* Count limited. */
> > > + check (__memcmpeq ("abc", "def", 0) == 0, 8); /* Zero count. */
> > > +}
> > > +
> > > static void
> > > test_strerror (void)
> > > {
> > > @@ -1611,6 +1624,9 @@ main (void)
> > > /* bcmp - somewhat like memcmp. */
> > > test_bcmp ();
> > >
> > > + /* __memcmpeq - somewhat like memcmp. */
> > > + test_memcmpeq ();
> > > +
> > > /* strndup. */
> > > test_strndup ();
> > >
> > > diff --git a/sysdeps/aarch64/memcmp.S b/sysdeps/aarch64/memcmp.S
> > > index c1937f6f5c..bc932eff2a 100644
> > > --- a/sysdeps/aarch64/memcmp.S
> > > +++ b/sysdeps/aarch64/memcmp.S
> > > @@ -177,4 +177,6 @@ L(ret_0):
> > > END (memcmp)
> > > #undef bcmp
> > > weak_alias (memcmp, bcmp)
> > > +#undef __memcmpeq
> > > +weak_alias (memcmp, __memcmpeq)
> >
> > Can we use strong_alias for __memcmpeq?
>
> Think we can but not sure if its needed or we should.
__memcmpeq shouldn't have STB_WEAK binding since it
shouldn't be preempted.
--
H.J.
next prev parent reply other threads:[~2021-10-22 2:38 UTC|newest]
Thread overview: 106+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-27 20:38 [PATCH v1] " Noah Goldstein
2021-09-27 20:43 ` Joseph Myers
2021-09-27 21:06 ` Noah Goldstein
2021-09-27 21:06 ` [PATCH v2] " Noah Goldstein
2021-09-27 21:52 ` Joseph Myers
2021-09-28 1:24 ` Noah Goldstein
2021-09-28 1:24 ` [PATCH v3] " Noah Goldstein
2021-09-28 8:15 ` Andreas Schwab
2021-09-28 16:47 ` Noah Goldstein
2021-09-28 8:40 ` Florian Weimer
2021-09-28 16:47 ` Noah Goldstein
2021-09-28 16:51 ` Florian Weimer
2021-09-28 16:46 ` [PATCH v4] " Noah Goldstein
2021-09-28 16:50 ` [PATCH v5] " Noah Goldstein
2021-09-28 16:53 ` [PATCH v6] " Noah Goldstein
2021-09-29 8:36 ` Florian Weimer
2021-09-29 15:17 ` Noah Goldstein
2021-09-29 8:52 ` Andreas Schwab
2021-09-29 9:18 ` Florian Weimer
2021-09-29 9:31 ` Andreas Schwab
2021-09-29 9:44 ` Florian Weimer
2021-09-28 16:57 ` [PATCH v1] " Noah Goldstein
2021-09-29 15:17 ` [PATCH v7] " Noah Goldstein
2021-09-30 19:31 ` Noah Goldstein
2021-10-11 2:33 ` Noah Goldstein
2021-10-18 14:47 ` Noah Goldstein
2021-10-21 19:28 ` H.J. Lu
2021-10-21 19:58 ` Noah Goldstein
2021-10-21 20:00 ` H.J. Lu
2021-10-21 21:04 ` Noah Goldstein
2021-10-21 20:02 ` Adhemerval Zanella
2021-10-21 20:23 ` Noah Goldstein
2021-10-21 20:26 ` Adhemerval Zanella
2021-10-21 19:33 ` Adhemerval Zanella
2021-10-21 20:01 ` Noah Goldstein
2021-10-21 20:06 ` Adhemerval Zanella
2021-10-21 21:18 ` Florian Weimer
2021-10-21 20:07 ` H.J. Lu
2021-10-21 20:11 ` Noah Goldstein
2021-10-21 22:38 ` [PATCH v8 1/3] " Noah Goldstein
2021-10-21 22:38 ` [PATCH v8 2/3] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-21 22:52 ` H.J. Lu
2021-10-21 23:08 ` Joseph Myers
2021-10-21 23:10 ` H.J. Lu
2021-10-21 23:14 ` Joseph Myers
2021-10-21 23:39 ` Noah Goldstein
2021-10-21 23:45 ` Noah Goldstein
2021-10-22 0:19 ` Joseph Myers
2021-10-22 0:40 ` H.J. Lu
2021-10-25 16:41 ` Joseph Myers
2021-10-22 0:18 ` Joseph Myers
2021-10-21 22:38 ` [PATCH v8 3/3] String: Add tests for __memcmpeq Noah Goldstein
2021-10-21 22:57 ` H.J. Lu
2021-10-21 23:47 ` Noah Goldstein
2021-10-22 0:41 ` H.J. Lu
2021-10-22 1:01 ` Noah Goldstein
2021-10-21 22:50 ` [PATCH v8 1/3] String: Add support for __memcmpeq() ABI on all targets H.J. Lu
2021-10-21 23:42 ` Noah Goldstein
2021-10-22 2:38 ` H.J. Lu [this message]
2021-10-22 4:04 ` Noah Goldstein
2021-10-22 5:49 ` [PATCH v9 " Noah Goldstein
2021-10-22 12:38 ` H.J. Lu
2021-10-22 16:07 ` Noah Goldstein
2021-10-22 17:19 ` Noah Goldstein
2021-10-22 17:40 ` Noah Goldstein
2021-10-22 17:44 ` H.J. Lu
2021-10-22 18:09 ` Noah Goldstein
2021-10-22 18:33 ` H.J. Lu
2021-10-22 5:49 ` [PATCH v9 2/3] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 12:44 ` H.J. Lu
2021-10-22 5:49 ` [PATCH v9 3/3] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 12:42 ` H.J. Lu
2021-10-22 16:06 ` [PATCH v10 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-22 16:06 ` [PATCH v10 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 16:06 ` [PATCH v10 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 16:06 ` [PATCH v10 4/4] NEWS: Add item " Noah Goldstein
2021-10-22 16:12 ` H.J. Lu
2021-10-22 16:12 ` [PATCH v10 1/4] String: Add support for __memcmpeq() ABI on all targets H.J. Lu
2021-10-22 16:18 ` Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 " Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 18:37 ` [PATCH v11 4/4] NEWS: Add item " Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 19:46 ` [PATCH v12 4/4] NEWS: Add item " Noah Goldstein
2021-10-22 20:28 ` [PATCH v12 1/4] String: Add support for __memcmpeq() ABI on all targets H.J. Lu
2021-10-22 20:33 ` Noah Goldstein
2021-10-22 20:45 ` H.J. Lu
2021-10-22 21:24 ` Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 " Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-22 21:23 ` [PATCH v13 4/4] NEWS: Add item " Noah Goldstein
2021-10-23 23:23 ` [PATCH v13 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-23 23:24 ` [PATCH v14 " Noah Goldstein
2021-10-23 23:24 ` [PATCH v14 2/4] String: Add hidden defs for __memcmpeq() to enable internal usage Noah Goldstein
2021-10-26 18:56 ` H.J. Lu
2021-10-23 23:24 ` [PATCH v14 3/4] String: Add tests for __memcmpeq Noah Goldstein
2021-10-26 18:57 ` H.J. Lu
2021-10-23 23:24 ` [PATCH v14 4/4] NEWS: Add item " Noah Goldstein
2021-10-26 18:58 ` H.J. Lu
2021-10-25 2:45 ` [PATCH v14 1/4] String: Add support for __memcmpeq() ABI on all targets Noah Goldstein
2021-10-26 18:55 ` H.J. Lu
2021-10-26 22:29 ` Noah Goldstein
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=CAMe9rOqzVYmj7M7-h_OYiVP006M-+AC21f5zigs8rPegB6oyqA@mail.gmail.com \
--to=hjl.tools@gmail.com \
--cc=carlos@systemhalted.org \
--cc=goldstein.w.n@gmail.com \
--cc=libc-alpha@sourceware.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).