From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12739 Path: news.gmane.org!.POSTED!not-for-mail From: Andre McCurdy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH 1/2] remove a_ctz_l from arch specific atomic_arch.h Date: Wed, 18 Apr 2018 17:40:59 -0700 Message-ID: <1524098460-8072-2-git-send-email-armccurdy@gmail.com> References: <1524098460-8072-1-git-send-email-armccurdy@gmail.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1524098369 12648 195.159.176.226 (19 Apr 2018 00:39:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 19 Apr 2018 00:39:29 +0000 (UTC) Cc: Andre McCurdy To: musl@lists.openwall.com Original-X-From: musl-return-12755-gllmg-musl=m.gmane.org@lists.openwall.com Thu Apr 19 02:39:25 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1f8xbf-0003Be-Q1 for gllmg-musl@m.gmane.org; Thu, 19 Apr 2018 02:39:23 +0200 Original-Received: (qmail 24552 invoked by uid 550); 19 Apr 2018 00:41:31 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 24508 invoked from network); 19 Apr 2018 00:41:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EOxRt4OvFwCniJGXj0gUpCC0jw07YV57oTuVrn7Pggg=; b=pcuUrSS+IPQEGgCPaCG6RvFI8LnAXttVM0MBbgxIf/WqEoHyUUSCl10nEIqf/TJ+VW CFukWVfak6v29LSLP76OT/0BDGk9ywYO3CmwFd1AjwLaVxGL8/d+LvmNleH6c0P2UUKp rID3up7tIzZsBjsmzMFw8+7scZDsA+3pU6rEncryVIaUJDp98EfKl7QZcrI2yLzUJzfF 9NXEDuJ17lbTEl3QWmF9sEs5FceI/bSojOSo+U9uJWrlgBZYHh62WZ8dLc5URuLKyiOO iqWb5Hq6GLx3k9OUIoJ9XBdk+dvWkLS3MEcTmuJ9ptRmpk02LvDJqA09FxYy+eukjVXh hlpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EOxRt4OvFwCniJGXj0gUpCC0jw07YV57oTuVrn7Pggg=; b=YlkZDS/JZzg/VUvWkZPqWrq4Vih9fDQdOOs4FuoqySXPQzDhuAnd76jSiGQQFJF5Aa 4kIQkv3ZMJwuwxlCBKhkknGLZ0EYdje6lvT4kvEaxMhjMzrPw2zNYhneCS+jQcos1Gcm h9i/YZPxnZBVp+sW75wmI2df7L9g5IMvOGWdEHCrRf5TxYs4EGrAHfDYSmmInBGoKv98 Ud0B/HDEktWkfmtRfW+jmn+tlwTxaPlmf8M5P+avMV33xLPvUNbXKvUh3z3vkQnOqFH6 q62qmdriJkUJQ1J1MF/EaZiSKLwxexQyGySolPl4EkgC5IBOnhWwmDVtqJcOMI5vCsCW NU6Q== X-Gm-Message-State: ALQs6tADAnOs/6DBO7E0AOxzqkL6/TghPayeQe832492I/l23y+Kyvnz XVkKoqu5oDzYB5g53C1bFNSUCw== X-Google-Smtp-Source: AIpwx48f4r+dos28Ba8sjVogqMA8WE6ctPzNIl4koihEg2HdHFWimU0Kd6x18JShcqPT63fRDEokhw== X-Received: by 10.99.127.86 with SMTP id p22mr3401657pgn.306.1524098477804; Wed, 18 Apr 2018 17:41:17 -0700 (PDT) X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524098460-8072-1-git-send-email-armccurdy@gmail.com> Xref: news.gmane.org gmane.linux.lib.musl.general:12739 Archived-At: Update atomic.h to provide a_ctz_l in all cases (atomic_arch.h should now only provide a_ctz_32 and/or a_ctz_64). The generic version of a_ctz_32 now takes advantage of a_clz_32 if available and the generic a_ctz_64 now makes use of a_ctz_32. --- arch/i386/atomic_arch.h | 6 +++--- arch/x32/atomic_arch.h | 4 ++-- src/internal/atomic.h | 42 +++++++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/arch/i386/atomic_arch.h b/arch/i386/atomic_arch.h index 7d2a48a..047fb68 100644 --- a/arch/i386/atomic_arch.h +++ b/arch/i386/atomic_arch.h @@ -92,10 +92,10 @@ static inline int a_ctz_64(uint64_t x) return r; } -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) { - long r; + int r; __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) ); return r; } diff --git a/arch/x32/atomic_arch.h b/arch/x32/atomic_arch.h index a744c29..918c2d4 100644 --- a/arch/x32/atomic_arch.h +++ b/arch/x32/atomic_arch.h @@ -106,8 +106,8 @@ static inline int a_ctz_64(uint64_t x) return x; } -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) { __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) ); return x; diff --git a/src/internal/atomic.h b/src/internal/atomic.h index ab473dd..f938879 100644 --- a/src/internal/atomic.h +++ b/src/internal/atomic.h @@ -251,6 +251,22 @@ static inline void a_crash() } #endif +#ifndef a_ctz_32 +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) +{ +#ifdef a_clz_32 + return 31-a_clz_32(x&-x); +#else + static const char debruijn32[32] = { + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 + }; + return debruijn32[(x&-x)*0x076be629 >> 27]; +#endif +} +#endif + #ifndef a_ctz_64 #define a_ctz_64 a_ctz_64 static inline int a_ctz_64(uint64_t x) @@ -261,22 +277,23 @@ static inline int a_ctz_64(uint64_t x) 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 }; - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; if (sizeof(long) < 8) { uint32_t y = x; if (!y) { y = x>>32; - return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; + return 32 + a_ctz_32(y); } - return debruijn32[(y&-y)*0x076be629 >> 27]; + return a_ctz_32(y); } return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; } #endif +static inline int a_ctz_l(unsigned long x) +{ + return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x); +} + #ifndef a_clz_64 #define a_clz_64 a_clz_64 static inline int a_clz_64(uint64_t x) @@ -298,17 +315,4 @@ static inline int a_clz_64(uint64_t x) } #endif -#ifndef a_ctz_l -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) -{ - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; - if (sizeof(long) == 8) return a_ctz_64(x); - return debruijn32[(x&-x)*0x076be629 >> 27]; -} -#endif - #endif -- 1.9.1