From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 58063 invoked by alias); 27 Jul 2017 11:13:27 -0000 Mailing-List: contact newlib-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-owner@sourceware.org Received: (qmail 57608 invoked by uid 89); 27 Jul 2017 11:13:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=painfully X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jul 2017 11:13:25 +0000 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CCD8C2E44CA; Thu, 27 Jul 2017 11:13:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CCD8C2E44CA Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com Received: from [10.10.121.48] (ovpn-121-48.rdu2.redhat.com [10.10.121.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 65BB418016; Thu, 27 Jul 2017 11:13:23 +0000 (UTC) Subject: Re: [PATCH] Workaround for ffs() on LP64 targets To: Sebastian Huber , newlib@sourceware.org References: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> From: Eric Blake Openpgp: url=http://people.redhat.com/eblake/eblake.gpg Message-ID: <26467603-cd3e-63af-04f3-d0c78e14e348@redhat.com> Date: Thu, 27 Jul 2017 11:13:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="x2FeKe81fG88d9igQqNlIxp9a0RwtHXc6" X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00673.txt.bz2 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --x2FeKe81fG88d9igQqNlIxp9a0RwtHXc6 Content-Type: multipart/mixed; boundary="LpxHEU3Qk8GA3F3l4Dn35x5VoOGVkxwL0"; protected-headers="v1" From: Eric Blake To: Sebastian Huber , newlib@sourceware.org Message-ID: <26467603-cd3e-63af-04f3-d0c78e14e348@redhat.com> Subject: Re: [PATCH] Workaround for ffs() on LP64 targets References: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> In-Reply-To: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> --LpxHEU3Qk8GA3F3l4Dn35x5VoOGVkxwL0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Content-length: 1121 On 07/27/2017 03:06 AM, Sebastian Huber wrote: > Signed-off-by: Sebastian Huber > --- > newlib/libc/misc/ffs.c | 11 +++++++++++ > 1 file changed, 11 insertions(+) >=20 > diff --git a/newlib/libc/misc/ffs.c b/newlib/libc/misc/ffs.c > index ba5700920..a09cbd3bb 100644 > --- a/newlib/libc/misc/ffs.c > +++ b/newlib/libc/misc/ffs.c > @@ -31,6 +31,17 @@ No supporting OS subroutines are required. */ > int > ffs(int i) > { > +#ifdef __LP64__ > + /* GCC would expand the __builtin_ffs() to ffs() in this case */ > + int bit; > + > + if (i =3D=3D 0) > + return (0); > + for (bit =3D 1; !(i & 1); bit++) > + i =3D (unsigned int)i >> 1; > + return (bit); If we're going to open-code it to work around the compiler creating an infloop recursion to ffs(), at least code a straight-line version without branches, rather than the painfully slow bit-by-bit loop. There's plenty of examples on the web of writing ffs() by using bit-twiddling without branching. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org --LpxHEU3Qk8GA3F3l4Dn35x5VoOGVkxwL0-- --x2FeKe81fG88d9igQqNlIxp9a0RwtHXc6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 619 -----BEGIN PGP SIGNATURE----- Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAll5ytIACgkQp6FrSiUn Q2pzowf9HoHuwNxFhGJFODkdxIIeI9iP0UVm4WVr1c/dtyVEb5qykuZ7+p6vvCai jcneciXyD2KRJ0w9E2srE4TEGRBG0nr3bjewAyqLTcPvgb97mwE5TQLmdKHo9Nuv AzK/8bxkNCLcLresHIg1NrOCBHAhfAocBIDXFMtnN94Bhv5XC0TelfjSBFrbI9LF 6E4UMOCLUqjaER3HXfS2T5tzGVZoCsTLtmSkSpYjAz7LHSCC9rcHyzBmY0VuBhI/ 3eJCxkbqBeXtTP5kMNIkf5xQRtzRT35TstX6kofU5j4m/oNhGRhwT8rmjLrD9K5s F80IPYhIwmmBWltROrgjijKvK9puUQ== =zkkH -----END PGP SIGNATURE----- --x2FeKe81fG88d9igQqNlIxp9a0RwtHXc6--