[v2,1/3] x86: Expand bench-memcmp.c and test-memcmp.c

Message ID 20210519022438.2986411-1-goldstein.w.n@gmail.com
State New
Headers show
Series
  • [v2,1/3] x86: Expand bench-memcmp.c and test-memcmp.c
Related show

Commit Message

No bug. This commit adds some additional performance test cases to
bench-memcmp.c and test-memcmp.c. The new benchtests include some
medium range sizes, as well as small sizes near page cross. The new
correctness tests correspond with the new benchtests though add some
additional cases for checking the page cross logic.

Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>

---
 benchtests/bench-memcmp.c | 32 +++++++++++++++++++++++++------
 string/test-memcmp.c      | 40 +++++++++++++++++++++++++++++++++------
 2 files changed, 60 insertions(+), 12 deletions(-)

-- 
2.29.2

Comments

On Tue, May 18, 2021 at 7:24 PM Noah Goldstein <goldstein.w.n@gmail.com> wrote:
>

> No bug. This commit adds some additional performance test cases to

> bench-memcmp.c and test-memcmp.c. The new benchtests include some

> medium range sizes, as well as small sizes near page cross. The new

> correctness tests correspond with the new benchtests though add some

> additional cases for checking the page cross logic.

>

> Signed-off-by: Noah Goldstein <goldstein.w.n@gmail.com>

> ---

>  benchtests/bench-memcmp.c | 32 +++++++++++++++++++++++++------

>  string/test-memcmp.c      | 40 +++++++++++++++++++++++++++++++++------

>  2 files changed, 60 insertions(+), 12 deletions(-)

>

> diff --git a/benchtests/bench-memcmp.c b/benchtests/bench-memcmp.c

> index eb0f94a0f1..744c7ec5ba 100644

> --- a/benchtests/bench-memcmp.c

> +++ b/benchtests/bench-memcmp.c

> @@ -88,11 +88,11 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,

>    if (len == 0)

>      return;

>

> -  align1 &= 63;

> +  align1 &= (4096 - CHARBYTES);

>    if (align1 + (len + 1) * CHARBYTES >= page_size)

>      return;

>

> -  align2 &= 63;

> +  align2 &= (4096 - CHARBYTES);

>    if (align2 + (len + 1) * CHARBYTES >= page_size)

>      return;

>

> @@ -100,6 +100,7 @@ do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,

>    json_attr_uint (json_ctx, "length", (double) len);

>    json_attr_uint (json_ctx, "align1", (double) align1);

>    json_attr_uint (json_ctx, "align2", (double) align2);

> +  json_attr_uint (json_ctx, "result", (double) exp_result);

>    json_array_begin (json_ctx, "timings");

>

>    FOR_EACH_IMPL (impl, 0)

> @@ -145,18 +146,31 @@ test_main (void)

>    json_array_end (&json_ctx);

>

>    json_array_begin (&json_ctx, "results");

> -  for (i = 1; i < 16; ++i)

> +  for (i = 1; i < 32; ++i)

>      {

>        do_test (&json_ctx, i * CHARBYTES, i * CHARBYTES, i, 0);

>        do_test (&json_ctx, i * CHARBYTES, i * CHARBYTES, i, 1);

>        do_test (&json_ctx, i * CHARBYTES, i * CHARBYTES, i, -1);

>      }

>

> -  for (i = 0; i < 16; ++i)

> +  for (i = 0; i < 32; ++i)

>      {

>        do_test (&json_ctx, 0, 0, i, 0);

>        do_test (&json_ctx, 0, 0, i, 1);

>        do_test (&json_ctx, 0, 0, i, -1);

> +      do_test (&json_ctx, 4096 - i, 0, i, 0);

> +      do_test (&json_ctx, 4096 - i, 0, i, 1);

> +      do_test (&json_ctx, 4096 - i, 0, i, -1);

> +    }

> +

> +  for (i = 33; i < 385; i += 32)

> +    {

> +      do_test (&json_ctx, 0, 0, i, 0);

> +      do_test (&json_ctx, 0, 0, i, 1);

> +      do_test (&json_ctx, 0, 0, i, -1);

> +      do_test (&json_ctx, i, 0, i, 0);

> +      do_test (&json_ctx, 0, i, i, 1);

> +      do_test (&json_ctx, i, i, i, -1);

>      }

