From patchwork Mon Jul 17 09:02:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sylvain Noiry X-Patchwork-Id: 121141 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp991509vqt; Mon, 17 Jul 2023 02:08:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlER2bsNneUyfbec87A/OEBSC0fOySyi04lGjjkQfF9O3Fik7bXexP0jdEwe1sh+VmMzV86z X-Received: by 2002:aa7:cb4d:0:b0:51d:8f9b:b6ce with SMTP id w13-20020aa7cb4d000000b0051d8f9bb6cemr10704559edt.1.1689584918544; Mon, 17 Jul 2023 02:08:38 -0700 (PDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d12-20020aa7c1cc000000b0051bfc04e1b4si13055419edp.226.2023.07.17.02.08.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 02:08:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RouPneOQ; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 264D03856DDF for ; Mon, 17 Jul 2023 09:07:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 264D03856DDF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689584823; bh=P7hSdHi6xaqfI1HNTVj2zfAo0PQk5KpGuPDMfhOT7CQ=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=RouPneOQw40uE3KUvNKjzB4qFQfWwbod0W4x9RVZKTNEdjSX2bfaLXRTHfwSNkMso ewnQwqRiFguYziuSMkmvz8PL6wQzTvS+2FRQdQtkuYJLUuUndG46byyGE7K7ACqPdr q1OG6RFS8ag7/C9gOWg5LA8aXmMZZ62BBOpD64u0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpout140.security-mail.net (smtpout140.security-mail.net [85.31.212.148]) by sourceware.org (Postfix) with ESMTPS id 5395E38582A3 for ; Mon, 17 Jul 2023 09:03:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5395E38582A3 Received: from localhost (fx408.security-mail.net [127.0.0.1]) by fx408.security-mail.net (Postfix) with ESMTP id 66CEA3229FB for ; Mon, 17 Jul 2023 11:03:54 +0200 (CEST) Received: from fx408 (fx408.security-mail.net [127.0.0.1]) by fx408.security-mail.net (Postfix) with ESMTP id 485CB322571 for ; Mon, 17 Jul 2023 11:03:54 +0200 (CEST) Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01lp0109.outbound.protection.outlook.com [104.47.24.109]) by fx408.security-mail.net (Postfix) with ESMTPS id C635C322517 for ; Mon, 17 Jul 2023 11:03:53 +0200 (CEST) Received: from MR2P264MB0113.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:11::21) by PAZP264MB3040.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1e7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.32; Mon, 17 Jul 2023 09:03:52 +0000 Received: from MR2P264MB0113.FRAP264.PROD.OUTLOOK.COM ([fe80::a854:17f0:8f2a:f6d9]) by MR2P264MB0113.FRAP264.PROD.OUTLOOK.COM ([fe80::a854:17f0:8f2a:f6d9%4]) with mapi id 15.20.6588.031; Mon, 17 Jul 2023 09:03:52 +0000 X-Virus-Scanned: E-securemail Secumail-id: <5884.64b503f9.c4ae3.0> ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RRV9SFC9pJkOcE7n0WwZqKHCksO0tNZYjgeNWv+6ln0RFC13laZ5Me8DstsYEPzdDDHYvwwMHH0MdlLEHQzsTcEH6Z2dnPyDynNy2b3uaNo434bE+61pXs5NU6vRjdbrRiy+MS/uwyKmPUptqlJVqfJdFPaJzjm9GcJ0Vv0snAO7cOo+zmtPJhMft5JOYIZJ9o20EPCeUFASX4BDt/KcjE2iDOM4IV6jaO1QBe4AauRwHgyv396APusj5b9EZp62i0r8N0rMLgl2Z4jBmBuSGGcSmJsenIcl/VA3bA3bWlL3VDocCoEw317kZzYa1BalLTpRo/MnB9SX61EK4gPQQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=P7hSdHi6xaqfI1HNTVj2zfAo0PQk5KpGuPDMfhOT7CQ=; b=oNEDS1ga7sVuUkczvFj1wRyS0uSQMKNh+lGP1TJSsNMjfaiHk5S+25uuGFhnxUMz4Ct2az6sMqsACCl0FAgUWK8LzqwjrgfumCVTjiiQQyRgac+rwdYjiAv0v0kXSAi1mrCcfQ81AhTF55BozhutloR28JNo/cvqcUC7Nh6UejdCKomcXWS/2c/PU8CfRzVaFl2YlvLHFplISjFw4aHl127ooYdFC536nZ/BJA7zj3WvISlTciRclTzZrlShFSEIbPd3U2Day0fklwF50Sf04XCyvGSUVpqhgNETHA9myIh6UK/3rf++YH8ZfyE0PVeZmo94BJCj/+9LYksp1A3Hpg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=kalrayinc.com; dmarc=pass action=none header.from=kalrayinc.com; dkim=pass header.d=kalrayinc.com; arc=none To: gcc-patches@gcc.gnu.org Cc: Sylvain Noiry Subject: [PATCH 8/9] Native complex operations: Add explicit vector of complex Date: Mon, 17 Jul 2023 11:02:49 +0200 Message-ID: <20230717090250.4645-9-snoiry@kalrayinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230717090250.4645-1-snoiry@kalrayinc.com> References: <20230717090250.4645-1-snoiry@kalrayinc.com> X-ClientProxiedBy: LO6P123CA0044.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::20) To MR2P264MB0113.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:11::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MR2P264MB0113:EE_|PAZP264MB3040:EE_ X-MS-Office365-Filtering-Correlation-Id: f0d7a5d5-0544-4908-1930-08db86a4bde9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gNRz+UiTivjDlhpdZ4ifb2y1kCC0BlAhWZcnj51I9oy4inc/Y6QI/C3DjwhLIlo7AZdKfCoZlDpzfPMUyz2nQAMxsj8JqNKXVoKzJWmmVKNkCKKIpAWPAwNHU0n62kPpiU+UkX29tHeTrsJdtxsbKYdHuBw22jN4A/NLCi6lc5w4MseWGyKNKB7D+JBialUUJ5iVzklepXrmBMf2igOPNqvw5+AVxVaLlbTu1fb+ENEaVMrkNgrY0rGNeRcY5iDtfpkuhpVJO2h0XUKjX07Dcwu3yBZo2A//vQF3qIJbPuKMf/8u2p1vIh6/xkzB1db3dE318HQFYXW89C8ZZPWJ0oWsxnZC0GyFETe7Avl3VppHUgoPGS6l89S0Ro7EdqbuJu9VG5mcJ1rtpB6oLpXauS+MuYtKuaOk5mJjViAjebaD5J/fAXyXqnxwOgvidQFTmizEQ5PXxh38ZFZv7kvCvNYG8fSpt01tBClzdsYmTKGHJ39BU/LKWRW3QyLkcEcs5lYzdfgLo1/4CIK3bU1VD/npuSvje+1UqOgorgZtmewz4tVYAQrfLa8UGoddMAmH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MR2P264MB0113.FRAP264.PROD.OUTLOOK.COM; PTR:; CAT:NONE; SFS:(13230028)(4636009)(396003)(366004)(346002)(136003)(39850400004)(376002)(451199021)(478600001)(6486002)(6666004)(186003)(1076003)(6506007)(26005)(6512007)(107886003)(2906002)(41300700001)(316002)(6916009)(4326008)(66476007)(66946007)(66556008)(5660300002)(36756003)(8676002)(8936002)(38100700002)(86362001)(2616005)(83380400001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ooLBJX+fxjSZ57kl9bTaEp691+ugnZnd5mebS7WekWiAW0x4sm7VlJEqYOOVjQ3Hd2xSQDA55gaXIR4RQXg51JloyY/qZI9B/x+qU65KivJHbpHp35yWfmNNpA0gnxkaFFu4TCxR8vWYB2r1abnLKBTdwMdo2T3TUeHLKcsMo7cFsPh1A95P3WqH5htiU/n1XLGAPLQsLZXqU6k09xq77WTaQL5BuDxVshj2SteA9ruvL05hZYL337xIgpsjPuAPvW1rNF0hTFLZR6eU1Qkr5MES2sOLWU+XcGZsd+op3/gVKGT9fb1rrKU1c2cTP/CEWuJOxtUZhbsvEC4EFiJuJHmSgt01XwnCz9Ytz/1BnKH5C+fAALgK0gcrphveGG2jcdCGWhbbzaX8FKZRRO4W5IQUS6z4XKDvRpw5ssW24x+K48GXHFz+igbhNlqGuZBSpGz8CqLn5htOxPdw1h0IVNIqjzezjc36+ZISXDstFAqvEKqTxnfmO+A9PvO56PC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4rAYlip2stR7f X-OriginatorOrg: kalrayinc.com X-MS-Exchange-CrossTenant-Network-Message-Id: f0d7a5d5-0544-4908-1930-08db86a4bde9 X-MS-Exchange-CrossTenant-AuthSource: MR2P264MB0113.FRAP264.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 09:03:52.2908 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8931925d-7620-4a64-b7fe-20afd86363d3 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: kbHZ6mhM1Iket4YICgHC1j32dlvosXb9O5zThQ8EiVq/6c+Rkar4wu17ndsc43fyarMSvavzeZX0xgMYezJV8Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAZP264MB3040 X-ALTERMIMEV2_out: done X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Sylvain Noiry via Gcc-patches From: Sylvain Noiry Reply-To: Sylvain Noiry Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771658196012333292 X-GMAIL-MSGID: 1771658196012333292 Allow the creation and usage of builtins vectors of complex in C, using __attribute__ ((vector_size ())) gcc/c-family/ChangeLog: * c-attribs.cc (vector_mode_valid_p): Add cases for vectors of complex (handle_mode_attribute): Likewise (type_valid_for_vector_size): Likewise * c-common.cc (c_common_type_for_mode): Likewise (vector_types_compatible_elements_p): Likewise gcc/ChangeLog: * fold-const.cc (fold_binary_loc): Likewise gcc/c/ChangeLog: * c-typeck.cc (build_unary_op): Likewise --- gcc/c-family/c-attribs.cc | 12 ++++++++++-- gcc/c-family/c-common.cc | 20 +++++++++++++++++++- gcc/c/c-typeck.cc | 8 ++++++-- gcc/fold-const.cc | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index e2792ca6898..d4de85160c1 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -2019,6 +2019,8 @@ vector_mode_valid_p (machine_mode mode) /* Doh! What's going on? */ if (mclass != MODE_VECTOR_INT && mclass != MODE_VECTOR_FLOAT + && mclass != MODE_VECTOR_COMPLEX_INT + && mclass != MODE_VECTOR_COMPLEX_FLOAT && mclass != MODE_VECTOR_FRACT && mclass != MODE_VECTOR_UFRACT && mclass != MODE_VECTOR_ACCUM @@ -2125,6 +2127,8 @@ handle_mode_attribute (tree *node, tree name, tree args, case MODE_VECTOR_INT: case MODE_VECTOR_FLOAT: + case MODE_VECTOR_COMPLEX_INT: + case MODE_VECTOR_COMPLEX_FLOAT: case MODE_VECTOR_FRACT: case MODE_VECTOR_UFRACT: case MODE_VECTOR_ACCUM: @@ -4361,9 +4365,13 @@ type_valid_for_vector_size (tree type, tree atname, tree args, if ((!INTEGRAL_TYPE_P (type) && !SCALAR_FLOAT_TYPE_P (type) + && !COMPLEX_INTEGER_TYPE_P (type) + && !COMPLEX_FLOAT_TYPE_P (type) && !FIXED_POINT_TYPE_P (type)) - || (!SCALAR_FLOAT_MODE_P (orig_mode) - && GET_MODE_CLASS (orig_mode) != MODE_INT + || ((!SCALAR_FLOAT_MODE_P (orig_mode) + && GET_MODE_CLASS (orig_mode) != MODE_INT) + && (!COMPLEX_FLOAT_MODE_P (orig_mode) + && GET_MODE_CLASS (orig_mode) != MODE_COMPLEX_INT) && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode)) || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type)) || TREE_CODE (type) == BOOLEAN_TYPE) diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc index 6ab63dae997..9574c074d26 100644 --- a/gcc/c-family/c-common.cc +++ b/gcc/c-family/c-common.cc @@ -2430,7 +2430,23 @@ c_common_type_for_mode (machine_mode mode, int unsignedp) : make_signed_type (precision)); } - if (COMPLEX_MODE_P (mode)) + if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL + && valid_vector_subparts_p (GET_MODE_NUNITS (mode))) + { + unsigned int elem_bits = vector_element_size (GET_MODE_BITSIZE (mode), + GET_MODE_NUNITS (mode)); + tree bool_type = build_nonstandard_boolean_type (elem_bits); + return build_vector_type_for_mode (bool_type, mode); + } + else if (VECTOR_MODE_P (mode) + && valid_vector_subparts_p (GET_MODE_NUNITS (mode))) + { + machine_mode inner_mode = GET_MODE_INNER (mode); + tree inner_type = c_common_type_for_mode (inner_mode, unsignedp); + if (inner_type != NULL_TREE) + return build_vector_type_for_mode (inner_type, mode); + } + else if (COMPLEX_MODE_P (mode)) { machine_mode inner_mode; tree inner_type; @@ -8104,9 +8120,11 @@ vector_types_compatible_elements_p (tree t1, tree t2) gcc_assert ((INTEGRAL_TYPE_P (t1) || c1 == REAL_TYPE + || c1 == COMPLEX_TYPE || c1 == FIXED_POINT_TYPE) && (INTEGRAL_TYPE_P (t2) || c2 == REAL_TYPE + || c2 == COMPLEX_TYPE || c2 == FIXED_POINT_TYPE)); t1 = c_common_signed_type (t1); diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 7cf411155c6..68a9646cf5b 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -4584,7 +4584,9 @@ build_unary_op (location_t location, enum tree_code code, tree xarg, /* ~ works on integer types and non float vectors. */ if (typecode == INTEGER_TYPE || (gnu_vector_type_p (TREE_TYPE (arg)) - && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg)))) + && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg)) + && !COMPLEX_INTEGER_TYPE_P (TREE_TYPE (TREE_TYPE (arg))) + && !COMPLEX_FLOAT_TYPE_P (TREE_TYPE (TREE_TYPE (arg))))) { tree e = arg; @@ -4607,7 +4609,9 @@ build_unary_op (location_t location, enum tree_code code, tree xarg, if (!noconvert) arg = default_conversion (arg); } - else if (typecode == COMPLEX_TYPE) + else if (typecode == COMPLEX_TYPE + || COMPLEX_INTEGER_TYPE_P (TREE_TYPE (TREE_TYPE (arg))) + || COMPLEX_FLOAT_TYPE_P (TREE_TYPE (TREE_TYPE (arg)))) { code = CONJ_EXPR; pedwarn (location, OPT_Wpedantic, diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index f1224b6a548..9e9f711e82d 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -11109,6 +11109,7 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type, to __complex__ ( x, y ). This is not the same for SNaNs or if signed zeros are involved. */ if (!HONOR_SNANS (arg0) + && !(VECTOR_TYPE_P (TREE_TYPE (arg0))) && !HONOR_SIGNED_ZEROS (arg0) && COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))) {