From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47971 invoked by alias); 27 Jul 2017 09:01:04 -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 39144 invoked by uid 89); 27 Jul 2017 09:00:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-19.3 required=5.0 tests=AWL,BAYES_00,FOREIGN_BODY,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1505, H*i:sk:d2568ba, H*f:sk:Gwo2odK, H*f:sk:d2568ba X-HELO: mail-ua0-f195.google.com Received: from mail-ua0-f195.google.com (HELO mail-ua0-f195.google.com) (209.85.217.195) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jul 2017 09:00:07 +0000 Received: by mail-ua0-f195.google.com with SMTP id w45so16157405uac.3 for ; Thu, 27 Jul 2017 02:00:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=0g8GtII9shs6W6BgzAjKNgjutBWSBEcBrSsiTgUljvA=; b=GAA3B7/K7gtLTZYSK5bwMrKncC4TVIP3TaT8iL6Xo/jk9hLsfwyT3QtpdI92359oog bKhtPG8f7ClxJ9/ZmnCs9SjTpCIXBTY5qTvkrIATPAyd8rVxV44ML1B1zBeZXCMH1STT BYNaBEYo2iw0pnm4jmrax4XSUDrXovEMqBWWWI8mh0riOlhU0JtJwwNuF+fu/ojCTLAZ YQHF2yXhydtbmZl0Gtbq51f2kPp56wCYEHT0Tb0PxlTgWGPRY/nELxVhn6igECb4mJCI spwL2aK19ocoraPLjZWYJjTzQPJIKKrc6pTZBHek3DC3t3iWtYgda0edDD8kdrAFFOnF sERQ== X-Gm-Message-State: AIVw110AXq/OoucsS5z4prxEsHxxI/PFqGVChI0QdBe3onW3S2VfWv+6 yYGeVsqmHAqxhLrddsvqfK6izXNJDb5G X-Received: by 10.159.57.201 with SMTP id p9mr2519299uag.209.1501146004424; Thu, 27 Jul 2017 02:00:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.31.96.72 with HTTP; Thu, 27 Jul 2017 01:59:44 -0700 (PDT) In-Reply-To: References: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> From: Kito Cheng Date: Thu, 27 Jul 2017 09:01:00 -0000 Message-ID: Subject: Re: [PATCH] Workaround for ffs() on LP64 targets To: Sebastian Huber Cc: newlib@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00668.txt.bz2 Hi Sebastian: You mean look like this? I am ok for this if you feel this solution is acceptable :) Signed-off-by: Sebastian Huber --- newlib/libc/misc/ffs.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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) { +#if defined(__LP64__) && defined(__riscv) + /* 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); +#else return (__builtin_ffs(i)); +#endif } On Thu, Jul 27, 2017 at 4:40 PM, Sebastian Huber wrote: > On 27/07/17 10:29, Kito Cheng wrote: > >> it's will make aarch64 gen worse code (compare to __builtin_ffs >> version) since aarch64 have clz, but I don't have better idea too... > > > Maybe we should add a defined(__riscv__). A count leading zeros instructi= on > is quite common. > > -- > Sebastian Huber, embedded brains GmbH > > Address : Dornierstr. 4, D-82178 Puchheim, Germany > Phone : +49 89 189 47 41-16 > Fax : +49 89 189 47 41-09 > E-Mail : sebastian.huber@embedded-brains.de > PGP : Public key available on request. > > Diese Nachricht ist keine gesch=C3=A4ftliche Mitteilung im Sinne des EHUG. >