>

>    for (i = 1; i < 10; ++i)

> @@ -164,13 +178,19 @@ test_main (void)

>        do_test (&json_ctx, 0, 0, 2 << i, 0);

>        do_test (&json_ctx, 0, 0, 2 << i, 1);

>        do_test (&json_ctx, 0, 0, 2 << i, -1);

> -      do_test (&json_ctx, 0, 0, 16 << i, 0);

>        do_test (&json_ctx, (8 - i) * CHARBYTES, (2 * i) * CHARBYTES, 16 << i, 0);

> +      do_test (&json_ctx, 0, 0, 16 << i, 0);

>        do_test (&json_ctx, 0, 0, 16 << i, 1);

>        do_test (&json_ctx, 0, 0, 16 << i, -1);

> +      do_test (&json_ctx, i, 0, 2 << i, 0);

> +      do_test (&json_ctx, 0, i, 2 << i, 1);

> +      do_test (&json_ctx, i, i, 2 << i, -1);

> +      do_test (&json_ctx, i, 0, 16 << i, 0);

> +      do_test (&json_ctx, 0, i, 16 << i, 1);

> +      do_test (&json_ctx, i, i, 16 << i, -1);

>      }

>

> -  for (i = 1; i < 8; ++i)

> +  for (i = 1; i < 10; ++i)

>      {

>        do_test (&json_ctx, i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 0);

>        do_test (&json_ctx, i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 1);

> diff --git a/string/test-memcmp.c b/string/test-memcmp.c

> index 02ea9b782d..fbda26a41e 100644

> --- a/string/test-memcmp.c

> +++ b/string/test-memcmp.c

> @@ -111,11 +111,11 @@ do_test (size_t align1, size_t align2, size_t len, int exp_result)

>    if (len == 0)

>      return;

>

> -  align1 &= 63;

> +  align1 &= (4096 - CHARBYTES);

>    if (align1 + (len + 1) * CHARBYTES >= page_size)

>      return;

>

> -  align2 &= 63;

> +  align2 &= (4096 - CHARBYTES);

>    if (align2 + (len + 1) * CHARBYTES >= page_size)

>      return;

>

> @@ -487,18 +487,40 @@ test_main (void)

>      printf ("\t%s", impl->name);

>    putchar ('\n');

>

> -  for (i = 1; i < 16; ++i)

> +  for (i = 1; i < 32; ++i)

>      {

>        do_test (i * CHARBYTES, i * CHARBYTES, i, 0);

>        do_test (i * CHARBYTES, i * CHARBYTES, i, 1);

>        do_test (i * CHARBYTES, i * CHARBYTES, i, -1);

>      }

>

> -  for (i = 0; i < 16; ++i)

> +  for (i = 0; i < 32; ++i)

>      {

>        do_test (0, 0, i, 0);

>        do_test (0, 0, i, 1);

>        do_test (0, 0, i, -1);

> +      do_test (4096 - i, 0, i, 0);

> +      do_test (4096 - i, 0, i, 1);

> +      do_test (4096 - i, 0, i, -1);

> +      do_test (4095, 0, i, 0);

> +      do_test (4095, 0, i, 1);

> +      do_test (4095, 0, i, -1);

> +      do_test (4095, 4095, i, 0);

> +      do_test (4095, 4095, i, 1);

> +      do_test (4095, 4095, i, -1);

> +      do_test (4000, 95, i, 0);

> +      do_test (4000, 95, i, 1);

> +      do_test (4000, 95, i, -1);

> +    }

> +

> +  for (i = 33; i < 385; i += 32)

> +    {

> +      do_test (0, 0, i, 0);

> +      do_test (0, 0, i, 1);

> +      do_test (0, 0, i, -1);

> +      do_test (i, 0, i, 0);

> +      do_test (0, i, i, 1);

> +      do_test (i, i, i, -1);

>      }

>

>    for (i = 1; i < 10; ++i)

> @@ -506,13 +528,19 @@ test_main (void)

>        do_test (0, 0, 2 << i, 0);

>        do_test (0, 0, 2 << i, 1);

>        do_test (0, 0, 2 << i, -1);

> -      do_test (0, 0, 16 << i, 0);

>        do_test ((8 - i) * CHARBYTES, (2 * i) * CHARBYTES, 16 << i, 0);

> +      do_test (0, 0, 16 << i, 0);

>        do_test (0, 0, 16 << i, 1);

>        do_test (0, 0, 16 << i, -1);

> +      do_test (i, 0, 2 << i, 0);

> +      do_test (0, i, 2 << i, 1);

> +      do_test (i, i, 2 << i, -1);

> +      do_test (i, 0, 16 << i, 0);

> +      do_test (0, i, 16 << i, 1);

> +      do_test (i, i, 16 << i, -1);

>      }

