From patchwork Sat Nov 7 12:32:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 541279 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 12F6B1402D4 for ; Sat, 7 Nov 2015 23:32:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=rA9Gxw7g; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=Egu8drQZN+/MvORh bgsrrSLzKCPYm4J1v6NPnXuEcDR1Aus3e1NUHVeM4lR9lzMv6w3ie2scmyFZNGuL sIMypSv1WzS6lOX2m9w6eVuMwyJ3lV5kT5uHODDYX9XOoc5/sniko+UTSTyJzJ1Z 3cOIgnZhxEsBqp88ydBrSIxJh+U= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=Xvy/xS5PDiL8GUlYhJh+Z8 U+u54=; b=rA9Gxw7glNfvQ1gYUmAptabo/A5qq/a8Adf+FHXVbQmuLiUfUutcpq UXzKlz0/ZfjiPI1ZjEklKEfNlxiwEP96ljwgtxC2YLThH6hynNstKrhzuvkP7XKk IuExDntfwIqgVxLVyLlIMjtq0T9p7tQuW24RHTLBBzPDRHHvNs6Rg= Received: (qmail 8197 invoked by alias); 7 Nov 2015 12:32:41 -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 8185 invoked by uid 89); 7 Nov 2015 12:32:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, SPF_PASS autolearn=ham version=3.3.2 X-HELO: eu-smtp-delivery-143.mimecast.com Received: from eu-smtp-delivery-143.mimecast.com (HELO eu-smtp-delivery-143.mimecast.com) (146.101.78.143) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Nov 2015 12:32:39 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.140]) by eu-smtp-1.mimecast.com with ESMTP id uk-mta-3-g1p9x9DaTUSAtW-1f6AYKw-1; Sat, 07 Nov 2015 12:32:33 +0000 Received: from localhost ([10.1.2.79]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 7 Nov 2015 12:32:33 +0000 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Add internal bitcount functions Date: Sat, 07 Nov 2015 12:32:33 +0000 Message-ID: <8737wirnvi.fsf@e105548-lin.cambridge.arm.com> User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-MC-Unique: g1p9x9DaTUSAtW-1f6AYKw-1 This patch adds internal function equivalents of all the INT_FN functions. Unlike the math functions, these functions never set errno and the internal functions should be exactly equivalent to the built-in ones. The reason for defining the internal functions is so that we can extend the functionality to other modes, in particular vector modes. Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi. OK to install? Thanks, Richard gcc/ * internal-fn.def (DEF_INTERNAL_INT_FN): New macro. (CLRSB, CLZ, CTZ, FFS, PARITY, POPCOUNT): New functions. * builtins.c (associated_internal_fn): Handle them. diff --git a/gcc/builtins.c b/gcc/builtins.c index 0a9b185..edf0086 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -1916,6 +1916,8 @@ associated_internal_fn (tree fndecl) { #define DEF_INTERNAL_FLT_FN(NAME, FLAGS, OPTAB, TYPE) \ CASE_FLT_FN (BUILT_IN_##NAME): return IFN_##NAME; +#define DEF_INTERNAL_INT_FN(NAME, FLAGS, OPTAB, TYPE) \ + CASE_INT_FN (BUILT_IN_##NAME): return IFN_##NAME; #include "internal-fn.def" CASE_FLT_FN (BUILT_IN_POW10): diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index 65e158e..bf8047a 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see DEF_INTERNAL_FN (NAME, FLAGS, FNSPEC) DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE) DEF_INTERNAL_FLT_FN (NAME, FLAGS, OPTAB, TYPE) + DEF_INTERNAL_INT_FN (NAME, FLAGS, OPTAB, TYPE) where NAME is the name of the function, FLAGS is a set of ECF_* flags and FNSPEC is a string describing functions fnspec. @@ -53,6 +54,10 @@ along with GCC; see the file COPYING3. If not see function BUILT_IN_{F,,L}. Unlike some built-in functions, these internal functions never set errno. + DEF_INTERNAL_INT_FN is like DEF_INTERNAL_OPTAB_FN, but in addition + says that the function extends the C-level BUILT_IN_{,L,LL,IMAX} + group of functions to any integral mode (including vector modes). + Each entry must have a corresponding expander of the form: void expand_NAME (gimple_call stmt) @@ -75,6 +80,11 @@ along with GCC; see the file COPYING3. If not see DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE) #endif +#ifndef DEF_INTERNAL_INT_FN +#define DEF_INTERNAL_INT_FN(NAME, FLAGS, OPTAB, TYPE) \ + DEF_INTERNAL_OPTAB_FN (NAME, FLAGS, OPTAB, TYPE) +#endif + DEF_INTERNAL_OPTAB_FN (MASK_LOAD, ECF_PURE, maskload, mask_load) DEF_INTERNAL_OPTAB_FN (LOAD_LANES, ECF_CONST, vec_load_lanes, load_lanes) @@ -119,6 +129,14 @@ DEF_INTERNAL_FLT_FN (SCALB, ECF_CONST, scalb, binary) /* FP scales. */ DEF_INTERNAL_FLT_FN (LDEXP, ECF_CONST, ldexp, binary) +/* Unary integer ops. */ +DEF_INTERNAL_INT_FN (CLRSB, ECF_CONST, clrsb, unary) +DEF_INTERNAL_INT_FN (CLZ, ECF_CONST, clz, unary) +DEF_INTERNAL_INT_FN (CTZ, ECF_CONST, ctz, unary) +DEF_INTERNAL_INT_FN (FFS, ECF_CONST, ffs, unary) +DEF_INTERNAL_INT_FN (PARITY, ECF_CONST, parity, unary) +DEF_INTERNAL_INT_FN (POPCOUNT, ECF_CONST, popcount, unary) + DEF_INTERNAL_FN (GOMP_SIMD_LANE, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (GOMP_SIMD_VF, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (GOMP_SIMD_LAST_LANE, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) @@ -163,6 +181,7 @@ DEF_INTERNAL_FN (GOACC_LOOP, ECF_PURE | ECF_NOTHROW, NULL) /* OpenACC reduction abstraction. See internal-fn.h for usage. */ DEF_INTERNAL_FN (GOACC_REDUCTION, ECF_NOTHROW | ECF_LEAF, NULL) +#undef DEF_INTERNAL_INT_FN #undef DEF_INTERNAL_FLT_FN #undef DEF_INTERNAL_OPTAB_FN #undef DEF_INTERNAL_FN