* [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646]
@ 2021-12-04 3:24 H.J. Lu
2021-12-04 3:50 ` Noah Goldstein
2021-12-04 8:14 ` Andreas Schwab
0 siblings, 2 replies; 4+ messages in thread
From: H.J. Lu @ 2021-12-04 3:24 UTC (permalink / raw)
To: libc-alpha
From: Noah Goldstein <goldstein.w.n@gmail.com>
Must use notl %edi here as lower bits are for CHAR comparisons
potentially out of range thus can be 0 without indicating mismatch.
This fixes BZ #28646.
Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
---
string/test-strcmp.c | 28 ++++++++++++++++++++++++++
sysdeps/x86_64/multiarch/strcmp-evex.S | 14 +++++++------
2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/string/test-strcmp.c b/string/test-strcmp.c
index 77ae73110f..42178a260b 100644
--- a/string/test-strcmp.c
+++ b/string/test-strcmp.c
@@ -23,6 +23,7 @@
# define TEST_NAME "strcmp"
#endif
#include "test-string.h"
+#include <support/test-driver.h>
#ifdef WIDE
# include <wchar.h>
@@ -390,6 +391,32 @@ check2 (void)
}
}
+static void
+check3 (void)
+{
+ size_t size = 0xd000 + 0x4000;
+ CHAR *s1, *s2;
+ CHAR *buffer1 = mmap (NULL, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0);
+ CHAR *buffer2 = mmap (NULL, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (buffer1 == MAP_FAILED || buffer1 == MAP_FAILED)
+ error (EXIT_UNSUPPORTED, errno, "mmap failed");
+
+ s1 = (CHAR *) (buffer1 + 0x8f8 / sizeof (CHAR));
+ s2 = (CHAR *) (buffer2 + 0xcff3 / sizeof (CHAR));
+
+ STRCPY(s1, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java"));
+ STRCPY(s2, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java"));
+
+ int exp_result = SIMPLE_STRCMP (s1, s2);
+ FOR_EACH_IMPL (impl, 0)
+ check_result (impl, s1, s2, exp_result);
+
+ munmap ((void *) buffer1, size);
+ munmap ((void *) buffer2, size);
+}
+
int
test_main (void)
{
@@ -398,6 +425,7 @@ test_main (void)
test_init ();
check();
check2 ();
+ check3 ();
printf ("%23s", "");
FOR_EACH_IMPL (impl, 0)
diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S
index 0bea318abd..b68e1f7a1e 100644
--- a/sysdeps/x86_64/multiarch/strcmp-evex.S
+++ b/sysdeps/x86_64/multiarch/strcmp-evex.S
@@ -646,12 +646,13 @@ L(loop_cross_page):
in YMM3 and 32 bytes at VEC_SIZE(%rdx, %r10). */
VPCMP $0, VEC_SIZE(%rdx, %r10), %YMM3, %k3{%k4}
kmovd %k3, %edi
+ /* Must use notl %edi here as lower bits are for CHAR
+ comparisons potentially out of range thus can be 0 without
+ indicating mismatch. */
+ notl %edi
# ifdef USE_AS_WCSCMP
/* Don't use subl since it is the upper 8 bits of EDI below. */
- notl %edi
andl $0xff, %edi
-# else
- incl %edi
# endif
# ifdef USE_AS_WCSCMP
@@ -733,12 +734,13 @@ L(loop_cross_page_2_vec):
in YMM1 and 32 bytes at (VEC_SIZE * 3)(%rdx, %r10). */
VPCMP $0, (VEC_SIZE * 3)(%rdx, %r10), %YMM1, %k3{%k4}
kmovd %k3, %edi
+ /* Must use notl %edi here as lower bits are for CHAR
+ comparisons potentially out of range thus can be 0 without
+ indicating mismatch. */
+ notl %edi
# ifdef USE_AS_WCSCMP
/* Don't use subl since it is the upper 8 bits of EDI below. */
- notl %edi
andl $0xff, %edi
-# else
- incl %edi
# endif
# ifdef USE_AS_WCSCMP
--
2.33.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646]
2021-12-04 3:24 [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646] H.J. Lu
@ 2021-12-04 3:50 ` Noah Goldstein
2022-04-23 1:49 ` Sunil Pandey
2021-12-04 8:14 ` Andreas Schwab
1 sibling, 1 reply; 4+ messages in thread
From: Noah Goldstein @ 2021-12-04 3:50 UTC (permalink / raw)
To: H.J. Lu; +Cc: GNU C Library
On Fri, Dec 3, 2021 at 9:24 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> From: Noah Goldstein <goldstein.w.n@gmail.com>
>
> Must use notl %edi here as lower bits are for CHAR comparisons
> potentially out of range thus can be 0 without indicating mismatch.
> This fixes BZ #28646.
>
> Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
> ---
> string/test-strcmp.c | 28 ++++++++++++++++++++++++++
> sysdeps/x86_64/multiarch/strcmp-evex.S | 14 +++++++------
> 2 files changed, 36 insertions(+), 6 deletions(-)
>
> diff --git a/string/test-strcmp.c b/string/test-strcmp.c
> index 77ae73110f..42178a260b 100644
> --- a/string/test-strcmp.c
> +++ b/string/test-strcmp.c
> @@ -23,6 +23,7 @@
> # define TEST_NAME "strcmp"
> #endif
> #include "test-string.h"
> +#include <support/test-driver.h>
>
> #ifdef WIDE
> # include <wchar.h>
> @@ -390,6 +391,32 @@ check2 (void)
> }
> }
>
> +static void
> +check3 (void)
> +{
> + size_t size = 0xd000 + 0x4000;
> + CHAR *s1, *s2;
> + CHAR *buffer1 = mmap (NULL, size, PROT_READ | PROT_WRITE,
> + MAP_PRIVATE | MAP_ANON, -1, 0);
> + CHAR *buffer2 = mmap (NULL, size, PROT_READ | PROT_WRITE,
> + MAP_PRIVATE | MAP_ANON, -1, 0);
> + if (buffer1 == MAP_FAILED || buffer1 == MAP_FAILED)
> + error (EXIT_UNSUPPORTED, errno, "mmap failed");
> +
> + s1 = (CHAR *) (buffer1 + 0x8f8 / sizeof (CHAR));
> + s2 = (CHAR *) (buffer2 + 0xcff3 / sizeof (CHAR));
> +
> + STRCPY(s1, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java"));
> + STRCPY(s2, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java"));
> +
> + int exp_result = SIMPLE_STRCMP (s1, s2);
> + FOR_EACH_IMPL (impl, 0)
> + check_result (impl, s1, s2, exp_result);
> +
> + munmap ((void *) buffer1, size);
> + munmap ((void *) buffer2, size);
> +}
> +
> int
> test_main (void)
> {
> @@ -398,6 +425,7 @@ test_main (void)
> test_init ();
> check();
> check2 ();
> + check3 ();
>
> printf ("%23s", "");
> FOR_EACH_IMPL (impl, 0)
> diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S
> index 0bea318abd..b68e1f7a1e 100644
> --- a/sysdeps/x86_64/multiarch/strcmp-evex.S
> +++ b/sysdeps/x86_64/multiarch/strcmp-evex.S
> @@ -646,12 +646,13 @@ L(loop_cross_page):
> in YMM3 and 32 bytes at VEC_SIZE(%rdx, %r10). */
> VPCMP $0, VEC_SIZE(%rdx, %r10), %YMM3, %k3{%k4}
> kmovd %k3, %edi
> + /* Must use notl %edi here as lower bits are for CHAR
> + comparisons potentially out of range thus can be 0 without
> + indicating mismatch. */
> + notl %edi
> # ifdef USE_AS_WCSCMP
> /* Don't use subl since it is the upper 8 bits of EDI below. */
> - notl %edi
> andl $0xff, %edi
> -# else
> - incl %edi
> # endif
>
> # ifdef USE_AS_WCSCMP
> @@ -733,12 +734,13 @@ L(loop_cross_page_2_vec):
> in YMM1 and 32 bytes at (VEC_SIZE * 3)(%rdx, %r10). */
> VPCMP $0, (VEC_SIZE * 3)(%rdx, %r10), %YMM1, %k3{%k4}
> kmovd %k3, %edi
> + /* Must use notl %edi here as lower bits are for CHAR
> + comparisons potentially out of range thus can be 0 without
> + indicating mismatch. */
> + notl %edi
> # ifdef USE_AS_WCSCMP
> /* Don't use subl since it is the upper 8 bits of EDI below. */
> - notl %edi
> andl $0xff, %edi
> -# else
> - incl %edi
> # endif
>
> # ifdef USE_AS_WCSCMP
> --
> 2.33.1
>
LGTM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646]
2021-12-04 3:24 [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646] H.J. Lu
2021-12-04 3:50 ` Noah Goldstein
@ 2021-12-04 8:14 ` Andreas Schwab
1 sibling, 0 replies; 4+ messages in thread
From: Andreas Schwab @ 2021-12-04 8:14 UTC (permalink / raw)
To: H.J. Lu via Libc-alpha
On Dez 03 2021, H.J. Lu via Libc-alpha wrote:
> diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S
> index 0bea318abd..b68e1f7a1e 100644
> --- a/sysdeps/x86_64/multiarch/strcmp-evex.S
> +++ b/sysdeps/x86_64/multiarch/strcmp-evex.S
> @@ -646,12 +646,13 @@ L(loop_cross_page):
> in YMM3 and 32 bytes at VEC_SIZE(%rdx, %r10). */
> VPCMP $0, VEC_SIZE(%rdx, %r10), %YMM3, %k3{%k4}
> kmovd %k3, %edi
> + /* Must use notl %edi here as lower bits are for CHAR
> + comparisons potentially out of range thus can be 0 without
> + indicating mismatch. */
> + notl %edi
Spacing off in the first line.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646]
2021-12-04 3:50 ` Noah Goldstein
@ 2022-04-23 1:49 ` Sunil Pandey
0 siblings, 0 replies; 4+ messages in thread
From: Sunil Pandey @ 2022-04-23 1:49 UTC (permalink / raw)
To: Noah Goldstein, libc-stable; +Cc: H.J. Lu, GNU C Library
On Fri, Dec 3, 2021 at 7:50 PM Noah Goldstein via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> On Fri, Dec 3, 2021 at 9:24 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > From: Noah Goldstein <goldstein.w.n@gmail.com>
> >
> > Must use notl %edi here as lower bits are for CHAR comparisons
> > potentially out of range thus can be 0 without indicating mismatch.
> > This fixes BZ #28646.
> >
> > Co-Authored-By: H.J. Lu <hjl.tools@gmail.com>
> > ---
> > string/test-strcmp.c | 28 ++++++++++++++++++++++++++
> > sysdeps/x86_64/multiarch/strcmp-evex.S | 14 +++++++------
> > 2 files changed, 36 insertions(+), 6 deletions(-)
> >
> > diff --git a/string/test-strcmp.c b/string/test-strcmp.c
> > index 77ae73110f..42178a260b 100644
> > --- a/string/test-strcmp.c
> > +++ b/string/test-strcmp.c
> > @@ -23,6 +23,7 @@
> > # define TEST_NAME "strcmp"
> > #endif
> > #include "test-string.h"
> > +#include <support/test-driver.h>
> >
> > #ifdef WIDE
> > # include <wchar.h>
> > @@ -390,6 +391,32 @@ check2 (void)
> > }
> > }
> >
> > +static void
> > +check3 (void)
> > +{
> > + size_t size = 0xd000 + 0x4000;
> > + CHAR *s1, *s2;
> > + CHAR *buffer1 = mmap (NULL, size, PROT_READ | PROT_WRITE,
> > + MAP_PRIVATE | MAP_ANON, -1, 0);
> > + CHAR *buffer2 = mmap (NULL, size, PROT_READ | PROT_WRITE,
> > + MAP_PRIVATE | MAP_ANON, -1, 0);
> > + if (buffer1 == MAP_FAILED || buffer1 == MAP_FAILED)
> > + error (EXIT_UNSUPPORTED, errno, "mmap failed");
> > +
> > + s1 = (CHAR *) (buffer1 + 0x8f8 / sizeof (CHAR));
> > + s2 = (CHAR *) (buffer2 + 0xcff3 / sizeof (CHAR));
> > +
> > + STRCPY(s1, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/PathDocFileFactory.java"));
> > + STRCPY(s2, L("/export/redhat/rpms/BUILD/java-1.8.0-openjdk-1.8.0.312.b07-2.fc35.x86_64/openjdk/langtools/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/ThrowsTaglet.java"));
> > +
> > + int exp_result = SIMPLE_STRCMP (s1, s2);
> > + FOR_EACH_IMPL (impl, 0)
> > + check_result (impl, s1, s2, exp_result);
> > +
> > + munmap ((void *) buffer1, size);
> > + munmap ((void *) buffer2, size);
> > +}
> > +
> > int
> > test_main (void)
> > {
> > @@ -398,6 +425,7 @@ test_main (void)
> > test_init ();
> > check();
> > check2 ();
> > + check3 ();
> >
> > printf ("%23s", "");
> > FOR_EACH_IMPL (impl, 0)
> > diff --git a/sysdeps/x86_64/multiarch/strcmp-evex.S b/sysdeps/x86_64/multiarch/strcmp-evex.S
> > index 0bea318abd..b68e1f7a1e 100644
> > --- a/sysdeps/x86_64/multiarch/strcmp-evex.S
> > +++ b/sysdeps/x86_64/multiarch/strcmp-evex.S
> > @@ -646,12 +646,13 @@ L(loop_cross_page):
> > in YMM3 and 32 bytes at VEC_SIZE(%rdx, %r10). */
> > VPCMP $0, VEC_SIZE(%rdx, %r10), %YMM3, %k3{%k4}
> > kmovd %k3, %edi
> > + /* Must use notl %edi here as lower bits are for CHAR
> > + comparisons potentially out of range thus can be 0 without
> > + indicating mismatch. */
> > + notl %edi
> > # ifdef USE_AS_WCSCMP
> > /* Don't use subl since it is the upper 8 bits of EDI below. */
> > - notl %edi
> > andl $0xff, %edi
> > -# else
> > - incl %edi
> > # endif
> >
> > # ifdef USE_AS_WCSCMP
> > @@ -733,12 +734,13 @@ L(loop_cross_page_2_vec):
> > in YMM1 and 32 bytes at (VEC_SIZE * 3)(%rdx, %r10). */
> > VPCMP $0, (VEC_SIZE * 3)(%rdx, %r10), %YMM1, %k3{%k4}
> > kmovd %k3, %edi
> > + /* Must use notl %edi here as lower bits are for CHAR
> > + comparisons potentially out of range thus can be 0 without
> > + indicating mismatch. */
> > + notl %edi
> > # ifdef USE_AS_WCSCMP
> > /* Don't use subl since it is the upper 8 bits of EDI below. */
> > - notl %edi
> > andl $0xff, %edi
> > -# else
> > - incl %edi
> > # endif
> >
> > # ifdef USE_AS_WCSCMP
> > --
> > 2.33.1
> >
>
> LGTM
I would like to backport this patch to release branches.
Any comments or objections?
--Sunil
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-23 1:49 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-04 3:24 [PATCH] x86-64: Use notl in EVEX strcmp [BZ #28646] H.J. Lu
2021-12-04 3:50 ` Noah Goldstein
2022-04-23 1:49 ` Sunil Pandey
2021-12-04 8:14 ` Andreas Schwab
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).