>

> -  for (i = 1; i < 8; ++i)

> +  for (i = 1; i < 10; ++i)

>      {

>        do_test (i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 0);

>        do_test (i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 1);

> --

> 2.29.2

>


LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>


Thanks.

-- 
H.J.

Patch

diff --git a/benchtests/bench-memcmp.c b/benchtests/bench-memcmp.c
index eb0f94a0f1..744c7ec5ba 100644
--- a/benchtests/bench-memcmp.c
+++ b/benchtests/bench-memcmp.c
@@ -88,11 +88,11 @@  do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,
   if (len == 0)
     return;
 
-  align1 &= 63;
+  align1 &= (4096 - CHARBYTES);
   if (align1 + (len + 1) * CHARBYTES >= page_size)
     return;
 
-  align2 &= 63;
+  align2 &= (4096 - CHARBYTES);
   if (align2 + (len + 1) * CHARBYTES >= page_size)
     return;
 
@@ -100,6 +100,7 @@  do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len,
   json_attr_uint (json_ctx, "length", (double) len);
   json_attr_uint (json_ctx, "align1", (double) align1);
   json_attr_uint (json_ctx, "align2", (double) align2);
+  json_attr_uint (json_ctx, "result", (double) exp_result);
   json_array_begin (json_ctx, "timings");
 
   FOR_EACH_IMPL (impl, 0)
@@ -145,18 +146,31 @@  test_main (void)
   json_array_end (&json_ctx);
 
   json_array_begin (&json_ctx, "results");
-  for (i = 1; i < 16; ++i)
+  for (i = 1; i < 32; ++i)
     {
       do_test (&json_ctx, i * CHARBYTES, i * CHARBYTES, i, 0);
       do_test (&json_ctx, i * CHARBYTES, i * CHARBYTES, i, 1);
       do_test (&json_ctx, i * CHARBYTES, i * CHARBYTES, i, -1);
     }
 
-  for (i = 0; i < 16; ++i)
+  for (i = 0; i < 32; ++i)
     {
       do_test (&json_ctx, 0, 0, i, 0);
       do_test (&json_ctx, 0, 0, i, 1);
       do_test (&json_ctx, 0, 0, i, -1);
+      do_test (&json_ctx, 4096 - i, 0, i, 0);
+      do_test (&json_ctx, 4096 - i, 0, i, 1);
+      do_test (&json_ctx, 4096 - i, 0, i, -1);
+    }
+
+  for (i = 33; i < 385; i += 32)
+    {
+      do_test (&json_ctx, 0, 0, i, 0);
+      do_test (&json_ctx, 0, 0, i, 1);
+      do_test (&json_ctx, 0, 0, i, -1);
+      do_test (&json_ctx, i, 0, i, 0);
+      do_test (&json_ctx, 0, i, i, 1);
+      do_test (&json_ctx, i, i, i, -1);
     }
 
   for (i = 1; i < 10; ++i)
@@ -164,13 +178,19 @@  test_main (void)
       do_test (&json_ctx, 0, 0, 2 << i, 0);
       do_test (&json_ctx, 0, 0, 2 << i, 1);
       do_test (&json_ctx, 0, 0, 2 << i, -1);
-      do_test (&json_ctx, 0, 0, 16 << i, 0);
       do_test (&json_ctx, (8 - i) * CHARBYTES, (2 * i) * CHARBYTES, 16 << i, 0);
+      do_test (&json_ctx, 0, 0, 16 << i, 0);
       do_test (&json_ctx, 0, 0, 16 << i, 1);
       do_test (&json_ctx, 0, 0, 16 << i, -1);
+      do_test (&json_ctx, i, 0, 2 << i, 0);
+      do_test (&json_ctx, 0, i, 2 << i, 1);
+      do_test (&json_ctx, i, i, 2 << i, -1);
+      do_test (&json_ctx, i, 0, 16 << i, 0);
+      do_test (&json_ctx, 0, i, 16 << i, 1);
+      do_test (&json_ctx, i, i, 16 << i, -1);
     }
 
