From owner-freebsd-hackers@FreeBSD.ORG Mon May 27 09:43:01 2013 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id DFCFC9C5 for ; Mon, 27 May 2013 09:43:01 +0000 (UTC) (envelope-from florent@peterschmitt.fr) Received: from peterschmitt.fr (peterschmitt.fr [5.135.177.31]) by mx1.freebsd.org (Postfix) with ESMTP id A8C1CC1 for ; Mon, 27 May 2013 09:43:01 +0000 (UTC) Received: from [172.29.180.39] (unknown [194.214.114.46]) by peterschmitt.fr (Postfix) with ESMTPSA id 32A4595D3 for ; Mon, 27 May 2013 11:43:01 +0200 (CEST) Message-ID: <51A32AE6.9010205@peterschmitt.fr> Date: Mon, 27 May 2013 11:44:06 +0200 From: Florent Peterschmitt User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130518 Icedove/17.0.5 MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Subject: Re: Performance improvement to strnlen(). References: <2adc4d8e7c55e92d935f61efb4c9d723@lthomas.net> In-Reply-To: X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2IFLGDRTAWGBPDRXLKSGF" X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: florent+FreeBSD-hackers@peterschmitt.fr List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 May 2013 09:43:01 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2IFLGDRTAWGBPDRXLKSGF Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Le 27/05/2013 10:37, V=C3=A1clav Zeman a =C3=A9crit : > On 26 May 2013 21:01, Lee Thomas wrote: >> On 2013-05-26 08:00, V=C3=A1clav Zeman wrote: >>> >>> On 05/25/2013 10:27 PM, Lee Thomas wrote: >>>> >>>> + lp =3D (const unsigned long *)((uintptr_t)str & ~LONGPTR_MAS= K); >>>> + va =3D (*lp - mask01); >>>> + vb =3D ((~*lp) & mask80); >>> >>> I do not think that this correct C. This is type punning violating th= e >>> rules of the language. >> >> >> Hello V=C3=A1clav, >> >> The aliasing here is safe, because there are no writes through either = of the >> pointers, and the reads are correctly aligned. > I disagree. IANALL but AFAIK, this is simply not allowed by the > language =3D> UB =3D> even though it seems to work in this instance, yo= u > are just lucky the UB is actually doing what you expect. In that case we should rewrite strlen, it's the same code. That doesn't mean it's a good code but I really don't think it's bad. Using signedness is totally valid and what is done here appears valid too. > -- > VZ --=20 Florent Peterschmitt | /"\ ASCII Ribbon Campaign florent@peterschmitt.fr | \ / - No HTML/RTF in E-mail +33 (0)6 64 33 97 92 | X - No proprietary attachments http://florent.peterschmitt.fr | / \ - Respect for open standards ------enig2IFLGDRTAWGBPDRXLKSGF Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iQEcBAEBAgAGBQJRoyrmAAoJEMtO2Sol0IImqq8H/j1LDig+rnjwM870atgOonEA KWGPYQSgoi1yyYCcHR/74hX6F1nkSK+2xCDI+ZLPge5BUFwKlxw6qNHzG+smOWlB iS2omHNgApV9XsNgVxWf8iGO9s74VkmVBuaY1TFIZEk2Qd6J29dLF70dhQN83+24 H4AByalis6L/3Pxe1/wN3R0x26Dcjw7R6tiw4G6IrNzqlsmKdREIzQPL9q3vFti2 t0T/ZsYkYzyA7A2CJt4Mpq+KBLEDJ9U8BZ2FwssfiwQi9QSSsfBc03ZSvFBUN0xs mT3oSEzha0Vm1qPg3Y7T5EQi6KkyeI7rol69doqRQZn29Or/xsweHgjRcSzrH6E= =j9T0 -----END PGP SIGNATURE----- ------enig2IFLGDRTAWGBPDRXLKSGF--