From patchwork Mon Jan 27 10:43:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Lapshin X-Patchwork-Id: 105431 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E628D385802C for ; Mon, 27 Jan 2025 10:45:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E628D385802C Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=espressifsystems.onmicrosoft.com header.i=@espressifsystems.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-espressifsystems-onmicrosoft-com header.b=Mxfbjpe2 X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on20702.outbound.protection.outlook.com [IPv6:2a01:111:f403:200e::702]) by sourceware.org (Postfix) with ESMTPS id 38B5D385843F for ; Mon, 27 Jan 2025 10:43:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38B5D385843F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=espressif.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=espressif.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 38B5D385843F Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=2a01:111:f403:200e::702 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1737974627; cv=pass; b=PF9QuBh5MPpANajxe6D+DB2CDAts1O30mxNpcIJm+W3jok6v8W8rnyDhkFkWLumcV/lSOl8F6ClR2s3fZVQexlVXeCIV3z5/NfZ6/nD3xX7E4jzf/gKE73FfUy4sBbRBm0PaIHB4RlgYliXrKai0l1WQntORHwTRJPAfmAx6jzY= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1737974627; c=relaxed/simple; bh=eXgqkyim4CQ2PgMjtvOpBUGwT4FUnuyw8SVpp8O5yH4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=lAPNcNnthq03YHpYAxOVmLEewmVVq9RMnzd/43KQOKeTB0DeZfe3vRArHNOYQyoCiaCrkNgMW1/OAESBoMn8J0LWyltYlh23c6JpsHqKVEXwGhG+V1mF65DCXHT/BLY/F3NYoRvEltwmVfPTWaf2Y+ipUF6YTdwZ+tjm2q/Q3VU= ARC-Authentication-Results: i=2; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38B5D385843F ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Kpf4yOy4nNGj29BGnfVvljAMBXCqKFxLB5xb12faCQULpcwB8UIcSkALboKENsZsCs+ItqKXhCDAmkGvvJClPwudFMLIm+87oO86W2cby1jhlmMrClYt/aDTFEw3coITtTPcatsw6b0po832M8PoVOz8rVP2XNsV4IsoA4JJ9rj6Tmz8AyxO7nny0LLJG8PsjFKNfHFAaA8dS7fP6owBVT6rh3vfw5GxuP3xbt961QYwwSpLwq+T3TFM+ew4ukTt2V+JXVI+BXXcVHbjZa7KIiQpGi2hIhv9/qGmzvcTSnLdFYF0g9XwO5kl0epFPv/hD0tCCqK4QSUGUnkIXHUNxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eXgqkyim4CQ2PgMjtvOpBUGwT4FUnuyw8SVpp8O5yH4=; b=SBraXApH/GxTarx7DlVSjpScHvCAPppJhQOl8cSshLJ2kJksGNZnRIh2u25isnZMY9AYqszoWW42SetbkZpDT19AWi7XBp9E0nmsU5EnINtuFAEZPA7UnA4vXcaZE8QPntP+iMBPGzY/cmptQXoLApGtoJt8JvcJKZLHCHq7igLXnho7ZOX/La7Q6qJuf/njXeJspiT/8JT3Q2pO5M5tJV/kmeLlF0URYFz3CHGjCyQzcsBJvgAlsFjb0Vk/4Ae3M8ru1aTfMgARE2ZgKvNPCBSaay4w9KHPR30JtM8dNWRua/EQ9Vo6G4YthdPL1P+idLsx7og1EjsdDHazOFiPzA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=espressif.com; dmarc=pass action=none header.from=espressif.com; dkim=pass header.d=espressif.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=espressifsystems.onmicrosoft.com; s=selector1-espressifsystems-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eXgqkyim4CQ2PgMjtvOpBUGwT4FUnuyw8SVpp8O5yH4=; b=Mxfbjpe2sJ3+uxe2e49wJXPc9nTZsOq66n7KxaNEXp3QIEEXMzV4z+1LHuyHxwv8GNSuWREmKNgQpFuPrRXMs71DNp/WfOOcZG0C/7fzTenH8eYuR8UT1LBp9R1q7RFxzHZo8fK//LBgwAijw9lape0/7nJueNlrtvR8xLtjJxU= Received: from TYZPR04MB5736.apcprd04.prod.outlook.com (2603:1096:400:1fa::7) by TYSPR04MB8166.apcprd04.prod.outlook.com (2603:1096:405:9a::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.17; Mon, 27 Jan 2025 10:43:41 +0000 Received: from TYZPR04MB5736.apcprd04.prod.outlook.com ([fe80::6d6:9923:c880:a521]) by TYZPR04MB5736.apcprd04.prod.outlook.com ([fe80::6d6:9923:c880:a521%6]) with mapi id 15.20.8377.009; Mon, 27 Jan 2025 10:43:41 +0000 From: Alexey Lapshin To: "newlib@sourceware.org" CC: Alexey Gerenkov , Ivan Grokhotkov Subject: [PATCH 1/6] newlib: string: refactor str/mem-family functions Thread-Topic: [PATCH 1/6] newlib: string: refactor str/mem-family functions Thread-Index: AQHbcKhUf5UnTFjOtku+t8q7qXRPtg== Date: Mon, 27 Jan 2025 10:43:41 +0000 Message-ID: <3668279f9eb28a9b644b90aab0b32152bc04a484.camel@espressif.com> References: <4ca70bc28f5edbc5a23c747313151ac5d290f54b.camel@espressif.com> In-Reply-To: <4ca70bc28f5edbc5a23c747313151ac5d290f54b.camel@espressif.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=espressif.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: TYZPR04MB5736:EE_|TYSPR04MB8166:EE_ x-ms-office365-filtering-correlation-id: 2e1fa108-6ed7-4dd7-7c1e-08dd3ebf774d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; ARA:13230040|376014|1800799024|366016|38070700018; x-microsoft-antispam-message-info: =?utf-8?q?2xkN9LWdMDdgH3AxOVWtpy3yfaeoJA8?= =?utf-8?q?MfG2VUO/qVUdfNHm3XVwgp9o8NM7pq5SqbzK2VxEN/1GVk2G01uvzZ6WaEuNM0sXv?= =?utf-8?q?loLWtWAw+520Nu8gZSc9IRz+yVp0ygnguhYQYHpd/hcG2Ul6Knx7HV5ZeSEVe7BYr?= =?utf-8?q?rYCZM2kBJkRjzVZNl/W0J3uRB3kYuTTkr3FhCgPNU3c6zuYNuM9phr72+KmsbJ3/D?= =?utf-8?q?B8s2g7iSO7G0B3Q4FaZUyD++dOUj2WWVaYmeiJukXCt9/c+kABmBI3CQvyUDr+Exi?= =?utf-8?q?peVKkZD9ROBgIG4/y8ZVzkuMPVAS7dfjcnllCTlxySYXCvpqdA0vn4PFv9dsp5r+3?= =?utf-8?q?4eEXQ3zTuS2x61gbTnza+irEe3NEwQ8tfGbER3CacV3+Y+7zB/yf2dRerkRxcuQce?= =?utf-8?q?L8akw9rQES+3lSBI7SCUvG08ff3R8rWcfBEvGKT/TjP7tO3UmNiOm6faj/eDXjR1S?= =?utf-8?q?0np9tEExCBb8sXIUenVxX09Pl01LAsZc0GA/15R6r8syyzjqdOSneayMiORrpJ1p0?= =?utf-8?q?SwbinJMKhrHd26EgFMH1pBT+J7GVzkIWcf41R2bMxO6kygdxPAoq1xxShiYQ2VDnT?= =?utf-8?q?YfxAi8jfqMQvCc2lb8IXitOZCy6nn6NOayZDhr66t1Vu1VJef6CdJT8ZSXdKo8NfG?= =?utf-8?q?WZCT80aP1BZDL9kV/rOcdcjW+Msm5WjsoBY19lqbYxJOsU6pJAwRaLZoPHXoHFrkw?= =?utf-8?q?sksGDkmb+y8y9DxCWnIq5a0GFM+uWbXb5qcoum5VbBrxfX3vYTjc7mjN9FgrXsIfD?= =?utf-8?q?kPTo0cufu7eQPi7Bc4KcslOsxRhll8/kjoOc36HhJj5LOzE0N13h/23LvskhLM0gP?= =?utf-8?q?BNI6/OIoioYpOpJbggbJEAvSvzhxIWDcm8bL7LxV8yTDIpqoxSUWg81UIfgoknXLE?= =?utf-8?q?3U8oQoeObBqWSzfSiEqOPDnmAUYp3/imadtF8WG/f7vqzbbkh7IL+4WFr9vHveFMJ?= =?utf-8?q?gnRS9kCkMLla/flob/s3EJr6GNoE1v6VqBcEPLqk1OGalqOfBr27/+okxpWQUZx0E?= =?utf-8?q?C5hpdF7iayTVtv9paszpV97vPu+bFSOmZBFYSMpWbvs3FVIkkOJ/mgfszUz93egN7?= =?utf-8?q?CfIqJVUH9BGyrRKhF7pBsalPies6eCYcgGrObtK68+hOfoKXQW2V03krWZUHPbmuh?= =?utf-8?q?rvKsURWAoY5fUFdCNCl0V1q9O1LlXQrNkwE2arOes50odtiXONckdCK6InNFsQAtL?= =?utf-8?q?HXluUQmj+CleOJtmfqLc7soX2HqA+I9VhdVPSPhjHsyBN6FMI8ViS/uoNlT2SAge9?= =?utf-8?q?4wBb8RCvquF33/upyfgRL0t2KNFgWfG/OeSahC1cdTPXI0GAPgsfzqctNi7lNRNGv?= =?utf-8?q?nfajqN57MLqq3eIyPyPNspijfK+wK2jZI7T5F8Pmb4qEgaK3yo/Ru9jMBghfjtRPd?= =?utf-8?q?U0Q8AnjMMs5?= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:TYZPR04MB5736.apcprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016)(38070700018); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?i/CTtmweh2774hsGa5tX1AghFDB1?= =?utf-8?q?4CI1HuEPVzUCoiMUvLPizcK+KyljTV62zbtj+bCIf01r99iwOFBRv90XzvWW+MB9e?= =?utf-8?q?FHGsTgqd4/vWwDJiChzC9XAqw8nA5I2+RIsSUX/LImrr6OhrAbQoBRsDMCCx7jDOE?= =?utf-8?q?DJFw4yVnGz/irXN8R3K7SaJ0TNE5xgp/LZDotnyoG7AFdi6qUbIeQ8uzryy1mr3jq?= =?utf-8?q?n016JtiSnFrJSMxyg9mVDgkrfTXSyrZzZLtM07UP8bs8QtC+sg+pqyvqcrJu9/FWj?= =?utf-8?q?0Z4ws8frvEsY0dlvxXGWltE6Ah6yTeibk+NFj1I6/ZztFTACOLV2fmvWh7xCDUyci?= =?utf-8?q?nDA6gKILlrWhEjXHEHI68lNBn6aprQxdxtLAIIv2Q9tDa6tONLX6LnIrGQN+8FCqK?= =?utf-8?q?X4F0t+yWB5/FfWMsGG7ddG8z2NivM0DddZJ3QfTzBlkEJg/Xbvw4RIvd4eqkDiGJG?= =?utf-8?q?ZzzV16Tq47Mk0lUBtg3bPTFh4Bw7Ub70xqnQ6XIt9CW5kZ8ZwLnhH+xigAIS15WR0?= =?utf-8?q?qDAOGEkcglox/i2aPhp4ki9GkuPuUqYONlspktJTiUaXdA/+buPW1m+JDXIzYVoWH?= =?utf-8?q?9CrBhNM0weTp5FGabW/8wyMMf5UuH7bbMsEIgqcdaZR+/mVa4mio1WRfENpKPereJ?= =?utf-8?q?fTH8Fof2uG1lWFmOvHPYs5FDMHQD6J28sZEVDPVhGRfLFMl/rgDy2z7g+P5mWYn6n?= =?utf-8?q?DI5ycDytE/ukiUXgpHCbeLXN/gz7HKhX3yEK8RXbGo02cxyyBQP+WYcX8adN+L/Sw?= =?utf-8?q?Oddo+sskaXli/VQLmWYdTXMnqHFipTfyXASEkQTb7LZg76qNhwNQCqwtpmB4VHpV7?= =?utf-8?q?8n8IK+YjyRnO2sXDlfchjWe6k+XjB1Sb5aRzUFqTl+im1Haaca7gakWjm3UUcmmJs?= =?utf-8?q?2XZseC6yFnPKpwVRTyEnlxNVDuoGqB7+rO1zVX2FRaw/Uab2wyxLtB3287tR7KfRO?= =?utf-8?q?SKpoWzLBSqd02Ovajf5WmoVLc/bJ2mwf933wGJcMwwpI/kckWQLgPkNVZHSPP0k0B?= =?utf-8?q?7kh5hxQ/hF+o9kUZOkrWgdYSq57X2NH4KNJEGDhwIZVjjK/M1ncVpHn/h7rNZbfgi?= =?utf-8?q?kGZnxz8+1eBt0ezt63dIK52WhcMBST+DNdW48DIIDLo/2EtJAWlCCEP8ew18G9iER?= =?utf-8?q?Lyy10NZXvFOA3IPb4rVI4Yc2RBcERJ1mUpm+pS/OYgukeCqorLanJTLZiZ1Q556PS?= =?utf-8?q?R+fD2kk0Psp7OwSQriA5Uu0517gO4jAtBik4LeErurSeyvhreXTqtOv25t/iLGZH9?= =?utf-8?q?la50ZyjfwZBtVvPqzZpStBdO/AVGfRawzkTjhIn678QGs6H19JOSyd+eAbFfy1+dx?= =?utf-8?q?+tC4Rw0XqGhJ945M5cj1n8nnd1c64JSaDNw8A24WTTXIVnHLj0c4U628xxH7unxa2?= =?utf-8?q?o8GCaIy/MvNb/0Huxl9PzlCM7BA76+7LdzhOArQsq5jrrpAoebFWtCiQ/TQKk8IoB?= =?utf-8?q?4aY04tf2oRIo5j/9PTm8Ct6SSh2kpwqxohLNDpgX4DvAsPHvKGkfn56DVE2RHSB/B?= =?utf-8?q?8ijb5XhBQEttTUQZKH6+deODt2LRnHcGMs1mpnT+iq3Xeyku8RN+RfY=3D?= Content-ID: MIME-Version: 1.0 X-OriginatorOrg: espressif.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: TYZPR04MB5736.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e1fa108-6ed7-4dd7-7c1e-08dd3ebf774d X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jan 2025 10:43:41.7213 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 5faf27fd-3557-4294-9545-8ea74a409f39 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 0MGmcTBf6OtNVOGi/ptriKO+ldtzd2/6PJWhhynALIeW3sLaI5/J5qHVteI6g3hTlvXnWKM2YEa5tLIzwZ7yYRH6ghrEXgqphUDhVnraxik= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYSPR04MB8166 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org Move common macros to local.h header --- newlib/libc/string/local.h | 32 +++++++++++++++++++++++ newlib/libc/string/memccpy.c | 34 +++++------------------- newlib/libc/string/memchr.c | 43 ++++++------------------------- newlib/libc/string/memcmp.c | 20 ++++----------- newlib/libc/string/memcpy.c | 23 ++++------------- newlib/libc/string/memmove.c | 23 ++++------------- newlib/libc/string/mempcpy.c | 24 +++++------------ newlib/libc/string/memrchr.c | 47 ++++++++-------------------------- newlib/libc/string/memset.c | 18 +++++-------- newlib/libc/string/rawmemchr.c | 35 +++---------------------- newlib/libc/string/stpcpy.c | 23 ++--------------- newlib/libc/string/stpncpy.c | 32 +++++------------------ newlib/libc/string/strcat.c | 25 +++--------------- newlib/libc/string/strchr.c | 30 ++++------------------ newlib/libc/string/strcmp.c | 23 ++--------------- newlib/libc/string/strcpy.c | 23 ++--------------- newlib/libc/string/strlen.c | 23 +++-------------- newlib/libc/string/strncat.c | 24 +++-------------- newlib/libc/string/strncmp.c | 24 +++-------------- newlib/libc/string/strncpy.c | 26 +++---------------- 20 files changed, 120 insertions(+), 432 deletions(-) -- 2.43.0 diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h index 8d364fdaa..fb8e6c65c 100644 --- a/newlib/libc/string/local.h +++ b/newlib/libc/string/local.h @@ -17,4 +17,36 @@ int __wcwidth (wint_t); # define __inhibit_loop_to_libcall #endif +/* Nonzero if X is not aligned on a "long" boundary. */ +#define UNALIGNED_X(X) ((long)X & (sizeof (long) - 1)) +/* Nonzero if either X or Y is not aligned on a "long" boundary. */ +#define UNALIGNED_X_Y(X, Y) \ + (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) + +/* How many bytes are copied each iteration of the word copy loop. */ +#define LITTLE_BLOCK_SIZE (sizeof (long)) + +/* How many bytes are copied each iteration of the 4X unrolled loop. */ +#define BIG_BLOCK_SIZE (sizeof (long) << 2) + +/* Threshhold for punting to the little block byte copier. */ +#define TOO_SMALL_LITTLE_BLOCK(LEN) ((LEN) < LITTLE_BLOCK_SIZE) + +/* Threshhold for punting to the big block byte copier. */ +#define TOO_SMALL_BIG_BLOCK(LEN) ((LEN) < BIG_BLOCK_SIZE) + +/* Macros for detecting endchar. */ +#if LONG_MAX == 2147483647L +#define DETECT_NULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) +#else +#if LONG_MAX == 9223372036854775807L +/* Nonzero if X (a long int) contains a NULL byte. */ +#define DETECT_NULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) +#else +#error long int is not a 32bit or 64bit type. +#endif +#endif + +/* Returns nonzero if (long)X contains the byte used to fill (long)MASK. */ +#define DETECT_CHAR(X, MASK) (DETECT_NULL(X ^ MASK)) diff --git a/newlib/libc/string/memccpy.c b/newlib/libc/string/memccpy.c index d6b2f8bea..332332489 100644 --- a/newlib/libc/string/memccpy.c +++ b/newlib/libc/string/memccpy.c @@ -31,29 +31,7 @@ PORTABILITY #include #include #include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < LITTLEBLOCKSIZE) - -/* Macros for detecting endchar */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - +#include "local.h" void * memccpy (void *__restrict dst0, @@ -88,7 +66,7 @@ memccpy (void *__restrict dst0, /* If the size is small, or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) + if (!TOO_SMALL_LITTLE_BLOCK(len0) && !UNALIGNED_X_Y(src, dst)) { unsigned int i; unsigned long mask = 0; @@ -102,19 +80,19 @@ memccpy (void *__restrict dst0, the word-sized segment with a word-sized block of the search character and then detecting for the presence of NULL in the result. */ - for (i = 0; i < LITTLEBLOCKSIZE; i++) + for (i = 0; i < sizeof(mask); i++) mask = (mask << 8) + endchar; /* Copy one long word at a time if possible. */ - while (len0 >= LITTLEBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(len0)) { unsigned long buffer = (unsigned long)(*aligned_src); buffer ^= mask; - if (DETECTNULL (buffer)) + if (DETECT_NULL(buffer)) break; /* endchar is found, go byte by byte from here */ *aligned_dst++ = *aligned_src++; - len0 -= LITTLEBLOCKSIZE; + len0 -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ diff --git a/newlib/libc/string/memchr.c b/newlib/libc/string/memchr.c index 21bc4d879..a702a9142 100644 --- a/newlib/libc/string/memchr.c +++ b/newlib/libc/string/memchr.c @@ -32,34 +32,7 @@ QUICKREF #include <_ansi.h> #include #include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the bytewise iterator. */ -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) +#include "local.h" void * memchr (const void *src_void, @@ -74,7 +47,7 @@ memchr (const void *src_void, unsigned long mask; unsigned int i; - while (UNALIGNED (src)) + while (UNALIGNED_X(src)) { if (!length--) return NULL; @@ -83,7 +56,7 @@ memchr (const void *src_void, src++; } - if (!TOO_SMALL (length)) + if (!TOO_SMALL_LITTLE_BLOCK(length)) { /* If we get this far, we know that length is large and src is word-aligned. */ @@ -96,18 +69,18 @@ memchr (const void *src_void, asrc = (unsigned long *) src; mask = d << 8 | d; mask = mask << 16 | mask; - for (i = 32; i < LBLOCKSIZE * 8; i <<= 1) + for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; - while (length >= LBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(length)) { - if (DETECTCHAR (*asrc, mask)) + if (DETECT_CHAR(*asrc, mask)) break; - length -= LBLOCKSIZE; + length -= LITTLE_BLOCK_SIZE; asrc++; } - /* If there are fewer than LBLOCKSIZE characters left, + /* If there are fewer than LITTLE_BLOCK_SIZE characters left, then we resort to the bytewise loop. */ src = (unsigned char *) asrc; diff --git a/newlib/libc/string/memcmp.c b/newlib/libc/string/memcmp.c index 342fb9fbc..c996f3349 100644 --- a/newlib/libc/string/memcmp.c +++ b/newlib/libc/string/memcmp.c @@ -30,17 +30,7 @@ QUICKREF */ #include - - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) +#include "local.h" int memcmp (const void *m1, @@ -70,22 +60,22 @@ memcmp (const void *m1, /* If the size is too small, or either pointer is unaligned, then we punt to the byte compare loop. Hopefully this will not turn up in inner loops. */ - if (!TOO_SMALL(n) && !UNALIGNED(s1,s2)) + if (!TOO_SMALL_LITTLE_BLOCK(n) && !UNALIGNED_X_Y(s1,s2)) { /* Otherwise, load and compare the blocks of memory one word at a time. */ a1 = (unsigned long*) s1; a2 = (unsigned long*) s2; - while (n >= LBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(n)) { if (*a1 != *a2) break; a1++; a2++; - n -= LBLOCKSIZE; + n -= LITTLE_BLOCK_SIZE; } - /* check m mod LBLOCKSIZE remaining characters */ + /* check m mod LITTLE_BLOCK_SIZE remaining characters */ s1 = (unsigned char*)a1; s2 = (unsigned char*)a2; diff --git a/newlib/libc/string/memcpy.c b/newlib/libc/string/memcpy.c index 52f716b92..1bbd4e0bf 100644 --- a/newlib/libc/string/memcpy.c +++ b/newlib/libc/string/memcpy.c @@ -31,19 +31,6 @@ QUICKREF #include #include "local.h" -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - void * __inhibit_loop_to_libcall memcpy (void *__restrict dst0, @@ -70,26 +57,26 @@ memcpy (void *__restrict dst0, /* If the size is small, or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) + if (!TOO_SMALL_BIG_BLOCK(len0) && !UNALIGNED_X_Y(src, dst)) { aligned_dst = (long*)dst; aligned_src = (long*)src; /* Copy 4X long words at a time if possible. */ - while (len0 >= BIGBLOCKSIZE) + while (!TOO_SMALL_BIG_BLOCK(len0)) { *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; - len0 -= BIGBLOCKSIZE; + len0 -= BIG_BLOCK_SIZE; } /* Copy one long word at a time if possible. */ - while (len0 >= LITTLEBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(len0)) { *aligned_dst++ = *aligned_src++; - len0 -= LITTLEBLOCKSIZE; + len0 -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ diff --git a/newlib/libc/string/memmove.c b/newlib/libc/string/memmove.c index da5dfdbdd..a82744c7d 100644 --- a/newlib/libc/string/memmove.c +++ b/newlib/libc/string/memmove.c @@ -34,19 +34,6 @@ QUICKREF #include #include "local.h" -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) - /*SUPPRESS 20*/ void * __inhibit_loop_to_libcall @@ -98,26 +85,26 @@ memmove (void *dst_void, /* Use optimizing algorithm for a non-destructive copy to closely match memcpy. If the size is small or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(length) && !UNALIGNED (src, dst)) + if (!TOO_SMALL_BIG_BLOCK(length) && !UNALIGNED_X_Y(src, dst)) { aligned_dst = (long*)dst; aligned_src = (long*)src; /* Copy 4X long words at a time if possible. */ - while (length >= BIGBLOCKSIZE) + while (!TOO_SMALL_BIG_BLOCK(length)) { *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; - length -= BIGBLOCKSIZE; + length -= BIG_BLOCK_SIZE; } /* Copy one long word at a time if possible. */ - while (length >= LITTLEBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(length)) { *aligned_dst++ = *aligned_src++; - length -= LITTLEBLOCKSIZE; + length -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ diff --git a/newlib/libc/string/mempcpy.c b/newlib/libc/string/mempcpy.c index 129165603..06e97de85 100644 --- a/newlib/libc/string/mempcpy.c +++ b/newlib/libc/string/mempcpy.c @@ -28,19 +28,7 @@ PORTABILITY #include #include #include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* How many bytes are copied each iteration of the 4X unrolled loop. */ -#define BIGBLOCKSIZE (sizeof (long) << 2) - -/* How many bytes are copied each iteration of the word copy loop. */ -#define LITTLEBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the byte copier. */ -#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) +#include "local.h" void * mempcpy (void *dst0, @@ -65,26 +53,26 @@ mempcpy (void *dst0, /* If the size is small, or either SRC or DST is unaligned, then punt into the byte copy loop. This should be rare. */ - if (!TOO_SMALL(len0) && !UNALIGNED (src, dst)) + if (!TOO_SMALL_BIG_BLOCK(len0) && !UNALIGNED_X_Y(src, dst)) { aligned_dst = (long*)dst; aligned_src = (long*)src; /* Copy 4X long words at a time if possible. */ - while (len0 >= BIGBLOCKSIZE) + while (!TOO_SMALL_BIG_BLOCK(len0)) { *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; *aligned_dst++ = *aligned_src++; - len0 -= BIGBLOCKSIZE; + len0 -= BIG_BLOCK_SIZE; } /* Copy one long word at a time if possible. */ - while (len0 >= LITTLEBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(len0)) { *aligned_dst++ = *aligned_src++; - len0 -= LITTLEBLOCKSIZE; + len0 -= LITTLE_BLOCK_SIZE; } /* Pick up any residual with a byte copier. */ diff --git a/newlib/libc/string/memrchr.c b/newlib/libc/string/memrchr.c index 652efb359..0a0c80fd9 100644 --- a/newlib/libc/string/memrchr.c +++ b/newlib/libc/string/memrchr.c @@ -32,34 +32,7 @@ QUICKREF #include <_ansi.h> #include #include - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)(X + 1) & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the bytewise iterator. */ -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) +#include "local.h" void * memrchr (const void *src_void, @@ -74,7 +47,7 @@ memrchr (const void *src_void, unsigned long mask; unsigned int i; - while (UNALIGNED (src)) + while (UNALIGNED_X(src)) { if (!length--) return NULL; @@ -83,7 +56,7 @@ memrchr (const void *src_void, src--; } - if (!TOO_SMALL (length)) + if (!TOO_SMALL_LITTLE_BLOCK(length)) { /* If we get this far, we know that length is large and src is word-aligned. */ @@ -93,24 +66,24 @@ memrchr (const void *src_void, the word-sized segment with a word-sized block of the search character and then detecting for the presence of NUL in the result. */ - asrc = (unsigned long *) (src - LBLOCKSIZE + 1); + asrc = (unsigned long *) (src - LITTLE_BLOCK_SIZE + 1); mask = d << 8 | d; mask = mask << 16 | mask; - for (i = 32; i < LBLOCKSIZE * 8; i <<= 1) + for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; - while (length >= LBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(length)) { - if (DETECTCHAR (*asrc, mask)) + if (DETECT_CHAR(*asrc, mask)) break; - length -= LBLOCKSIZE; + length -= LITTLE_BLOCK_SIZE; asrc--; } - /* If there are fewer than LBLOCKSIZE characters left, + /* If there are fewer than LITTLE_BLOCK_SIZE characters left, then we resort to the bytewise loop. */ - src = (unsigned char *) asrc + LBLOCKSIZE - 1; + src = (unsigned char *) asrc + LITTLE_BLOCK_SIZE - 1; } #endif /* not PREFER_SIZE_OVER_SPEED */ diff --git a/newlib/libc/string/memset.c b/newlib/libc/string/memset.c index e8e667a24..99b5526c7 100644 --- a/newlib/libc/string/memset.c +++ b/newlib/libc/string/memset.c @@ -29,10 +29,6 @@ QUICKREF #include #include "local.h" -#define LBLOCKSIZE (sizeof(long)) -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - void * __inhibit_loop_to_libcall memset (void *m, @@ -48,7 +44,7 @@ memset (void *m, unsigned int d = c & 0xff; /* To avoid sign extension, copy C to an unsigned variable. */ - while (UNALIGNED (s)) + while (UNALIGNED_X(s)) { if (n--) *s++ = (char) c; @@ -56,7 +52,7 @@ memset (void *m, return m; } - if (!TOO_SMALL (n)) + if (!TOO_SMALL_LITTLE_BLOCK(n)) { /* If we get this far, we know that n is large and s is word-aligned. */ aligned_addr = (unsigned long *) s; @@ -65,23 +61,23 @@ memset (void *m, we can set large blocks quickly. */ buffer = (d << 8) | d; buffer |= (buffer << 16); - for (i = 32; i < LBLOCKSIZE * 8; i <<= 1) + for (i = 32; i < sizeof(buffer) * 8; i <<= 1) buffer = (buffer << i) | buffer; /* Unroll the loop. */ - while (n >= LBLOCKSIZE*4) + while (!TOO_SMALL_BIG_BLOCK(n)) { *aligned_addr++ = buffer; *aligned_addr++ = buffer; *aligned_addr++ = buffer; *aligned_addr++ = buffer; - n -= 4*LBLOCKSIZE; + n -= BIG_BLOCK_SIZE; } - while (n >= LBLOCKSIZE) + while (!TOO_SMALL_LITTLE_BLOCK(n)) { *aligned_addr++ = buffer; - n -= LBLOCKSIZE; + n -= LITTLE_BLOCK_SIZE; } /* Pick up the remainder with a bytewise loop. */ s = (char*)aligned_addr; diff --git a/newlib/libc/string/rawmemchr.c b/newlib/libc/string/rawmemchr.c index 56e2b5e2d..1458a9d8b 100644 --- a/newlib/libc/string/rawmemchr.c +++ b/newlib/libc/string/rawmemchr.c @@ -31,34 +31,7 @@ QUICKREF #include <_ansi.h> #include #include - -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -/* Threshhold for punting to the bytewise iterator. */ -#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) +#include "local.h" void * rawmemchr (const void *src_void, @@ -72,7 +45,7 @@ rawmemchr (const void *src_void, unsigned long mask; unsigned int i; - while (UNALIGNED (src)) + while (UNALIGNED_X (src)) { if (*src == d) return (void *) src; @@ -89,12 +62,12 @@ rawmemchr (const void *src_void, asrc = (unsigned long *) src; mask = d << 8 | d; mask = mask << 16 | mask; - for (i = 32; i < LBLOCKSIZE * 8; i <<= 1) + for (i = 32; i < sizeof(mask) * 8; i <<= 1) mask = (mask << i) | mask; while (1) { - if (DETECTCHAR (*asrc, mask)) + if (DETECT_CHAR (*asrc, mask)) break; asrc++; } diff --git a/newlib/libc/string/stpcpy.c b/newlib/libc/string/stpcpy.c index 4e2ae9fe0..884ac8f10 100644 --- a/newlib/libc/string/stpcpy.c +++ b/newlib/libc/string/stpcpy.c @@ -33,25 +33,6 @@ QUICKREF /*SUPPRESS 560*/ /*SUPPRESS 530*/ -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - char* stpcpy (char *__restrict dst, const char *__restrict src) @@ -61,14 +42,14 @@ stpcpy (char *__restrict dst, const long *aligned_src; /* If SRC or DEST is unaligned, then copy bytes. */ - if (!UNALIGNED (src, dst)) + if (!UNALIGNED_X_Y(src, dst)) { aligned_dst = (long*)dst; aligned_src = (long*)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ - while (!DETECTNULL(*aligned_src)) + while (!DETECT_NULL(*aligned_src)) { *aligned_dst++ = *aligned_src++; } diff --git a/newlib/libc/string/stpncpy.c b/newlib/libc/string/stpncpy.c index 87fe268cf..2e356c4b8 100644 --- a/newlib/libc/string/stpncpy.c +++ b/newlib/libc/string/stpncpy.c @@ -35,31 +35,11 @@ QUICKREF #include #include +#include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -#define TOO_SMALL(LEN) ((LEN) < sizeof (long)) - char * stpncpy (char *__restrict dst, const char *__restrict src, @@ -72,16 +52,16 @@ stpncpy (char *__restrict dst, const long *aligned_src; /* If SRC and DEST is aligned and count large enough, then copy words. */ - if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) + if (!UNALIGNED_X_Y (src, dst) && !TOO_SMALL_LITTLE_BLOCK (count)) { aligned_dst = (long*)dst; aligned_src = (long*)src; - /* SRC and DEST are both "long int" aligned, try to do "long int" - sized copies. */ - while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) + /* SRC and DEST are both LITTLE_BLOCK_SIZE aligned, + try to do LITTLE_BLOCK_SIZE sized copies. */ + while (!TOO_SMALL_LITTLE_BLOCK (count) && !DETECT_NULL(*aligned_src)) { - count -= sizeof (long int); + count -= LITTLE_BLOCK_SIZE; *aligned_dst++ = *aligned_src++; } diff --git a/newlib/libc/string/strcat.c b/newlib/libc/string/strcat.c index 92313c492..71dd1db75 100644 --- a/newlib/libc/string/strcat.c +++ b/newlib/libc/string/strcat.c @@ -29,26 +29,7 @@ QUICKREF #include #include - -/* Nonzero if X is aligned on a "long" boundary. */ -#define ALIGNED(X) \ - (((long)X & (sizeof (long) - 1)) == 0) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - +#include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ @@ -71,10 +52,10 @@ strcat (char *__restrict s1, /* Skip over the data in s1 as quickly as possible. */ - if (ALIGNED (s1)) + if (!UNALIGNED_X(s1)) { unsigned long *aligned_s1 = (unsigned long *)s1; - while (!DETECTNULL (*aligned_s1)) + while (!DETECT_NULL(*aligned_s1)) aligned_s1++; s1 = (char *)aligned_s1; diff --git a/newlib/libc/string/strchr.c b/newlib/libc/string/strchr.c index 96f30be04..66afefdb1 100644 --- a/newlib/libc/string/strchr.c +++ b/newlib/libc/string/strchr.c @@ -30,26 +30,6 @@ QUICKREF #include #include -/* Nonzero if X is not aligned on a "long" boundary. */ -#define UNALIGNED(X) ((long)X & (sizeof (long) - 1)) - -/* How many bytes are loaded each iteration of the word copy loop. */ -#define LBLOCKSIZE (sizeof (long)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -/* DETECTCHAR returns nonzero if (long)X contains the byte used - to fill (long)MASK. */ -#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK)) char * strchr (const char *s1, @@ -65,7 +45,7 @@ strchr (const char *s1, /* Special case for finding 0. */ if (!c) { - while (UNALIGNED (s)) + while (UNALIGNED_X(s)) { if (!*s) return (char *) s; @@ -73,7 +53,7 @@ strchr (const char *s1, } /* Operate a word at a time. */ aligned_addr = (unsigned long *) s; - while (!DETECTNULL (*aligned_addr)) + while (!DETECT_NULL(*aligned_addr)) aligned_addr++; /* Found the end of string. */ s = (const unsigned char *) aligned_addr; @@ -83,7 +63,7 @@ strchr (const char *s1, } /* All other bytes. Align the pointer, then search a long at a time. */ - while (UNALIGNED (s)) + while (UNALIGNED_X(s)) { if (!*s) return NULL; @@ -93,11 +73,11 @@ strchr (const char *s1, } mask = c; - for (j = 8; j < LBLOCKSIZE * 8; j <<= 1) + for (j = 8; j < sizeof(mask) * 8; j <<= 1) mask = (mask << j) | mask; aligned_addr = (unsigned long *) s; - while (!DETECTNULL (*aligned_addr) && !DETECTCHAR (*aligned_addr, mask)) + while (!DETECT_NULL(*aligned_addr) && !DETECT_CHAR(*aligned_addr, mask)) aligned_addr++; /* The block of bytes currently pointed to by aligned_addr diff --git a/newlib/libc/string/strcmp.c b/newlib/libc/string/strcmp.c index 894424a69..1cd2ec1c1 100644 --- a/newlib/libc/string/strcmp.c +++ b/newlib/libc/string/strcmp.c @@ -32,25 +32,6 @@ QUICKREF #include #include -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - int strcmp (const char *s1, const char *s2) @@ -68,7 +49,7 @@ strcmp (const char *s1, unsigned long *a2; /* If s1 or s2 are unaligned, then compare bytes. */ - if (!UNALIGNED (s1, s2)) + if (!UNALIGNED_X_Y(s1, s2)) { /* If s1 and s2 are word-aligned, compare them a word at a time. */ a1 = (unsigned long*)s1; @@ -77,7 +58,7 @@ strcmp (const char *s1, { /* To get here, *a1 == *a2, thus if we find a null in *a1, then the strings must be equal, so return zero. */ - if (DETECTNULL (*a1)) + if (DETECT_NULL(*a1)) return 0; a1++; diff --git a/newlib/libc/string/strcpy.c b/newlib/libc/string/strcpy.c index 94e16b512..f79651e75 100644 --- a/newlib/libc/string/strcpy.c +++ b/newlib/libc/string/strcpy.c @@ -32,25 +32,6 @@ QUICKREF /*SUPPRESS 560*/ /*SUPPRESS 530*/ -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - char* strcpy (char *dst0, const char *src0) @@ -69,14 +50,14 @@ strcpy (char *dst0, const long *aligned_src; /* If SRC or DEST is unaligned, then copy bytes. */ - if (!UNALIGNED (src, dst)) + if (!UNALIGNED_X_Y(src, dst)) { aligned_dst = (long*)dst; aligned_src = (long*)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ - while (!DETECTNULL(*aligned_src)) + while (!DETECT_NULL(*aligned_src)) { *aligned_dst++ = *aligned_src++; } diff --git a/newlib/libc/string/strlen.c b/newlib/libc/string/strlen.c index acffa49e1..f48d6d400 100644 --- a/newlib/libc/string/strlen.c +++ b/newlib/libc/string/strlen.c @@ -29,24 +29,7 @@ QUICKREF #include <_ansi.h> #include #include - -#define LBLOCKSIZE (sizeof (long)) -#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1)) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif +#include "local.h" size_t strlen (const char *str) @@ -57,7 +40,7 @@ strlen (const char *str) unsigned long *aligned_addr; /* Align the pointer, so we can search a word at a time. */ - while (UNALIGNED (str)) + while (UNALIGNED_X(str)) { if (!*str) return str - start; @@ -67,7 +50,7 @@ strlen (const char *str) /* If the string is word-aligned, we can check for the presence of a null in each word-sized block. */ aligned_addr = (unsigned long *)str; - while (!DETECTNULL (*aligned_addr)) + while (!DETECT_NULL(*aligned_addr)) aligned_addr++; /* Once a null is detected, we check each byte in that block for a diff --git a/newlib/libc/string/strncat.c b/newlib/libc/string/strncat.c index 7351913f9..01f20f681 100644 --- a/newlib/libc/string/strncat.c +++ b/newlib/libc/string/strncat.c @@ -37,25 +37,7 @@ QUICKREF #include #include - -/* Nonzero if X is aligned on a "long" boundary. */ -#define ALIGNED(X) \ - (((long)X & (sizeof (long) - 1)) == 0) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif +#include "local.h" char * strncat (char *__restrict s1, @@ -78,10 +60,10 @@ strncat (char *__restrict s1, char *s = s1; /* Skip over the data in s1 as quickly as possible. */ - if (ALIGNED (s1)) + if (!UNALIGNED_X(s1)) { unsigned long *aligned_s1 = (unsigned long *)s1; - while (!DETECTNULL (*aligned_s1)) + while (!DETECT_NULL(*aligned_s1)) aligned_s1++; s1 = (char *)aligned_s1; diff --git a/newlib/libc/string/strncmp.c b/newlib/libc/string/strncmp.c index 16f8a7729..d59a26364 100644 --- a/newlib/libc/string/strncmp.c +++ b/newlib/libc/string/strncmp.c @@ -31,25 +31,7 @@ QUICKREF #include #include - -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -/* DETECTNULL returns nonzero if (long)X contains a NULL byte. */ -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif +#include "local.h" int strncmp (const char *s1, @@ -77,7 +59,7 @@ strncmp (const char *s1, return 0; /* If s1 or s2 are unaligned, then compare bytes. */ - if (!UNALIGNED (s1, s2)) + if (!UNALIGNED_X_Y(s1, s2)) { /* If s1 and s2 are word-aligned, compare them a word at a time. */ a1 = (unsigned long*)s1; @@ -88,7 +70,7 @@ strncmp (const char *s1, /* If we've run out of bytes or hit a null, return zero since we already know *a1 == *a2. */ - if (n == 0 || DETECTNULL (*a1)) + if (n == 0 || DETECT_NULL (*a1)) return 0; a1++; diff --git a/newlib/libc/string/strncpy.c b/newlib/libc/string/strncpy.c index e7eb34d72..98748a17d 100644 --- a/newlib/libc/string/strncpy.c +++ b/newlib/libc/string/strncpy.c @@ -33,31 +33,11 @@ QUICKREF #include #include +#include "local.h" /*SUPPRESS 560*/ /*SUPPRESS 530*/ -/* Nonzero if either X or Y is not aligned on a "long" boundary. */ -#define UNALIGNED(X, Y) \ - (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1))) - -#if LONG_MAX == 2147483647L -#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080) -#else -#if LONG_MAX == 9223372036854775807L -/* Nonzero if X (a long int) contains a NULL byte. */ -#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080) -#else -#error long int is not a 32bit or 64bit type. -#endif -#endif - -#ifndef DETECTNULL -#error long int is not a 32bit or 64bit byte -#endif - -#define TOO_SMALL(LEN) ((LEN) < sizeof (long)) - char * strncpy (char *__restrict dst0, const char *__restrict src0, @@ -86,14 +66,14 @@ strncpy (char *__restrict dst0, const long *aligned_src; /* If SRC and DEST is aligned and count large enough, then copy words. */ - if (!UNALIGNED (src, dst) && !TOO_SMALL (count)) + if (!UNALIGNED_X_Y(src, dst) && !TOO_SMALL_LITTLE_BLOCK(count)) { aligned_dst = (long*)dst; aligned_src = (long*)src; /* SRC and DEST are both "long int" aligned, try to do "long int" sized copies. */ - while (count >= sizeof (long int) && !DETECTNULL(*aligned_src)) + while (!TOO_SMALL_LITTLE_BLOCK(count) && !DETECT_NULL(*aligned_src)) { count -= sizeof (long int); *aligned_dst++ = *aligned_src++;