From patchwork Tue Nov 5 17:35:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krzysztof Koch X-Patchwork-Id: 35654 Received: (qmail 18222 invoked by alias); 5 Nov 2019 17:35:34 -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 18211 invoked by uid 89); 5 Nov 2019 17:35:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: EUR04-HE1-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tkrEFJdyMh4S7mhzEwCiq+PVqCPQY2StZtjeupIh94w=; b=1vvfUP0y7chMrM9+X+hv6UIvUz0SIjXYOQc7THkloH7tDHhczoEfCsGq5iLZ8KP2T6A0OMt6V1uO5ABVYpxAhZ0Ypb3vyz6miuM/rTK4V1Qw/kYzn1YiRzgKyS+fg5SQgG55ZQqpEscOmu9OsvvhSaLUTJ4pZGCuf8ZhT0OdKxo= Authentication-Results: spf=fail (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; sourceware.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; sourceware.org; dmarc=none action=none header.from=arm.com; Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; X-CR-MTA-TID: 64aa7808 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eTMc8oPMYiNakJ/XZwkCCdgbSNXOlR93V3DYwSOcd8/lIVaCaZbTcltcMxGVBbi80LxjYwVnUjxtob8QUTsS0XfoElB1CUT5i/IZJ4SaJEZvJoUwdQumTwIpHzN8Wfq5BARejwrwF3gcQEi4aPuFVsSDkJqYD9cqhQnzm1b92lTDcraRFtPPhehS05JeNS4peIUyqpAPgQ/r4TCvU9LKNfmAAXxoUE5BQLZv/nKJOms2VBfcbPwv7ykMWpeujDCEeOdtJUzdt5t/CeePHSJjXGSoIlEEdhvn4s8L49Wf7C4DO6MFvdT+TsoTylyRnDTzKK8V6Hayim/e8JKwGfm+2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tkrEFJdyMh4S7mhzEwCiq+PVqCPQY2StZtjeupIh94w=; b=Fp0pM9bDG5HYMIQIK8MWZSEYIMNnMrjFdGUqUAydMPSb9FpJcchtEzozN2NpB5SU4pf0XklnPX9DlNX/EblF575e0S9KhDyLH0sW/Whf7tg3DeUrqEjjcVbF9sew1uB+edydI9fuuBI1xbvcCsj9XFg9ClxjdVgiS7zuq+Q0Op+ms9sDDeToQ4Y6kyZZMh9NfRsZr4W1RLtlV98Ce4EmQc0B414GO9f01IQi6/+f/LZ3GrosA1wqYc2kJD6Q0FvJiwHnZJfE5FcqBL5MOlVgnXgz37UwWC9pwIYHIJDgVUOj2cxyGC8Pd0risG44Ff4UAmq6Z7jRJAXcFmDk6w5/HA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tkrEFJdyMh4S7mhzEwCiq+PVqCPQY2StZtjeupIh94w=; b=1vvfUP0y7chMrM9+X+hv6UIvUz0SIjXYOQc7THkloH7tDHhczoEfCsGq5iLZ8KP2T6A0OMt6V1uO5ABVYpxAhZ0Ypb3vyz6miuM/rTK4V1Qw/kYzn1YiRzgKyS+fg5SQgG55ZQqpEscOmu9OsvvhSaLUTJ4pZGCuf8ZhT0OdKxo= From: Krzysztof Koch To: "libc-alpha@sourceware.org" CC: nd Subject: [PATCH] aarch64: Increase small and medium cases for __memcpy_generic Date: Tue, 5 Nov 2019 17:35:18 +0000 Message-ID: x-ts-tracking-id: c63927b0-2d9b-48fb-8ec5-5e54bbba1533.0 x-checkrecipientchecked: true Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=Krzysztof.Koch@arm.com; X-MS-Exchange-PUrlCount: 1 x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:9508;OLM:9508; X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(396003)(346002)(366004)(39860400002)(376002)(136003)(199004)(189003)(52536014)(4326008)(66616009)(81156014)(3846002)(6116002)(486006)(66066001)(476003)(966005)(33656002)(5660300002)(6916009)(305945005)(2351001)(186003)(74316002)(2906002)(2501003)(14454004)(99936001)(7736002)(478600001)(316002)(5024004)(14444005)(5640700003)(86362001)(71200400001)(71190400001)(99286004)(26005)(81166006)(66476007)(64756008)(66446008)(102836004)(8676002)(76116006)(25786009)(66946007)(8936002)(66556008)(55016002)(9686003)(256004)(7696005)(6306002)(6436002)(6506007)(41533002)(357404004); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB4782; H:VE1PR08MB4783.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: Tlf1W5YffoFNmGtvmIoWoaan9N9yp2eXVhFOBd78Xr3SJuPS925k2Qkj1CSvNbm1mt9zngPKQK9uj/zl1DEBh/wYdrLG1Yau8h6vM6lFBM+Iu/GK0PFGmaPsiB6JvyBHVTzXYftXgC5URH7xxerUCgbQf9NFUm0w3RiorNBl+FJGlhwEu7Y2Tc05YoI1CkcgHkbbQ/9D+15yVqF+jOOOZny9Xi0QGNc3xzNH4vTvkXcuB1KKCxTFYOm36dbjEPx3cyLOfqJbofH/A0dSjQLUYG7kuMNKINTT3WEZmjNmP//LOD5Zm1wcWA9j5N6/tkGi3lFiZ5PPqkVafzDnt2OqKA2kg24T4v1bhxTdDGMpMY7zA4y1wNbG7iSUW2u+I6GfxMnk4SUzPBHD+bTRh6rZwy7p1OWTx9NY9I+6WvFLRQk7pOHxGR0Gs16+aqs6shndegkMoyL0/B7dyr9Z1jd7Xwecf8FF/J6HjuenZd3Xa1U= x-ms-exchange-transport-forked: True MIME-Version: 1.0 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Krzysztof.Koch@arm.com; Return-Path: Krzysztof.Koch@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Office365-Filtering-Correlation-Id-Prvs: 5b1731e0-19e1-41d6-e7fb-08d7621686ea Increase the upper bound on medium cases from 96 to 128 bytes. Now, up to 128 bytes are copied unrolled. Increase the upper bound on small cases from 16 to 32 bytes so that copies of 17-32 bytes are not impacted by the larger medium case. Benchmarking: The attached figures show relative timing difference with respect to 'memcpy_generic', which is the existing implementation. 'memcpy_med_128' denotes the the version of memcpy_generic with only the medium case enlarged. The 'memcpy_med_128_small_32' numbers are for the version of memcpy_generic submitted in this patch, which has both medium and small cases enlarged. The figures were generated using the script from: https://www.sourceware.org/ml/libc-alpha/2019-10/msg00563.html Depending on the platform, the performance improvement in the bench-memcpy-random.c benchmark ranges from 6% to 20% between the original and final version of memcpy.S Tested against GLIBC testsuite and randomized tests. --- sysdeps/aarch64/memcpy.S | 82 +++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/sysdeps/aarch64/memcpy.S b/sysdeps/aarch64/memcpy.S index 6e4f4a7..10801aa 100644 --- a/sysdeps/aarch64/memcpy.S +++ b/sysdeps/aarch64/memcpy.S @@ -41,17 +41,19 @@ #define C_h x11 #define D_l x12 #define D_h x13 -#define E_l src -#define E_h count -#define F_l srcend -#define F_h dst +#define E_l x14 +#define E_h x15 +#define F_l x16 +#define F_h x17 #define G_l count #define G_h dst +#define H_l src +#define H_h srcend #define tmp1 x14 -/* Copies are split into 3 main cases: small copies of up to 16 bytes, - medium copies of 17..96 bytes which are fully unrolled. Large copies - of more than 96 bytes align the destination and use an unrolled loop +/* Copies are split into 3 main cases: small copies of up to 32 bytes, + medium copies of 33..128 bytes which are fully unrolled. Large copies + of more than 128 bytes align the destination and use an unrolled loop processing 64 bytes per iteration. In order to share code with memmove, small and medium copies read all data before writing, allowing any kind of overlap. So small, medium @@ -73,7 +75,7 @@ ENTRY_ALIGN (MEMMOVE, 6) DELOUSE (2) sub tmp1, dstin, src - cmp count, 96 + cmp count, 128 ccmp tmp1, count, 2, hi b.lo L(move_long) @@ -89,31 +91,39 @@ ENTRY (MEMCPY) prfm PLDL1KEEP, [src] add srcend, src, count add dstend, dstin, count - cmp count, 16 - b.ls L(copy16) - cmp count, 96 + cmp count, 32 + b.ls L(copy32) + cmp count, 128 b.hi L(copy_long) - /* Medium copies: 17..96 bytes. */ - sub tmp1, count, 1 + /* Medium copies: 33..128 bytes. */ ldp A_l, A_h, [src] - tbnz tmp1, 6, L(copy96) - ldp D_l, D_h, [srcend, -16] - tbz tmp1, 5, 1f ldp B_l, B_h, [src, 16] ldp C_l, C_h, [srcend, -32] + ldp D_l, D_h, [srcend, -16] + cmp count, 64 + b.hi L(copy128) + stp A_l, A_h, [dstin] stp B_l, B_h, [dstin, 16] stp C_l, C_h, [dstend, -32] -1: - stp A_l, A_h, [dstin] stp D_l, D_h, [dstend, -16] ret .p2align 4 - /* Small copies: 0..16 bytes. */ -L(copy16): - cmp count, 8 + /* Small copies: 0..32 bytes. */ +L(copy32): + /* 16-32 bytes. */ + cmp count, 16 b.lo 1f + ldp A_l, A_h, [src] + ldp B_l, B_h, [srcend, -16] + stp A_l, A_h, [dstin] + stp B_l, B_h, [dstend, -16] + ret + .p2align 4 +1: + /* 8-15 bytes. */ + tbz count, 3, 1f ldr A_l, [src] ldr A_h, [srcend, -8] str A_l, [dstin] @@ -121,6 +131,7 @@ L(copy16): ret .p2align 4 1: + /* 4-7 bytes. */ tbz count, 2, 1f ldr A_lw, [src] ldr A_hw, [srcend, -4] @@ -142,24 +153,25 @@ L(copy16): 2: ret .p2align 4 - /* Copy 64..96 bytes. Copy 64 bytes from the start and - 32 bytes from the end. */ -L(copy96): - ldp B_l, B_h, [src, 16] - ldp C_l, C_h, [src, 32] - ldp D_l, D_h, [src, 48] - ldp E_l, E_h, [srcend, -32] - ldp F_l, F_h, [srcend, -16] + /* Copy 65..128 bytes. Copy 64 bytes from the start and + 64 bytes from the end. */ +L(copy128): + ldp E_l, E_h, [src, 32] + ldp F_l, F_h, [src, 48] + ldp G_l, G_h, [srcend, -64] + ldp H_l, H_h, [srcend, -48] stp A_l, A_h, [dstin] stp B_l, B_h, [dstin, 16] - stp C_l, C_h, [dstin, 32] - stp D_l, D_h, [dstin, 48] - stp E_l, E_h, [dstend, -32] - stp F_l, F_h, [dstend, -16] + stp E_l, E_h, [dstin, 32] + stp F_l, F_h, [dstin, 48] + stp G_l, G_h, [dstend, -64] + stp H_l, H_h, [dstend, -48] + stp C_l, C_h, [dstend, -32] + stp D_l, D_h, [dstend, -16] ret /* Align DST to 16 byte alignment so that we don't cross cache line - boundaries on both loads and stores. There are at least 96 bytes + boundaries on both loads and stores. There are at least 128 bytes to copy, so copy 16 bytes unaligned and then align. The loop copies 64 bytes per iteration and prefetches one iteration ahead. */ @@ -215,7 +227,7 @@ L(move_long): add dstend, dstin, count /* Align dstend to 16 byte alignment so that we don't cross cache line - boundaries on both loads and stores. There are at least 96 bytes + boundaries on both loads and stores. There are at least 128 bytes to copy, so copy 16 bytes unaligned and then align. The loop copies 64 bytes per iteration and prefetches one iteration ahead. */