From patchwork Wed Sep 4 13:26:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 1980819 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=A4uIo/7E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WzNm80tMzz1yXY for ; Wed, 4 Sep 2024 23:35:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50FEF38708AD for ; Wed, 4 Sep 2024 13:35:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc2f.google.com (mail-oo1-xc2f.google.com [IPv6:2607:f8b0:4864:20::c2f]) by sourceware.org (Postfix) with ESMTPS id 3ECB73861027 for ; Wed, 4 Sep 2024 13:27:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3ECB73861027 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3ECB73861027 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725456480; cv=none; b=phlmCzHHisUY7pQTMSDiqaHSPvXFGWm5H7T9VeM+FYEgYCrHFUVCrK7oi+hH67Kw8WuTWJDcgYML/qvX3eTfPK+L8xRj0dz1OVLSAVkkd92BStO66k0hvez/8odemWrWVVfzFqRwoJzq1FDwrjfKNKiFzDB/+7DtJjNwI38014A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725456480; c=relaxed/simple; bh=WhNdcH8BrhG5Bbdlt2Kl/i9LAOmm2UwZ/vlDCb65qik=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=u5EpWG9R434gANQMLdQhEqEvo+qXSpLA4PvYUuC9D0jXk03N/t81m6xnuoZ2k6/DDAnlpjXNXE0+HWU5T8klIHoodfmd2Wr3HwqVyuu7yeqWOqGHEjAmQCYi0Mw4LVDGnGxdMNTxbuOelxgCLt2Mal+GWssF+4EdLeNMO+jtQ6k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2f.google.com with SMTP id 006d021491bc7-5df9433ac0cso4415613eaf.3 for ; Wed, 04 Sep 2024 06:27:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725456474; x=1726061274; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fnwhyqZyijtHQp2JzsgiqUA2kLkDNYK+xDVZh42rGhc=; b=A4uIo/7EK9ubbGECrvuKszZEG9V6VJIQVXjRNj8kdEsS9UQz5NgJykITDuM/XiE3Za D36j2z2nuCH4ggk48LODXPDQvMz14ahk/N2983014mI/Cr48DpUzhgOSy0tjKzTx4av3 cAcv2ZvoRmij2VrQgNhr+uYpEzG1IHKK+azPSLUh4B+/bVQe0W617SRjmY3jCsCS43fY BziTeX53dIa4OwdIFDfeKKEUEegdBUgyLe65bLYgvuWRv+8XsQTR8cwDHjp78nzrd49T DVKzqbkt3fIrpUI+EsyYiSIOcPXY4fhl2z0J/fOSi6nZyA9b765IhpHx/kpJ8zmld2Tg r1qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725456474; x=1726061274; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fnwhyqZyijtHQp2JzsgiqUA2kLkDNYK+xDVZh42rGhc=; b=ZtVQlNt61b5ZAQW1a5e6eqC3OAS+QhOywNtgVk6FMDksBgJjRq1mQSU+RFDA1mTfeT LWDlDMrCdiRhJLHRawaki5RCYKjx/Rw+sO5M/49+/5IlnJx4P/7krlBXoi586PReMb2Y kSD4Iu6gydDGnkY/DHMcP22UgHiT5M06dkNA8gPXArMiJ+aiu4WL4PYZOMdu6Gll8z0U v5n5sKq42Q13UKgMuzOH+asvSbQvRDhKzfuyWzl+73rLmX6m2Fc69mVnAe8fbsZ+9Uxv 7ccnM0FsdWWKIMLU8b0PlKzKzF1HNnErF10D92yAZE6g1xFN2YFzRlwK4ZuR2EpicUd6 /tCw== X-Gm-Message-State: AOJu0Yydgwu/RI6LFDIco99RWvxbsDJLVQHIzTQ+jt4KQBmAzCKQq33Z C1xW7Wo8WxFyB0C48RsszhHA55Pc05jfzCvsNstEVMB+ZZHi3Da8frbSGK8OOxs3fcJUdCciOM8 tieTTzg== X-Google-Smtp-Source: AGHT+IGResFOFAQcbEuWZv99iHhzgZlnRSocWBbZKBOwezmulLMswPfCKl/FO81H48J2GcsEkn458w== X-Received: by 2002:a05:6820:1ad5:b0:5da:9b98:e208 with SMTP id 006d021491bc7-5dfad0203e6mr19650502eaf.5.1725456474224; Wed, 04 Sep 2024 06:27:54 -0700 (PDT) Received: from localhost.localdomain ([139.178.84.207]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5dfa0580692sm2308062eaf.46.2024.09.04.06.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 06:27:53 -0700 (PDT) From: Christophe Lyon To: gcc-patches@gcc.gnu.org, richard.earnshaw@arm.com, ramanara@nvidia.com Cc: Christophe Lyon Subject: [PATCH v2 36/36] arm: [MVE intrinsics] use long_type_suffix / half_type_suffix helpers Date: Wed, 4 Sep 2024 13:26:50 +0000 Message-Id: <20240904132650.2720446-37-christophe.lyon@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240904132650.2720446-1-christophe.lyon@linaro.org> References: <20240711214305.3193022-1-christophe.lyon@linaro.org> <20240904132650.2720446-1-christophe.lyon@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org In several places we are looking for a type twice or half as large as the type suffix: this patch introduces helper functions to avoid code duplication. long_type_suffix is similar to the SVE counterpart, but adds an 'expected_tclass' parameter. half_type_suffix is similar to it, but does not exist in SVE. 2024-08-28 Christophe Lyon gcc/ * config/arm/arm-mve-builtins-shapes.cc (long_type_suffix): New. (half_type_suffix): New. (struct binary_move_narrow_def): Use new helper. (struct binary_move_narrow_unsigned_def): Likewise. (struct binary_rshift_narrow_def): Likewise. (struct binary_rshift_narrow_unsigned_def): Likewise. (struct binary_widen_def): Likewise. (struct binary_widen_n_def): Likewise. (struct binary_widen_opt_n_def): Likewise. (struct unary_widen_def): Likewise. --- gcc/config/arm/arm-mve-builtins-shapes.cc | 114 +++++++++++++--------- 1 file changed, 68 insertions(+), 46 deletions(-) diff --git a/gcc/config/arm/arm-mve-builtins-shapes.cc b/gcc/config/arm/arm-mve-builtins-shapes.cc index 9deed178966..0a108cf0127 100644 --- a/gcc/config/arm/arm-mve-builtins-shapes.cc +++ b/gcc/config/arm/arm-mve-builtins-shapes.cc @@ -320,6 +320,45 @@ build_16_32 (function_builder &b, const char *signature, } } +/* TYPE is the largest type suffix associated with the arguments of R, but the + result is twice as wide. Return the associated type suffix of + EXPECTED_TCLASS if it exists, otherwise report an appropriate error and + return NUM_TYPE_SUFFIXES. */ +static type_suffix_index +long_type_suffix (function_resolver &r, + type_suffix_index type, + type_class_index expected_tclass) +{ + unsigned int element_bits = type_suffixes[type].element_bits; + if (expected_tclass == function_resolver::SAME_TYPE_CLASS) + expected_tclass = type_suffixes[type].tclass; + + if (type_suffixes[type].integer_p && element_bits < 64) + return find_type_suffix (expected_tclass, element_bits * 2); + + r.report_no_such_form (type); + return NUM_TYPE_SUFFIXES; +} + +/* Return the type suffix half as wide as TYPE with EXPECTED_TCLASS if it + exists, otherwise report an appropriate error and return + NUM_TYPE_SUFFIXES. */ +static type_suffix_index +half_type_suffix (function_resolver &r, + type_suffix_index type, + type_class_index expected_tclass) +{ + unsigned int element_bits = type_suffixes[type].element_bits; + if (expected_tclass == function_resolver::SAME_TYPE_CLASS) + expected_tclass = type_suffixes[type].tclass; + + if (type_suffixes[type].integer_p && element_bits > 8) + return find_type_suffix (expected_tclass, element_bits / 2); + + r.report_no_such_form (type); + return NUM_TYPE_SUFFIXES; +} + /* Declare the function shape NAME, pointing it to an instance of class _def. */ #define SHAPE(NAME) \ @@ -779,16 +818,13 @@ struct binary_move_narrow_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, narrow_suffix; if (!r.check_gp_argument (2, i, nargs) - || (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES) + || (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES + || ((narrow_suffix = half_type_suffix (r, type, r.SAME_TYPE_CLASS)) + == NUM_TYPE_SUFFIXES)) return error_mark_node; - type_suffix_index narrow_suffix - = find_type_suffix (type_suffixes[type].tclass, - type_suffixes[type].element_bits / 2); - - if (!r.require_matching_vector_type (0, narrow_suffix)) return error_mark_node; @@ -816,15 +852,13 @@ struct binary_move_narrow_unsigned_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, narrow_suffix; if (!r.check_gp_argument (2, i, nargs) - || (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES) + || (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES + || ((narrow_suffix = half_type_suffix (r, type, TYPE_unsigned)) + == NUM_TYPE_SUFFIXES)) return error_mark_node; - type_suffix_index narrow_suffix - = find_type_suffix (TYPE_unsigned, - type_suffixes[type].element_bits / 2); - if (!r.require_matching_vector_type (0, narrow_suffix)) return error_mark_node; @@ -1112,16 +1146,14 @@ struct binary_rshift_narrow_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, narrow_suffix; if (!r.check_gp_argument (3, i, nargs) || (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES + || ((narrow_suffix = half_type_suffix (r, type, r.SAME_TYPE_CLASS)) + == NUM_TYPE_SUFFIXES) || !r.require_integer_immediate (i)) return error_mark_node; - type_suffix_index narrow_suffix - = find_type_suffix (type_suffixes[type].tclass, - type_suffixes[type].element_bits / 2); - if (!r.require_matching_vector_type (0, narrow_suffix)) return error_mark_node; @@ -1159,16 +1191,14 @@ struct binary_rshift_narrow_unsigned_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, narrow_suffix; if (!r.check_gp_argument (3, i, nargs) || (type = r.infer_vector_type (1)) == NUM_TYPE_SUFFIXES + || ((narrow_suffix = half_type_suffix (r, type, TYPE_unsigned)) + == NUM_TYPE_SUFFIXES) || !r.require_integer_immediate (i)) return error_mark_node; - type_suffix_index narrow_suffix - = find_type_suffix (TYPE_unsigned, - type_suffixes[type].element_bits / 2); - if (!r.require_matching_vector_type (0, narrow_suffix)) return error_mark_node; @@ -1205,15 +1235,13 @@ struct binary_widen_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, wide_suffix; if (!r.check_gp_argument (2, i, nargs) - || (type = r.infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES) + || (type = r.infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES + || ((wide_suffix = long_type_suffix (r, type, r.SAME_TYPE_CLASS)) + == NUM_TYPE_SUFFIXES)) return error_mark_node; - type_suffix_index wide_suffix - = find_type_suffix (type_suffixes[type].tclass, - type_suffixes[type].element_bits * 2); - if (!r.require_matching_vector_type (i, type)) return error_mark_node; @@ -1298,17 +1326,15 @@ struct binary_widen_n_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, wide_suffix; tree res; if (!r.check_gp_argument (2, i, nargs) || (type = r.infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES + || ((wide_suffix = long_type_suffix (r, type, r.SAME_TYPE_CLASS)) + == NUM_TYPE_SUFFIXES) || !r.require_integer_immediate (i)) return error_mark_node; - type_suffix_index wide_suffix - = find_type_suffix (type_suffixes[type].tclass, - type_suffixes[type].element_bits * 2); - /* Check the inactive argument has the wide type. */ if (((r.pred == PRED_m) && (r.infer_vector_type (0) == wide_suffix)) || r.pred == PRED_none @@ -1352,15 +1378,13 @@ struct binary_widen_opt_n_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, wide_suffix; if (!r.check_gp_argument (2, i, nargs) - || (type = r.infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES) + || (type = r.infer_vector_type (i - 1)) == NUM_TYPE_SUFFIXES + || ((wide_suffix = long_type_suffix (r, type, r.SAME_TYPE_CLASS)) + == NUM_TYPE_SUFFIXES)) return error_mark_node; - type_suffix_index wide_suffix - = find_type_suffix (type_suffixes[type].tclass, - type_suffixes[type].element_bits * 2); - /* Skip last argument, may be scalar, will be checked below by finish_opt_n_resolution. */ unsigned int last_arg = i--; @@ -1939,16 +1963,14 @@ struct unary_widen_def : public overloaded_base<0> resolve (function_resolver &r) const override { unsigned int i, nargs; - type_suffix_index type; + type_suffix_index type, wide_suffix; tree res; if (!r.check_gp_argument (1, i, nargs) - || (type = r.infer_vector_type (i)) == NUM_TYPE_SUFFIXES) + || (type = r.infer_vector_type (i)) == NUM_TYPE_SUFFIXES + || ((wide_suffix = long_type_suffix (r, type, r.SAME_TYPE_CLASS)) + == NUM_TYPE_SUFFIXES)) return error_mark_node; - type_suffix_index wide_suffix - = find_type_suffix (type_suffixes[type].tclass, - type_suffixes[type].element_bits * 2); - /* Check the inactive argument has the wide type. */ if ((r.pred == PRED_m) && (r.infer_vector_type (0) != wide_suffix))