From patchwork Tue Jan 7 16:34:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yufeng Zhang X-Patchwork-Id: 307703 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E8A822C00DF for ; Wed, 8 Jan 2014 03:35:09 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=WlA44iR9RXkJyD9G9J/IAfV1nOQYfx0s8MjdAhGs+po fZus+/slX3nhfSgwWPQx0AnzNh26CC6n0chm/feNzLoKLgY2BDPPrUe1NlR63FPu YKiaqJ44PO3ZH97k6AXfFfPQ8d5/GXVQp9LiRguUl6rWeOemE+rvC65pQAwtlflA = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=P7hxotFx5uXa2LttefVfyMqBZdU=; b=OSQBZU5GIpDioK8Cg eY5XLSLNhXQeETbYKXA4IiUezEJ2szRSmKZITS7/h831XTfB0psISoCyHnsRcySk lBkGN3mEZ+ZY+K7FZMsD8bEn49bLPdsp7iP0ev0kR5INaCRdW9AOeKaL7Vs/FECn dG5ZUScz0AwGaF0Lb5Pn7eEUus= Received: (qmail 4645 invoked by alias); 7 Jan 2014 16:35:02 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 4628 invoked by uid 89); 7 Jan 2014 16:35:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: service87.mimecast.com Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Jan 2014 16:35:00 +0000 Received: from cam-owa1.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Tue, 07 Jan 2014 16:34:57 +0000 Received: from [10.1.201.52] ([10.1.255.212]) by cam-owa1.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Tue, 7 Jan 2014 16:34:57 +0000 Message-ID: <52CC2CB0.3080309@arm.com> Date: Tue, 07 Jan 2014 16:34:56 +0000 From: Yufeng Zhang User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Marcus Shawcroft Subject: [PATCH, AArch64] Use GCC builtins to count leading/tailing zeros X-MC-Unique: 114010716345701001 X-IsSubscribed: yes Hi, This patch is to sync up include/longlong.h with its glibc peer after the proposed change here: http://sourceware.org/ml/libc-alpha/2014-01/msg00114.html The patch defines a number of macros in stdlib/longlong.h to use GCC builtins __builtin_clz* to implement the __clz* and __ctz* functions on AArch64. OK for the mainline? Thanks, Yufeng include/ * longlong.h (count_leading_zeros, count_trailing_zeros) (COUNT_LEADING_ZEROS_0): Define for aarch64. diff --git a/include/longlong.h b/include/longlong.h index 5f00e54..b4c1f400 100644 --- a/include/longlong.h +++ b/include/longlong.h @@ -122,6 +122,22 @@ extern const UQItype __clz_tab[256] attribute_hidden; #define __AND_CLOBBER_CC , "cc" #endif /* __GNUC__ < 2 */ +#if defined (__aarch64__) + +#if W_TYPE_SIZE == 32 +#define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X)) +#define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X)) +#define COUNT_LEADING_ZEROS_0 32 +#endif /* W_TYPE_SIZE == 32 */ + +#if W_TYPE_SIZE == 64 +#define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clzll (X)) +#define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctzll (X)) +#define COUNT_LEADING_ZEROS_0 64 +#endif /* W_TYPE_SIZE == 64 */ + +#endif /* __aarch64__ */ + #if defined (__alpha) && W_TYPE_SIZE == 64 #define umul_ppmm(ph, pl, m0, m1) \ do { \