[v8,3/3] String: Add tests for __memcmpeq

Message ID 20211021223850.415607-3-goldstein.w.n@gmail.com
State Superseded
Headers
Series [v8,1/3] String: Add support for __memcmpeq() ABI on all targets |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Noah Goldstein Oct. 21, 2021, 10:38 p.m. UTC
  No bug.

This commit adds tests for the new function __memcmpeq. The new tests
use the existing tests in 'test-memcmp.c' but relax the result
requirement to only check for zero or non-zero returns.

All string tests include test-memcmpeq are passing.
---
Note at the momement for test-memcmpeq.c the
tests only appear to do the generic versions.

For example on x86_64 the output of test-memcmpeq.out is:


```
                        __memcmpeq simple_memcmp
```

whereas test-memcmp.out is:

```
                        simple_memcmp __memcmp_avx2_movbe
__memcmp_evex_movbe __memcmp_sse4_1 __memcmp_ssse3 __memcmp_sse2
```

So the test is not going through all available ifuncs. I'm not
sure if this is expected or indicates a bug in the previous
patches adding support for __memcmpeq.

 string/Makefile        |  4 ++--
 string/test-memcmp.c   | 27 ++++++++++++++++++---------
 string/test-memcmpeq.c | 21 +++++++++++++++++++++
 3 files changed, 41 insertions(+), 11 deletions(-)
 create mode 100644 string/test-memcmpeq.c
  

Comments

H.J. Lu Oct. 21, 2021, 10:57 p.m. UTC | #1
On Thu, Oct 21, 2021 at 3:40 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> No bug.
>
> This commit adds tests for the new function __memcmpeq. The new tests
> use the existing tests in 'test-memcmp.c' but relax the result
> requirement to only check for zero or non-zero returns.
>
> All string tests include test-memcmpeq are passing.
> ---
> Note at the momement for test-memcmpeq.c the
> tests only appear to do the generic versions.
>
> For example on x86_64 the output of test-memcmpeq.out is:
>
>
> ```
>                         __memcmpeq simple_memcmp
> ```
>
> whereas test-memcmp.out is:
>
> ```
>                         simple_memcmp __memcmp_avx2_movbe
> __memcmp_evex_movbe __memcmp_sse4_1 __memcmp_ssse3 __memcmp_sse2
> ```
>
> So the test is not going through all available ifuncs. I'm not
> sure if this is expected or indicates a bug in the previous
> patches adding support for __memcmpeq.
>

This doesn't look right.  If __memcmpeq is a true alias of memcmp, you
should only have simple_memcmpeq and __memcmpeq.
  
Noah Goldstein Oct. 21, 2021, 11:47 p.m. UTC | #2
On Thu, Oct 21, 2021 at 5:58 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Oct 21, 2021 at 3:40 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > No bug.
> >
> > This commit adds tests for the new function __memcmpeq. The new tests
> > use the existing tests in 'test-memcmp.c' but relax the result
> > requirement to only check for zero or non-zero returns.
> >
> > All string tests include test-memcmpeq are passing.
> > ---
> > Note at the momement for test-memcmpeq.c the
> > tests only appear to do the generic versions.
> >
> > For example on x86_64 the output of test-memcmpeq.out is:
> >
> >
> > ```
> >                         __memcmpeq simple_memcmp
> > ```
> >
> > whereas test-memcmp.out is:
> >
> > ```
> >                         simple_memcmp __memcmp_avx2_movbe
> > __memcmp_evex_movbe __memcmp_sse4_1 __memcmp_ssse3 __memcmp_sse2
> > ```
> >
> > So the test is not going through all available ifuncs. I'm not
> > sure if this is expected or indicates a bug in the previous
> > patches adding support for __memcmpeq.
> >
>
> This doesn't look right.  If __memcmpeq is a true alias of memcmp, you
> should only have simple_memcmpeq and __memcmpeq.

Figured. Any idea what the issue might be?

>
> --
> H.J.
  
