From patchwork Mon Aug 20 09:29:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 28968 Received: (qmail 15757 invoked by alias); 20 Aug 2018 09:29:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15624 invoked by uid 89); 20 Aug 2018 09:29:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=worker, 12096 X-HELO: EUR03-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr30043.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.107.3.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 20 Aug 2018 09:29:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=30kI2FHwtLiJqv12REbkjBWxQNKwYtGj8EioyG627z0=; b=d6odvVbGzHu1wGAyx3ITXbmiAZMwRC8cSpBzvCyZe9wCU4mnqsiGSr7KLl2PQ8mfrtw6YLbQxidTEYQdFtCKXoHUE50w8jANtRhZvRZbxrZKnanrUmKcss98y3HxgPL+ld6nv4y0+4AvwnUd/BxKrri8qX+kXqD1AQmtFmBgH98= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.manchester.arm.com (217.140.106.32) by AM4PR0802MB2131.eurprd08.prod.outlook.com (2603:10a6:200:5c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1059.21; Mon, 20 Aug 2018 09:29:47 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH 1/4] Aarch64: Func to detect args passed in float regs Date: Mon, 20 Aug 2018 10:29:30 +0100 Message-Id: <20180820092933.83224-2-alan.hayward@arm.com> In-Reply-To: <20180820092933.83224-1-alan.hayward@arm.com> References: <20180820092933.83224-1-alan.hayward@arm.com> MIME-Version: 1.0 Return-Path: alan.hayward@arm.com Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes aapcs_is_vfp_call_or_return_candidate is as an eventual replacement for is_hfa_or_hva. This function is based on the GCC code gcc/config/aarch64/aarch64.c:aarch64_vfp_is_call_or_return_candidate () 2018-08-20 Alan Hayward * aarch64-tdep.c (HA_MAX_NUM_FLDS): New macro. (aapcs_is_vfp_call_or_return_candidate_1): New function. (aapcs_is_vfp_call_or_return_candidate): Likewise. --- gdb/aarch64-tdep.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 5c6eb98545..d3ea13f6f6 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -71,6 +71,10 @@ #define AARCH64_B0_REGNUM (AARCH64_H0_REGNUM + 32) #define AARCH64_SVE_V0_REGNUM (AARCH64_B0_REGNUM + 32) +/* A Homogeneous Floating-Point or Short-Vector Aggregate may have at most + four members. */ +#define HA_MAX_NUM_FLDS 4 + /* All possible aarch64 target descriptors. */ struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1]; @@ -1209,6 +1213,143 @@ is_hfa_or_hva (struct type *ty) return 0; } +/* Worker function for aapcs_is_vfp_call_or_return_candidate. + + Return the number of register required, or -1 on failure. + + When encountering a base element, if FUNDAMENTAL_TYPE is not set then set it + to the element, else fail if the type of this element does not match the + existing value. */ + +static int +aapcs_is_vfp_call_or_return_candidate_1 (struct type *type, + struct type **fundamental_type) +{ + if (type == nullptr) + return -1; + + switch (TYPE_CODE (type)) + { + case TYPE_CODE_FLT: + if (TYPE_LENGTH (type) > 16) + return -1; + + if (*fundamental_type == nullptr) + *fundamental_type = type; + else if (TYPE_LENGTH (type) != TYPE_LENGTH (*fundamental_type) + || TYPE_CODE (type) != TYPE_CODE (*fundamental_type)) + return -1; + + return 1; + + case TYPE_CODE_COMPLEX: + { + struct type *target_type = check_typedef (TYPE_TARGET_TYPE (type)); + if (TYPE_LENGTH (target_type) > 16) + return -1; + + if (*fundamental_type == nullptr) + *fundamental_type = target_type; + else if (TYPE_LENGTH (target_type) != TYPE_LENGTH (*fundamental_type) + || TYPE_CODE (target_type) != TYPE_CODE (*fundamental_type)) + return -1; + + return 2; + } + + case TYPE_CODE_ARRAY: + { + if (TYPE_VECTOR (type)) + { + if (TYPE_LENGTH (type) != 8 && TYPE_LENGTH (type) != 16) + return -1; + + if (*fundamental_type == nullptr) + *fundamental_type = type; + else if (TYPE_LENGTH (type) != TYPE_LENGTH (*fundamental_type) + || TYPE_CODE (type) != TYPE_CODE (*fundamental_type)) + return -1; + + return 1; + } + else + { + struct type *target_type = TYPE_TARGET_TYPE (type); + int count = aapcs_is_vfp_call_or_return_candidate_1 + (target_type, fundamental_type); + + if (count == -1) + return count; + + count *= TYPE_LENGTH (type); + return count; + } + } + + case TYPE_CODE_STRUCT: + case TYPE_CODE_UNION: + { + int count = 0; + + for (int i = 0; i < TYPE_NFIELDS (type); i++) + { + struct type *member = check_typedef (TYPE_FIELD_TYPE (type, i)); + + int sub_count = aapcs_is_vfp_call_or_return_candidate_1 + (member, fundamental_type); + if (sub_count == -1) + return -1; + count += sub_count; + } + return count; + } + + default: + break; + } + + return -1; +} + +/* Return true if an argument, whose type is described by TYPE, can be passed or + returned in simd/fp registers, providing enough parameter passing registers + are available. This is as described in the AAPCS64. + + Upon successful return, *COUNT returns the number of needed registers, + *FUNDAMENTAL_TYPE contains the type of those registers. + + Candidate as per the AAPCS64 5.4.2.C is either a: + - float. + - short-vector. + - HFA (Homogeneous Floating-point Aggregate, 4.3.5.1). A Composite type where + all the members are floats and has at most 4 members. + - HVA (Homogeneous Short-vector Aggregate, 4.3.5.2). A Composite type where + all the members are short vectors and has at most 4 members. + - Complex (7.1.1) + + Note that HFAs and HVAs can include nested structures and arrays. */ + +bool +aapcs_is_vfp_call_or_return_candidate (struct type *type, int *count, + struct type **fundamental_type) +{ + if (type == nullptr) + return false; + + *fundamental_type = nullptr; + + int ag_count = aapcs_is_vfp_call_or_return_candidate_1 (type, + fundamental_type); + + if (ag_count > 0 && ag_count <= HA_MAX_NUM_FLDS) + { + *count = ag_count; + return true; + } + else + return false; +} + /* AArch64 function call information structure. */ struct aarch64_call_info {