public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Noah Goldstein <goldstein.w.n@gmail.com>
Cc: libc-alpha@sourceware.org, carlos@systemhalted.org
Subject: Re: [PATCH v5 2/2] x86: Expand test-memset.c and bench-memset.c
Date: Mon, 19 Apr 2021 14:52:59 -0700	[thread overview]
Message-ID: <CAMe9rOpbnfOdnws9jXUwn91X4wtRhzxDz5KGoE56nJQ9LbgMxQ@mail.gmail.com> (raw)
In-Reply-To: <20210419214811.2852085-2-goldstein.w.n@gmail.com>

On Mon, Apr 19, 2021 at 2:48 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>
> No bug. This commit adds tests cases and benchmarks for page cross and
> for memset to the end of the page without crossing. As well in
> test-memset.c this commit adds sentinel on start/end of tstbuf to test
> for overwrites
>
> Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>
> ---
>  benchtests/bench-memset.c |  6 ++++--
>  string/test-memset.c      | 20 +++++++++++++++-----
>  2 files changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/benchtests/bench-memset.c b/benchtests/bench-memset.c
> index 1174900e88..d6619b4836 100644
> --- a/benchtests/bench-memset.c
> +++ b/benchtests/bench-memset.c
> @@ -61,7 +61,7 @@ do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s,
>  static void
>  do_test (json_ctx_t *json_ctx, size_t align, int c, size_t len)
>  {
> -  align &= 63;
> +  align &= 4095;
>    if ((align + len) * sizeof (CHAR) > page_size)
>      return;
>
> @@ -110,9 +110,11 @@ test_main (void)
>      {
>        for (i = 0; i < 18; ++i)
>         do_test (&json_ctx, 0, c, 1 << i);
> -      for (i = 1; i < 32; ++i)
> +      for (i = 1; i < 64; ++i)
>         {
>           do_test (&json_ctx, i, c, i);
> +         do_test (&json_ctx, 4096 - i, c, i);
> +         do_test (&json_ctx, 4095, c, i);
>           if (i & (i - 1))
>             do_test (&json_ctx, 0, c, i);
>         }
> diff --git a/string/test-memset.c b/string/test-memset.c
> index eb71517390..82bfcd6ad4 100644
> --- a/string/test-memset.c
> +++ b/string/test-memset.c
> @@ -109,16 +109,24 @@ SIMPLE_MEMSET (CHAR *s, int c, size_t n)
>  static void
>  do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
>  {
> -  CHAR tstbuf[n];
> +  CHAR buf[n + 2];
> +  CHAR *tstbuf = buf + 1;
> +  CHAR sentinel = c - 1;
> +  buf[0] = sentinel;
> +  buf[n + 1] = sentinel;
>  #ifdef TEST_BZERO
>    simple_bzero (tstbuf, n);
>    CALL (impl, s, n);
> -  if (memcmp (s, tstbuf, n) != 0)
> +  if (memcmp (s, tstbuf, n) != 0
> +      || buf[0] != sentinel
> +      || buf[n + 1] != sentinel)
>  #else
>    CHAR *res = CALL (impl, s, c, n);
>    if (res != s
>        || SIMPLE_MEMSET (tstbuf, c, n) != tstbuf
> -      || MEMCMP (s, tstbuf, n) != 0)
> +      || MEMCMP (s, tstbuf, n) != 0
> +      || buf[0] != sentinel
> +      || buf[n + 1] != sentinel)
>  #endif /* !TEST_BZERO */
>      {
>        error (0, 0, "Wrong result in function %s", impl->name);
> @@ -130,7 +138,7 @@ do_one_test (impl_t *impl, CHAR *s, int c __attribute ((unused)), size_t n)
>  static void
>  do_test (size_t align, int c, size_t len)
>  {
> -  align &= 7;
> +  align &= 4095;
>    if ((align + len) * sizeof (CHAR) > page_size)
>      return;
>
> @@ -245,9 +253,11 @@ test_main (void)
>      {
>        for (i = 0; i < 18; ++i)
>         do_test (0, c, 1 << i);
> -      for (i = 1; i < 32; ++i)
> +      for (i = 1; i < 64; ++i)
>         {
>           do_test (i, c, i);
> +         do_test (4096 - i, c, i);
> +         do_test (4095, c, i);
>           if (i & (i - 1))
>             do_test (0, c, i);
>         }
> --
> 2.29.2
>

LGTM.  I will check it in for you.

Thanks.

-- 
H.J.

  reply	other threads:[~2021-04-19 21:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 21:48 [PATCH v5 1/2] x86: Optimize less_vec evex and avx512 memset-vec-unaligned-erms.S Noah Goldstein
2021-04-19 21:48 ` [PATCH v5 2/2] x86: Expand test-memset.c and bench-memset.c Noah Goldstein
2021-04-19 21:52   ` H.J. Lu [this message]
2021-04-19 21:51 ` [PATCH v5 1/2] x86: Optimize less_vec evex and avx512 memset-vec-unaligned-erms.S H.J. Lu
2022-04-27 23:49   ` Sunil Pandey

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=CAMe9rOpbnfOdnws9jXUwn91X4wtRhzxDz5KGoE56nJQ9LbgMxQ@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).