H.J. Lu Oct. 22, 2021, 12:41 a.m. UTC | #3
On Thu, Oct 21, 2021 at 4:47 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> On Thu, Oct 21, 2021 at 5:58 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Thu, Oct 21, 2021 at 3:40 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > >
> > > No bug.
> > >
> > > This commit adds tests for the new function __memcmpeq. The new tests
> > > use the existing tests in 'test-memcmp.c' but relax the result
> > > requirement to only check for zero or non-zero returns.
> > >
> > > All string tests include test-memcmpeq are passing.
> > > ---
> > > Note at the momement for test-memcmpeq.c the
> > > tests only appear to do the generic versions.
> > >
> > > For example on x86_64 the output of test-memcmpeq.out is:
> > >
> > >
> > > ```
> > >                         __memcmpeq simple_memcmp
> > > ```
> > >
> > > whereas test-memcmp.out is:
> > >
> > > ```
> > >                         simple_memcmp __memcmp_avx2_movbe
> > > __memcmp_evex_movbe __memcmp_sse4_1 __memcmp_ssse3 __memcmp_sse2
> > > ```
> > >
> > > So the test is not going through all available ifuncs. I'm not
> > > sure if this is expected or indicates a bug in the previous
> > > patches adding support for __memcmpeq.
> > >
> >
> > This doesn't look right.  If __memcmpeq is a true alias of memcmp, you
> > should only have simple_memcmpeq and __memcmpeq.
>
> Figured. Any idea what the issue might be?

Where is your branch?  I can take a look.
  
Noah Goldstein Oct. 22, 2021, 1:01 a.m. UTC | #4
On Thu, Oct 21, 2021 at 7:42 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Oct 21, 2021 at 4:47 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> >
> > On Thu, Oct 21, 2021 at 5:58 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Thu, Oct 21, 2021 at 3:40 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
> > > >
> > > > No bug.
> > > >
> > > > This commit adds tests for the new function __memcmpeq. The new tests
> > > > use the existing tests in 'test-memcmp.c' but relax the result
> > > > requirement to only check for zero or non-zero returns.
> > > >
> > > > All string tests include test-memcmpeq are passing.
> > > > ---
> > > > Note at the momement for test-memcmpeq.c the
> > > > tests only appear to do the generic versions.
> > > >
> > > > For example on x86_64 the output of test-memcmpeq.out is:
> > > >
> > > >
> > > > ```
> > > >                         __memcmpeq simple_memcmp
> > > > ```
> > > >
> > > > whereas test-memcmp.out is:
> > > >
> > > > ```
> > > >                         simple_memcmp __memcmp_avx2_movbe
> > > > __memcmp_evex_movbe __memcmp_sse4_1 __memcmp_ssse3 __memcmp_sse2
> > > > ```
> > > >
> > > > So the test is not going through all available ifuncs. I'm not
> > > > sure if this is expected or indicates a bug in the previous
> > > > patches adding support for __memcmpeq.
> > > >
> > >
> > > This doesn't look right.  If __memcmpeq is a true alias of memcmp, you
> > > should only have simple_memcmpeq and __memcmpeq.
> >
> > Figured. Any idea what the issue might be?
>
> Where is your branch?  I can take a look.

Made a new branch on your gitlab here:

https://gitlab.com/x86-glibc/glibc/-/tree/users/goldsteinn/memcmpeq-abi

>
> --
> H.J.
  

Patch

diff --git a/string/Makefile b/string/Makefile
index f0fce2a0b8..40d6fac133 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -48,8 +48,8 @@  routines	:= strcat strchr strcmp strcoll strcpy strcspn		\
 		   sigdescr_np sigabbrev_np strerrorname_np		\
 		   strerrordesc_np
 
