From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2815 Path: news.gmane.org!not-for-mail From: Jonas Wagner Newsgroups: gmane.linux.lib.musl.general Subject: Fwd: Alignment check in strlen Date: Wed, 20 Feb 2013 19:05:28 +0100 Message-ID: References: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=047d7b86de88058dcf04d62bd003 X-Trace: ger.gmane.org 1361383588 24473 80.91.229.3 (20 Feb 2013 18:06:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 20 Feb 2013 18:06:28 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2816-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 20 19:06:49 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1U8E44-0002Sj-9B for gllmg-musl@plane.gmane.org; Wed, 20 Feb 2013 19:06:44 +0100 Original-Received: (qmail 11712 invoked by uid 550); 20 Feb 2013 18:06:23 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 11704 invoked from network); 20 Feb 2013 18:06:22 -0000 X-Virus-Scanned: ClamAV X-Received: by 10.194.58.202 with SMTP id t10mr27395796wjq.4.1361383568805; Wed, 20 Feb 2013 10:06:08 -0800 (PST) In-Reply-To: Xref: news.gmane.org gmane.linux.lib.musl.general:2815 Archived-At: --047d7b86de88058dcf04d62bd003 Content-Type: multipart/alternative; boundary=047d7b86de88058dcb04d62bd001 --047d7b86de88058dcb04d62bd001 Content-Type: text/plain; charset=ISO-8859-1 Dear all, attached is a patch that makes the alignment check in strlen more consistent with the one in memcpy, and hopefully faster. In src/string/memcpy.c, I find the following: #define ALIGN (sizeof(size_t)-1) if (((uintptr_t)d & ALIGN) != ((uintptr_t)s & ALIGN)) goto misaligned; In src/string/strlen.c, a different check was used instead: #define ALIGN (sizeof(size_t)) for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a; I do not think there is any particular reason for this difference. Best, Jonas --047d7b86de88058dcb04d62bd001 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Dear all,
<= div>
attached is a patch that makes the alignment check in st= rlen more consistent with the one in memcpy, and hopefully faster.

In src/string/memcpy.c, I find the following:

#define ALIG= N (sizeof(size_t)-1)
if (((uintptr_t)d & ALIGN) !=3D ((uintptr_t)s & ALIGN))
=A0 goto misaligned;

In= src/string/strlen.c, a different check was used instead:

#define ALIGN (si= zeof(size_t))
for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a;

I do not think there is any particular reason for this = difference.

Best,
Jonas


--047d7b86de88058dcb04d62bd001-- --047d7b86de88058dcf04d62bd003 Content-Type: application/octet-stream; name="0001-strlen-use-bitwise-AND-for-alignment-test-instead-of.patch" Content-Disposition: attachment; filename="0001-strlen-use-bitwise-AND-for-alignment-test-instead-of.patch" Content-Transfer-Encoding: base64 X-Attachment-Id: f_hdeshalj0 RnJvbSBkMmI4YWZmOWI3OTlhMjQwMmU3Zjc3NjliZGZhNTExY2MyNDY3NjhiIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBKb25hcyBXYWduZXIgPGpvbmFzLndhZ25lckBlcGZsLmNoPgpE YXRlOiBXZWQsIDIwIEZlYiAyMDEzIDE4OjUwOjAxICswMTAwClN1YmplY3Q6IFtQQVRDSF0gc3Ry bGVuOiB1c2UgYml0d2lzZSBBTkQgZm9yIGFsaWdubWVudCB0ZXN0LCBpbnN0ZWFkIG9mICUuCgot LS0KIHNyYy9zdHJpbmcvc3RybGVuLmMgfCAgICA0ICsrLS0KIDEgZmlsZSBjaGFuZ2VkLCAyIGlu c2VydGlvbnMoKyksIDIgZGVsZXRpb25zKC0pCg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