From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9256 invoked by alias); 27 Jul 2017 12:49:15 -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 8989 invoked by uid 89); 27 Jul 2017 12:48:47 -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=H*f:sk:fe8c56d, H*i:sk:fe8c56d 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 12:48:46 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 50A135FB40 for ; Thu, 27 Jul 2017 12:48:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 50A135FB40 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=vinschen@redhat.com Received: from calimero.vinschen.de (ovpn-116-16.ams2.redhat.com [10.36.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED52E7DE2C for ; Thu, 27 Jul 2017 12:48:44 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id 3D941A805A0; Thu, 27 Jul 2017 14:48:44 +0200 (CEST) Date: Thu, 27 Jul 2017 12:49:00 -0000 From: Corinna Vinschen To: newlib@sourceware.org Subject: Re: [PATCH] Workaround for ffs() on LP64 targets Message-ID: <20170727124844.GC27695@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: newlib@sourceware.org References: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> <26467603-cd3e-63af-04f3-d0c78e14e348@redhat.com> <42255ff2-66cf-e021-788b-250d45693374@embedded-brains.de> <20170727122734.GA27695@calimero.vinschen.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kfjH4zxOES6UT95V" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.8.3 (2017-05-23) X-SW-Source: 2017/txt/msg00678.txt.bz2 --kfjH4zxOES6UT95V Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2100 On Jul 27 14:33, Sebastian Huber wrote: > On 27/07/17 14:27, Corinna Vinschen wrote: >=20 > > On Jul 27 13:24, Sebastian Huber wrote: > > > On 27/07/17 13:13, Eric Blake wrote: > > >=20 > > > > 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. > > > This is roughly the same implementation we had before. I do not inten= d to > > > optimize this. > > Still, __LP64__ is unacceptable. Cygwin would be affected by this as > > well and would have to revert to its former own ffs implementation. > >=20 > > Reverting to a C-based implementation should only be performed on a > > case-by-case basis. >=20 > Yes, so maybe something like this >=20 > #if defined(__LP64__) && defined(__riscv) >=20 > or a target-specific ffs.c file similar to memcpy.c, etc. I'm inclined to favor a target-specific file. This would also allow to implement the replacement in assembler easily. Corinna --=20 Corinna Vinschen Cygwin Maintainer Red Hat --kfjH4zxOES6UT95V Content-Type: application/pgp-signature; name="signature.asc" Content-length: 819 -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJZeeEsAAoJEPU2Bp2uRE+gjWQP/imL/BQJrIvIKkXqEENoJys1 n1PkkxMxVuq+DF+7ArBG3e+IfE2cdifJoomTgv0/LvFy5DrfrnLmv4PCNo4Xc/Q0 7D+B6pK8AYUQdBhekpd5Q05NF6fA8xEy54L2iknbWdeAVfLuEMap6Xj8wnZxSPv8 E5NwLSA7BImjzQwYeWkJz252+PzOkAq3sBgyVYnjnb52AzvMp4suEGzoT0iZ6PWy EPOzsylgwiIW6v56a7X/HU/VhkBjRG5jaRsfG5qZV6PQNE1Xa9ykgR/TksVf65Lm 7b1JSR5B5ZvOP3uJV/YdU+96+ExLYoC89cq1HF7nV+Rbyqx1OwY4VLXRoc3QaCeP ab+uXGDTI6isAw6sXw+GOF9uX6IIKOvfBq+qVU4aJ8gKeAZeTnOKfGazx2C9BUMK UrTAg8T9EoMazA6MRFBKzf6Dm6wnCwjpwL7f+HTfei3XFmmuUJh5G5UwHiGY3g+6 n00zNM3HP8hY57s4Wvoo4dw/kQA2RDTP0ZKpVWPMtWJJUfrKI0TsqmqBxQj1f4r7 dfbCAZPASIjjZxbPWn4x472JAYk4mWCQYFQh3XcMXupLJK1gMCgtgj78jnFI7r/a lTIVvzDfOp4w0T143gyXLbFswSBzyU7uYVrIISqsrXKeSDPmS4Fl0BELjMReRJgs ER0NQ0z1SXGcexP1d8OC =VNdg -----END PGP SIGNATURE----- --kfjH4zxOES6UT95V--