From patchwork Tue Feb 7 13:06:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 19142 Received: (qmail 96309 invoked by alias); 7 Feb 2017 13:06:33 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 96296 invoked by uid 89); 7 Feb 2017 13:06:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_50, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=CALL, test_name, prediction, 387 X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: Re: [PATCH] Add random memcpy test Date: Tue, 7 Feb 2017 13:06:10 +0000 Message-ID: References: , , In-Reply-To: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-ms-office365-filtering-correlation-id: 241a70ba-3056-4a48-0132-08d44f5a165a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081); SRVR:AM5PR0802MB2612; x-microsoft-exchange-diagnostics: 1; AM5PR0802MB2612; 7:Ot5gwWDWbRplPdZ9yAyEEAMOk+39b5r+EZD2rwqlK6Y1+2NfD8D9eEZQlk4w2vC9DHxPe5FnTS+CITJT/dTLvtDnRcUG4aqhJZmCFrw32Q9AnpsrqbSxdk4a0r0wgDGKA8Jj0IBp+tW4McgdlXq31M/EHJ6MwrArY8XeOGc5AnJsviQdNqi1tpiZrKX0gIwnJkWfHGJNlrGm8KD6v8w5mFs47uNzxrLSHEfrDQJaT0f8SQqD9D1DmqVDAy63uAiC1J7EZ4yJD09lrd8fy4/8JWyf46zXnu9XIigUCNdZZZUFXra+Gx927p2lSu9cwx6xP6fsKLev3Kk7drjBt37OagQSibs07BQj7Fb7yuACJu/zmOh1g6s546lxpxa/bxF0CWISm4pFV2UMYmiliQK+2D02SW3FZl747B87/HM3Z98jkGD1X5y0P7e3NG/aa8cZp65O/DAZHKUUDAQuZTI7T6qRsGA2I/sJGn5rUwlSSA2c30wGGK32Zxl22AQflnJNGooZeCkz0s74wpkmi7MDJw== nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(250305191791016)(180628864354917)(22074186197030); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(2017020603029)(5005006)(20170203043)(8121501046)(10201501046)(3002001)(6055026)(6041248)(20161123560025)(20161123564025)(20161123555025)(20161123558025)(20161123562025)(6072148); SRVR:AM5PR0802MB2612; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2612; x-forefront-prvs: 0211965D06 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(7916002)(39850400002)(39840400002)(39450400003)(39860400002)(39410400002)(189002)(54534003)(377424004)(199003)(3280700002)(450100001)(68736007)(575784001)(86362001)(33656002)(53546003)(6246003)(2906002)(81156014)(6116002)(3660700001)(8676002)(8936002)(110136004)(38730400002)(4326007)(122556002)(81166006)(102836003)(3846002)(189998001)(305945005)(54356999)(99286003)(55016002)(76176999)(50986999)(7736002)(25786008)(6506006)(6436002)(229853002)(101416001)(97736004)(106356001)(92566002)(106116001)(53936002)(105586002)(5660300001)(7696004)(77096006)(9686003)(6306002)(74316002)(66066001)(2900100001)(2950100002)(6916009)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2612; H:AM5PR0802MB2610.eurprd08.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Feb 2017 13:06:10.5089 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2612 ping diff --git a/benchtests/Makefile b/benchtests/Makefile index 61077ea9b6f7d4c342192429a8d90ecdf9bdaea7..03311dd72856bf0e595a759b817cb772f0fd3a6f 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -38,7 +38,7 @@ string-benchset := bcopy bzero memccpy memchr memcmp memcpy memmem memmove \                    strcat strchr strchrnul strcmp strcpy strcspn strlen \                    strncasecmp strncat strncmp strncpy strnlen strpbrk strrchr \                    strspn strstr strcpy_chk stpcpy_chk memrchr strsep strtok \ -                  strcoll memcpy-large memmove-large memset-large +                  strcoll memcpy-large memcpy-random memmove-large memset-large  wcsmbs-benchset := wcslen wcsnlen wcscpy wcpcpy wcsncpy wcpncpy wcscat wcsncat \                    wcscmp wcsncmp wcschr wcschrnul wcsrchr wcsspn wcspbrk wcscspn \                    wmemchr wmemset wmemcmp diff --git a/benchtests/bench-memcpy-random.c b/benchtests/bench-memcpy-random.c new file mode 100644 index 0000000000000000000000000000000000000000..668d6a1d35074f4227be4e1ff424da556a377cef --- /dev/null +++ b/benchtests/bench-memcpy-random.c @@ -0,0 +1,130 @@ +/* Measure memcpy functions. +   Copyright (C) 2016 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 MIN_PAGE_SIZE 131072 +#define TEST_MAIN +#define TEST_NAME "memcpy-random" +#include "bench-string.h" + +IMPL (memcpy, 0) + +#define NUM_COPIES 2048 +#define NUM_DISTR  1024 + +typedef struct +{ +  uint16_t src; +  uint16_t dst; +  uint16_t len; +} copy_t; + +static copy_t copy[NUM_COPIES]; +static uint8_t copy_distribution[NUM_DISTR]; + +typedef char *(*proto_t) (char *, const char *, size_t); + + +static void +init_copy_distribution (void) +{ +  int i, n, pos = 0; +  for (i = 0; i < 256; i++) +    { +      if (i < 8) +       n = 1; +      else if (i < 16) +       n = 8; +      else if (i < 32) +       n = 6; +      else if (i < 64) +       n = 4; +      else if (i < 128) +       n = 2; +      else +       n = 1; + +      if ((i & 15) == 0) +       n = n * 7; +      else if ((i & 7) == 0) +       n = n * 5; +      else if ((i & 3) == 0) +       n = n * 3; + +      for ( ; n > 0 && pos < NUM_DISTR; n--) +       copy_distribution[pos++] = i; +    } +  for ( ; pos < NUM_DISTR; pos++) +    copy_distribution[pos] = 255; +} + +static void +do_one_test (impl_t *impl, char *dst, char *src, copy_t *copy, size_t n) +{ +  timing_t start, stop, cur; +  size_t iters = INNER_LOOP_ITERS * 20; + +  TIMING_NOW (start); +  for (int i = 0; i < iters; ++i) +    for (int j = 0; j < n; j++) +      CALL (impl, dst + copy[j].dst, src + copy[j].src, copy[j].len); +  TIMING_NOW (stop); + +  TIMING_DIFF (cur, start, stop); + +  TIMING_PRINT_MEAN ((double) cur, (double) iters); +} + +static void +do_test (size_t max_size) +{ +  for (int i = 0; i < max_size; i++) +    buf1[i] = i * 3; + +  for (int i = 0; i < NUM_COPIES; i++) +    { +      copy[i].dst = rand () & (max_size - 1); +      copy[i].src = rand () & (max_size - 1); +      copy[i].len = copy_distribution[rand () & (NUM_DISTR - 1)]; +    } + +  printf ("Memory size %6zd:", max_size); + +  FOR_EACH_IMPL (impl, 0) +    do_one_test (impl, (char *) buf2, (char *) buf1, copy, NUM_COPIES); + +  putchar ('\n'); +} + +int +test_main (void) +{ +  test_init (); +  init_copy_distribution (); + +  printf ("%23s", ""); +  FOR_EACH_IMPL (impl, 0) +    printf ("\t%s", impl->name); +  putchar ('\n'); + +  for (int i = 4; i <= 64; i = i * 2) +    do_test (i * 1024); + +  return ret; +} + +#include "../test-skeleton.c"