From patchwork Thu May 19 11:34:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 12377 Received: (qmail 98902 invoked by alias); 19 May 2016 11:34:58 -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 98871 invoked by uid 89); 19 May 2016 11:34:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, SPF_PASS autolearn=ham version=3.3.2 spammy=prediction, 23s, sk:inner_l, *impl X-HELO: eu-smtp-delivery-143.mimecast.com From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: Re: [PATCH] Add random memcpy test Date: Thu, 19 May 2016 11:34:40 +0000 Message-ID: References: In-Reply-To: x-ms-office365-filtering-correlation-id: ba8127f0-7661-485d-e1bc-08d37fd99128 x-microsoft-exchange-diagnostics: 1; AM3PR08MB0087; 5:bk829K2JLx2tFz9hUDupicxGAR443s/zb3pUUClY+zBn93uYEI6uwqfcvbuZfPIEsp55i3M1Z8v54jHyoWnpC8TyLc99fwuVGeVIKodc/p4GG12Ub61akOUT//GKGQaDd5TLsdFFyGBgmjfaeHqmBQ==; 24:iTyRbGoFq66retkJQvyqWOl9kIsk/7A4yCmax91jjfSJUufYkJVSa2vLkH6xELDJUm8zZD6n2AD0FSjQUINd6FuaX/DASAlwqsgx2U2/0GQ=; 7:4MWG7h7u7WxTEis6xgjehvM+s++AhKJyfrB1lxrUQGLjNtiBs0+opeGdFWaMEUbNOHoM/FJ4og2zHIziXQIPxlpJLYR1GA0C7sDfRgFONOVh6F0YNi8AMBlIBZPQWHtfdIw+Tjce+ZHbAQiRGjOCuS8P568yAonsMa0EW8pdUmJo0krR3f88xVcxrT4jVufW; 20:teaS+2VYXKnQZZxASNBk8IhvKE07yWzXX4RWVDZwXWO6SnMoT2PGA5rpx9ihmlQaxLOJkRzK4aGhjgd2VDyZLL05+wQQLu+vkpPOlzHaOmwNX5a7j15YmPubIiXGscV0XbqMqGV98Ou5SkN9M6Jz2V2BKQLBkyALX87c5M+z0hk= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM3PR08MB0087; nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(6055026); SRVR:AM3PR08MB0087; BCL:0; PCL:0; RULEID:; SRVR:AM3PR08MB0087; x-forefront-prvs: 094700CA91 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(6009001)(377424004)(450100001)(9686002)(87936001)(33656002)(575784001)(86362001)(189998001)(6116002)(92566002)(586003)(8936002)(8676002)(3846002)(3280700002)(76176999)(81166006)(50986999)(110136002)(102836003)(11100500001)(66066001)(76576001)(54356999)(19580395003)(19580405001)(106116001)(5002640100001)(5004730100002)(5008740100001)(74316001)(5003600100002)(3900700001)(1220700001)(2900100001)(3660700001)(2950100001)(4326007)(2906002)(5250100002)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM3PR08MB0087; H:AM3PR08MB0088.eurprd08.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-originalarrivaltime: 19 May 2016 11:34:40.7190 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM3PR08MB0087 X-MC-Unique: sR2oqBsgQqORLcHJeGtmKA-1 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"