-  for (i = 1; i < 8; ++i)
+  for (i = 1; i < 10; ++i)
     {
       do_test (&json_ctx, i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 0);
       do_test (&json_ctx, i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 1);
diff --git a/string/test-memcmp.c b/string/test-memcmp.c
index 02ea9b782d..fbda26a41e 100644
--- a/string/test-memcmp.c
+++ b/string/test-memcmp.c
@@ -111,11 +111,11 @@  do_test (size_t align1, size_t align2, size_t len, int exp_result)
   if (len == 0)
     return;
 
-  align1 &= 63;
+  align1 &= (4096 - CHARBYTES);
   if (align1 + (len + 1) * CHARBYTES >= page_size)
     return;
 
-  align2 &= 63;
+  align2 &= (4096 - CHARBYTES);
   if (align2 + (len + 1) * CHARBYTES >= page_size)
     return;
 
@@ -487,18 +487,40 @@  test_main (void)
     printf ("\t%s", impl->name);
   putchar ('\n');
 
-  for (i = 1; i < 16; ++i)
+  for (i = 1; i < 32; ++i)
     {
       do_test (i * CHARBYTES, i * CHARBYTES, i, 0);
       do_test (i * CHARBYTES, i * CHARBYTES, i, 1);
       do_test (i * CHARBYTES, i * CHARBYTES, i, -1);
     }
 
-  for (i = 0; i < 16; ++i)
+  for (i = 0; i < 32; ++i)
     {
       do_test (0, 0, i, 0);
       do_test (0, 0, i, 1);
       do_test (0, 0, i, -1);
+      do_test (4096 - i, 0, i, 0);
+      do_test (4096 - i, 0, i, 1);
+      do_test (4096 - i, 0, i, -1);
+      do_test (4095, 0, i, 0);
+      do_test (4095, 0, i, 1);
+      do_test (4095, 0, i, -1);
+      do_test (4095, 4095, i, 0);
+      do_test (4095, 4095, i, 1);
+      do_test (4095, 4095, i, -1);
+      do_test (4000, 95, i, 0);
+      do_test (4000, 95, i, 1);
+      do_test (4000, 95, i, -1);
+    }
+
+  for (i = 33; i < 385; i += 32)
+    {
+      do_test (0, 0, i, 0);
+      do_test (0, 0, i, 1);
+      do_test (0, 0, i, -1);
+      do_test (i, 0, i, 0);
+      do_test (0, i, i, 1);
+      do_test (i, i, i, -1);
     }
 
   for (i = 1; i < 10; ++i)
@@ -506,13 +528,19 @@  test_main (void)
       do_test (0, 0, 2 << i, 0);
       do_test (0, 0, 2 << i, 1);
       do_test (0, 0, 2 << i, -1);
-      do_test (0, 0, 16 << i, 0);
       do_test ((8 - i) * CHARBYTES, (2 * i) * CHARBYTES, 16 << i, 0);
+      do_test (0, 0, 16 << i, 0);
       do_test (0, 0, 16 << i, 1);
       do_test (0, 0, 16 << i, -1);
+      do_test (i, 0, 2 << i, 0);
+      do_test (0, i, 2 << i, 1);
+      do_test (i, i, 2 << i, -1);
+      do_test (i, 0, 16 << i, 0);
+      do_test (0, i, 16 << i, 1);
+      do_test (i, i, 16 << i, -1);
     }
 
-  for (i = 1; i < 8; ++i)
+  for (i = 1; i < 10; ++i)
     {
       do_test (i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 0);
       do_test (i * CHARBYTES, 2 * (i * CHARBYTES), 8 << i, 1);