From 94aca5e740d6101f91002d027776252340f6abef Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Tue, 11 Jun 2013 20:51:55 +0530 Subject: [PATCH] Port remaining string benchmarks There were a few more string benchmarks (strcpy_chk and stpcpy_check) in the debug directory that needed to be ported over. --- ChangeLog | 12 ++ benchtests/Makefile | 3 +- benchtests/bench-stpcpy_chk-ifunc.c | 20 +++ benchtests/bench-stpcpy_chk.c | 45 +++++++ benchtests/bench-strcpy_chk-ifunc.c | 20 +++ .../bench-strcpy_chk.c | 139 +-------------------- debug/test-strcpy_chk.c | 24 ---- 7 files changed, 103 insertions(+), 160 deletions(-) create mode 100644 benchtests/bench-stpcpy_chk-ifunc.c create mode 100644 benchtests/bench-stpcpy_chk.c create mode 100644 benchtests/bench-strcpy_chk-ifunc.c copy debug/test-strcpy_chk.c => benchtests/bench-strcpy_chk.c (67%) diff --git a/ChangeLog b/ChangeLog index f2f9f7da03..3a451b4efc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2013-06-11 Siddhesh Poyarekar + + * benchtests/Makefile (string-bench): Add strcpy_chk and + stpcpy_chk. + * benchtests/bench-stpcpy_chk-ifunc.c: New file. + * benchtests/bench-stpcpy_chk.c: New file. + * benchtests/bench-strcpy_chk-ifunc.c: New file. + * benchtests/bench-strcpy_chk.c: New file. + * debug/test-strcpy_chk.c (do_one_test): Remove HP_TIMING + code. + (do_test): Likewise. + 2013-06-11 Ryan S. Arnold * sysdeps/powerpc/dl-procinfo.c (_dl_powerpc_platforms): Add ppc405, diff --git a/benchtests/Makefile b/benchtests/Makefile index 5023c7c9c2..ba313d2cf8 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -27,7 +27,8 @@ bench := acos acosh asin asinh atan atanh cos cosh exp log modf pow rint sin \ string-bench := bcopy bzero memccpy memchr memcmp memmem memmove mempcpy \ memset rawmemchr stpcpy stpncpy strcasecmp strcasestr strcat \ strchr strchrnul strcmp strcpy strcspn strlen strncasecmp \ - strncat strncmp strncpy strnlen strpbrk strrchr strspn strstr + strncat strncmp strncpy strnlen strpbrk strrchr strspn strstr \ + strcpy_chk stpcpy_chk string-bench-ifunc := $(addsuffix -ifunc, $(string-bench)) string-bench-all := $(string-bench) $(string-bench-ifunc) diff --git a/benchtests/bench-stpcpy_chk-ifunc.c b/benchtests/bench-stpcpy_chk-ifunc.c new file mode 100644 index 0000000000..3449615bfe --- /dev/null +++ b/benchtests/bench-stpcpy_chk-ifunc.c @@ -0,0 +1,20 @@ +/* Measure IFUNC implementations of stpcpy checking function. + Copyright (C) 2013 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 + . */ + +#define TEST_IFUNC 1 +#include "bench-stpcpy_chk.c" diff --git a/benchtests/bench-stpcpy_chk.c b/benchtests/bench-stpcpy_chk.c new file mode 100644 index 0000000000..964ca5e2ba --- /dev/null +++ b/benchtests/bench-stpcpy_chk.c @@ -0,0 +1,45 @@ +/* Measure stpcpy checking functions. + Copyright (C) 2013 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 + . */ + +#define STRCPY_RESULT(dst, len) ((dst) + (len)) +#define TEST_MAIN +#define TEST_NAME "stpcpy_chk" +#include "bench-string.h" + +extern void __attribute__ ((noreturn)) __chk_fail (void); +char *simple_stpcpy_chk (char *, const char *, size_t); +extern char *normal_stpcpy (char *, const char *, size_t) + __asm ("stpcpy"); +extern char *__stpcpy_chk (char *, const char *, size_t); + +IMPL (simple_stpcpy_chk, 0) +IMPL (normal_stpcpy, 1) +IMPL (__stpcpy_chk, 2) + +char * +simple_stpcpy_chk (char *dst, const char *src, size_t len) +{ + if (! len) + __chk_fail (); + while ((*dst++ = *src++) != '\0') + if (--len == 0) + __chk_fail (); + return dst - 1; +} + +#include "bench-strcpy_chk.c" diff --git a/benchtests/bench-strcpy_chk-ifunc.c b/benchtests/bench-strcpy_chk-ifunc.c new file mode 100644 index 0000000000..2dd2aa318d --- /dev/null +++ b/benchtests/bench-strcpy_chk-ifunc.c @@ -0,0 +1,20 @@ +/* Measure IFUNC implementations of strcpy checking function. + Copyright (C) 2012-2013 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 + . */ + +#define TEST_IFUNC 1 +#include "bench-strcpy_chk.c" diff --git a/debug/test-strcpy_chk.c b/benchtests/bench-strcpy_chk.c similarity index 67% copy from debug/test-strcpy_chk.c copy to benchtests/bench-strcpy_chk.c index 1c64c60fb7..29e57285b0 100644 --- a/debug/test-strcpy_chk.c +++ b/benchtests/bench-strcpy_chk.c @@ -1,7 +1,6 @@ -/* Test and measure __strcpy_chk functions. - Copyright (C) 1999-2013 Free Software Foundation, Inc. +/* Measure __strcpy_chk functions. + Copyright (C) 2013 Free Software Foundation, Inc. This file is part of the GNU C Library. - Written by Jakub Jelinek , 1999. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -21,7 +20,7 @@ # define STRCPY_RESULT(dst, len) dst # define TEST_MAIN # define TEST_NAME "strcpy_chk" -# include "../string/test-string.h" +# include "bench-string.h" /* This test case implicitly tests the availability of the __chk_fail symbol, which is part of the public ABI and may be used @@ -161,135 +160,6 @@ do_test (size_t align1, size_t align2, size_t len, size_t dlen, int max_char) putchar ('\n'); } -static void -do_random_tests (void) -{ - size_t i, j, n, align1, align2, len, dlen; - unsigned char *p1 = buf1 + page_size - 512; - unsigned char *p2 = buf2 + page_size - 512; - unsigned char *res; - - for (n = 0; n < ITERATIONS; n++) - { - align1 = random () & 31; - if (random () & 1) - align2 = random () & 31; - else - align2 = align1 + (random () & 24); - len = random () & 511; - j = align1; - if (align2 > j) - j = align2; - if (len + j >= 511) - len = 510 - j - (random () & 7); - j = len + align1 + 64; - if (j > 512) - j = 512; - for (i = 0; i < j; i++) - { - if (i == len + align1) - p1[i] = 0; - else - { - p1[i] = random () & 255; - if (i >= align1 && i < len + align1 && !p1[i]) - p1[i] = (random () & 127) + 3; - } - } - - switch (random () & 7) - { - case 0: - dlen = len - (random () & 31); - if (dlen > len) - dlen = len; - break; - case 1: - dlen = (size_t) -1; - break; - case 2: - dlen = len + 1 + (random () & 65535); - break; - case 3: - dlen = len + 1 + (random () & 255); - break; - case 4: - dlen = len + 1 + (random () & 31); - break; - case 5: - dlen = len + 1 + (random () & 7); - break; - case 6: - dlen = len + 1 + (random () & 3); - break; - default: - dlen = len + 1; - break; - } - - FOR_EACH_IMPL (impl, 1) - { - if (dlen <= len) - { - if (impl->test != 1) - { - chk_fail_ok = 1; - if (setjmp (chk_fail_buf) == 0) - { - res = (unsigned char *) - CALL (impl, (char *) p2 + align2, - (char *) p1 + align1, dlen); - printf ("Iteration %zd - did not __chk_fail\n", n); - chk_fail_ok = 0; - ret = 1; - } - } - continue; - } - memset (p2 - 64, '\1', 512 + 64); - res = (unsigned char *) - CALL (impl, (char *) p2 + align2, (char *) p1 + align1, dlen); - if (res != STRCPY_RESULT (p2 + align2, len)) - { - printf ("\ -Iteration %zd - wrong result in function %s (%zd, %zd, %zd) %p != %p\n", - n, impl->name, align1, align2, len, res, - STRCPY_RESULT (p2 + align2, len)); - ret = 1; - } - for (j = 0; j < align2 + 64; ++j) - { - if (p2[j - 64] != '\1') - { - printf ("\ -Iteration %zd - garbage before, %s (%zd, %zd, %zd)\n", - n, impl->name, align1, align2, len); - ret = 1; - break; - } - } - for (j = align2 + len + 1; j < 512; ++j) - { - if (p2[j] != '\1') - { - printf ("\ -Iteration %zd - garbage after, %s (%zd, %zd, %zd)\n", - n, impl->name, align1, align2, len); - ret = 1; - break; - } - } - if (memcmp (p1 + align1, p2 + align2, len + 1)) - { - printf ("\ -Iteration %zd - different strings, %s (%zd, %zd, %zd)\n", - n, impl->name, align1, align2, len); - ret = 1; - } - } - } -} - int test_main (void) { @@ -386,8 +256,7 @@ test_main (void) do_test (i, i, (8 << i), (8 << i) + i + 3, 255); } - do_random_tests (); - return ret; + return 0; } #include "../test-skeleton.c" diff --git a/debug/test-strcpy_chk.c b/debug/test-strcpy_chk.c index 1c64c60fb7..736ef3cd7a 100644 --- a/debug/test-strcpy_chk.c +++ b/debug/test-strcpy_chk.c @@ -110,24 +110,6 @@ do_one_test (impl_t *impl, char *dst, const char *src, ret = 1; return; } - - if (HP_TIMING_AVAIL) - { - hp_timing_t start __attribute ((unused)); - hp_timing_t stop __attribute ((unused));; - hp_timing_t best_time = ~ (hp_timing_t) 0; - size_t i; - - for (i = 0; i < 32; ++i) - { - HP_TIMING_NOW (start); - CALL (impl, dst, src, dlen); - HP_TIMING_NOW (stop); - HP_TIMING_BEST (best_time, start, stop); - } - - printf ("\t%zd", (size_t) best_time); - } } static void @@ -151,14 +133,8 @@ do_test (size_t align1, size_t align2, size_t len, size_t dlen, int max_char) s1[i] = 32 + 23 * i % (max_char - 32); s1[len] = 0; - if (HP_TIMING_AVAIL && dlen > len) - printf ("Length %4zd, alignment %2zd/%2zd:", len, align1, align2); - FOR_EACH_IMPL (impl, 0) do_one_test (impl, s2, s1, len, dlen); - - if (HP_TIMING_AVAIL && dlen > len) - putchar ('\n'); } static void -- 2.11.4.GIT