Date: Mon, 27 May 2013 11:44:06 +0200 From: Florent Peterschmitt <florent@peterschmitt.fr> To: freebsd-hackers@freebsd.org Subject: Re: Performance improvement to strnlen(). Message-ID: <51A32AE6.9010205@peterschmitt.fr> In-Reply-To: <CAKw7uVi2oofoy=yJQiHR927oGfy74UuYFq68r=C=gUVXBXZuKw@mail.gmail.com> References: <2adc4d8e7c55e92d935f61efb4c9d723@lthomas.net> <CAKw7uVi2oofoy=yJQiHR927oGfy74UuYFq68r=C=gUVXBXZuKw@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?51A32AE6.9010205>