From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18654 invoked by alias); 27 Jul 2017 08:06:32 -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 18626 invoked by uid 89); 27 Jul 2017 08:06:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.6 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: dedi548.your-server.de Received: from dedi548.your-server.de (HELO dedi548.your-server.de) (85.10.215.148) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 27 Jul 2017 08:06:29 +0000 Received: from [88.198.220.131] (helo=sslproxy02.your-server.de) by dedi548.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.85_2) (envelope-from ) id 1dadoR-0001Wx-17 for newlib@sourceware.org; Thu, 27 Jul 2017 10:06:27 +0200 Received: from [82.135.62.35] (helo=mail.embedded-brains.de) by sslproxy02.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-GCM-SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dadoQ-00008W-O9 for newlib@sourceware.org; Thu, 27 Jul 2017 10:06:26 +0200 Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 106D02A001D for ; Thu, 27 Jul 2017 10:06:35 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ZxI-Pqbi8BKm for ; Thu, 27 Jul 2017 10:06:33 +0200 (CEST) Received: from localhost (localhost.localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id C5E352A004F for ; Thu, 27 Jul 2017 10:06:33 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id T_JSKJWt2Imr for ; Thu, 27 Jul 2017 10:06:33 +0200 (CEST) Received: from linux-diu0.suse (unknown [192.168.96.129]) by mail.embedded-brains.de (Postfix) with ESMTP id A547F2A001D for ; Thu, 27 Jul 2017 10:06:33 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH] Workaround for ffs() on LP64 targets Date: Thu, 27 Jul 2017 08:06:00 -0000 Message-Id: <20170727080624.24818-1-sebastian.huber@embedded-brains.de> X-IsSubscribed: yes X-SW-Source: 2017/txt/msg00665.txt.bz2 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) { +#ifdef __LP64__ + /* GCC would expand the __builtin_ffs() to ffs() in this case */ + int bit; + + if (i == 0) + return (0); + for (bit = 1; !(i & 1); bit++) + i = (unsigned int)i >> 1; + return (bit); +#else return (__builtin_ffs(i)); +#endif } -- 2.12.3