-strop-tests	:= memchr memcmp memcpy memmove mempcpy memset memccpy	\
-		   stpcpy stpncpy strcat strchr strcmp strcpy strcspn	\
+strop-tests	:= memchr memcmp memcpy memcmpeq memmove mempcpy memset	\
+		   memccpy stpcpy stpncpy strcat strchr strcmp strcpy strcspn	\
 		   strlen strncmp strncpy strpbrk strrchr strspn memmem	\
 		   strstr strcasestr strnlen strcasecmp strncasecmp	\
 		   strncat rawmemchr strchrnul bcopy bzero memrchr	\
diff --git a/string/test-memcmp.c b/string/test-memcmp.c
index 6ddbc05d2f..e1f07cab58 100644
--- a/string/test-memcmp.c
+++ b/string/test-memcmp.c
@@ -17,11 +17,14 @@ 
    <https://www.gnu.org/licenses/>.  */
 
 #define TEST_MAIN
-#ifdef WIDE
+#ifdef TEST_MEMCMPEQ
+# define TEST_NAME "__memcmpeq"
+#elif defined WIDE
 # define TEST_NAME "wmemcmp"
 #else
 # define TEST_NAME "memcmp"
 #endif
+
 #include "test-string.h"
 #ifdef WIDE
 # include <inttypes.h>
@@ -35,6 +38,7 @@ 
 # define CHARBYTES 4
 # define CHAR__MIN WCHAR_MIN
 # define CHAR__MAX WCHAR_MAX
+
 int
 simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
 {
@@ -48,8 +52,11 @@  simple_wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n)
 }
 #else
 # include <limits.h>
-
-# define MEMCMP memcmp
+# ifdef TEST_MEMCMPEQ
+#  define MEMCMP __memcmpeq
+# else
+#  define MEMCMP memcmp
+# endif
 # define MEMCPY memcpy
 # define SIMPLE_MEMCMP simple_memcmp
 # define CHAR char
@@ -69,6 +76,12 @@  simple_memcmp (const char *s1, const char *s2, size_t n)
 }
 #endif
 
+#ifndef BAD_RESULT
+# define BAD_RESULT(result, expec)                                      \
+    (((result) == 0 && (expec)) || ((result) < 0 && (expec) >= 0) ||    \
+     ((result) > 0 && (expec) <= 0))
+# endif
+
 typedef int (*proto_t) (const CHAR *, const CHAR *, size_t);
 
 IMPL (SIMPLE_MEMCMP, 0)
@@ -79,9 +92,7 @@  check_result (impl_t *impl, const CHAR *s1, const CHAR *s2, size_t len,
 	      int exp_result)
 {
   int result = CALL (impl, s1, s2, len);
-  if ((exp_result == 0 && result != 0)
-      || (exp_result < 0 && result >= 0)
-      || (exp_result > 0 && result <= 0))
+  if (BAD_RESULT(result, exp_result))
     {
       error (0, 0, "Wrong result in function %s %d %d", impl->name,
 	     result, exp_result);
@@ -186,9 +197,7 @@  do_random_tests (void)
 	{
 	  r = CALL (impl, (CHAR *) p1 + align1, (const CHAR *) p2 + align2,
 		    len);
-	  if ((r == 0 && result)
-	      || (r < 0 && result >= 0)
-	      || (r > 0 && result <= 0))
+	  if (BAD_RESULT(r, result))
 	    {
 	      error (0, 0, "Iteration %zd - wrong result in function %s (%zd, %zd, %zd, %zd) %ld != %d, p1 %p p2 %p",
 		     n, impl->name, align1 * CHARBYTES & 63,  align2 * CHARBYTES & 63, len, pos, r, result, p1, p2);
diff --git a/string/test-memcmpeq.c b/string/test-memcmpeq.c
new file mode 100644
index 0000000000..8889117868
--- /dev/null
+++ b/string/test-memcmpeq.c
@@ -0,0 +1,21 @@ 
+/* Test and measure __memcmpeq functions.
+   Copyright (C) 2012-2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#define BAD_RESULT(result, expec) ((!(result)) != (!(expec)))
+#define TEST_MEMCMPEQ 1
+#include "test-memcmp.c"