From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 3C3863858416 for ; Fri, 22 Oct 2021 02:38:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3C3863858416 Received: by mail-pf1-x434.google.com with SMTP id 187so2327836pfc.10 for ; Thu, 21 Oct 2021 19:38:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bhA6MqKjGl3a+cH4QfsCxLiYPhGq32ZQ3oom2ArFM5o=; b=A/jAqf07EhdaBOOvq/VjQ+H66unt8siy/BuUxf/QqUprioFlVUZMzFawxYng0jC3Mx wuzDWUqBkHEeD67n6vsLKZi8W5l9ZRLKspcJ1zEsguRjG+ti066aTtEu3EOt9EfsNb0P mgx5kS3GPrNvJTUA1P5cWAPKJphTZUiPAQnUNfJI7N/payYiFu5owYhFdd/MQlqaV5GL HWBs7ewP6Azsfet6QabBfgaYdWtcOD3I5wQvg0JlHPFnEByKQ+I2sYyOTS4eeOtcRg7m QkXucs5zRbOtzA+pPVkaI7jijNfM/eO6vj4Qmh+Og21HoOHjf8FrZfzFxd54CUdYA3Eq LrJw== X-Gm-Message-State: AOAM532/09rWFNp+QsWjAmCLanodBK/3O0q0TYD9rF3UloMH1hYmLuVk aejOetqjEoWwDhY3b5L0VI5bsDXyitymrNkkd7o= X-Google-Smtp-Source: ABdhPJzcXoc/7Tb7rnXIQftNvgHAyb7h950UhIkoh/TjEgRIVfK4Qxm1YAjf884XeUj5BS5L0ljtPh/5X1zYMAwkQfA= X-Received: by 2002:a62:7752:0:b0:44c:eb65:8561 with SMTP id s79-20020a627752000000b0044ceb658561mr9329000pfc.43.1634870328152; Thu, 21 Oct 2021 19:38:48 -0700 (PDT) MIME-Version: 1.0 References: <20210927203827.2852935-1-goldstein.w.n@gmail.com> <20211021223850.415607-1-goldstein.w.n@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Thu, 21 Oct 2021 19:38:12 -0700 Message-ID: Subject: Re: [PATCH v8 1/3] String: Add support for __memcmpeq() ABI on all targets To: Noah Goldstein Cc: GNU C Library , "Carlos O'Donell" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3029.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Oct 2021 02:38:51 -0000 On Thu, Oct 21, 2021 at 4:42 PM Noah Goldstein wrote: > > On Thu, Oct 21, 2021 at 5:50 PM H.J. Lu wrote: > > > > On Thu, Oct 21, 2021 at 3:38 PM Noah Goldstein 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.