From patchwork Thu Mar 30 10:23:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 77022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1022593vqo; Thu, 30 Mar 2023 03:27:58 -0700 (PDT) X-Google-Smtp-Source: AKy350bv/igGS+JK+hy4aSoXmFH6I2HBuUcxUxmjq7cI74BoNWIOzYRhA8KFpAdGomgfmKKu2HGY X-Received: by 2002:a17:906:36db:b0:93b:49e8:d7b9 with SMTP id b27-20020a17090636db00b0093b49e8d7b9mr24030147ejc.40.1680172078411; Thu, 30 Mar 2023 03:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680172078; cv=none; d=google.com; s=arc-20160816; b=Nf7XIQHX86Os+7KVZSQAS7wJSOUQoHUeuxmAuc7N5GTYrhvq5B45EhI9tOXspKXLF8 5hWG7aed+5vG5YVg2JPtvQFPfhtKkX2R8gM+8F0zGdZt5oP6vFM7AaRewxpMuKFhKz0Z v6+jNY/3i2xkfqZKc634S/K9uSPBc732ko6I7deCVRcUDkk3wPI2jGNptSgojAu30eC2 ITq6ku6kkDfrV8W9E47QBmoxsGxnYRBSPcun3PzQrpuZ+uDKIQS6sQS7fnVyLGnkhHXg BCFuN3CKX7Qbg1VaWLkuf2S+wCVeLaQ4xVoyXWCiX+Fgfw3pugSJ0M4vRpmdyEifFyPh PhCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=tmc+E2tWA7iyYjEM1FjCwy+iyCVFX0PDL7XAArRXWqc=; b=kIIrqgFqQxNO2aHxzP0DKEGwv7S71pzuq5J/4B+kbSFwQxWBitzdb/tPqRk7/1fNGw ckHhDyDIlsXjjDC6NX1vSYjHECk9SDf7usZtLrj0VcnP7FIHbmi8JxIEZ0KIT2Es/+ZP fGgk0ns8OmNsBpolVdN9rYPPZXAdtWNz58gnAlGHtX4QcoeUCSeY0NnaeXe330z7Bqhu TeCbcuqX/Jg7ov8ZB9NwinVzzE27pkH/thYXMIk8D7kx9+oS6sXXdkKOt0ret3Fce5ac X55LFdkPCUumML2fbrvntY0QqRug5Na6DZ5t9DmnrcaE0tfB3XCQXQMXbvOp+Smi98/i 1p6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MaOcIMAl; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v12-20020a1709061dcc00b0092ff7e4cdc8si31913268ejh.267.2023.03.30.03.27.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 03:27:58 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=MaOcIMAl; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 843833883016 for ; Thu, 30 Mar 2023 10:26:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 843833883016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680171966; bh=tmc+E2tWA7iyYjEM1FjCwy+iyCVFX0PDL7XAArRXWqc=; 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=MaOcIMAlkHLLqvI4qNaX8ggP4819YAiRfScCFZOcQOA+TYb/mN0AaZkDxXL1NAgvY OSbh1PoIaRZr4ZqUp9ojYc442efrhYTeXBYRCSFpJX6zGCQwTBrF6T8FqqGJ3aML7u q1MDO9k9N1B8O55NMlPd1PI6NVECTShttmwM0kKI= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 1D5E738582A4 for ; Thu, 30 Mar 2023 10:24:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D5E738582A4 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 4BA952F4; Thu, 30 Mar 2023 03:25:05 -0700 (PDT) Received: from e121540-lin.manchester.arm.com (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 82BBF3F663; Thu, 30 Mar 2023 03:24:20 -0700 (PDT) To: binutils@sourceware.org Cc: Richard Sandiford Subject: [PATCH 09/43] aarch64: Rework parse_typed_reg interface Date: Thu, 30 Mar 2023 11:23:25 +0100 Message-Id: <20230330102359.3327695-10-richard.sandiford@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230330102359.3327695-1-richard.sandiford@arm.com> References: <20230330102359.3327695-1-richard.sandiford@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-33.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Sandiford via Binutils From: Richard Sandiford Reply-To: Richard Sandiford Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761788117385868321?= X-GMAIL-MSGID: =?utf-8?q?1761788117385868321?= parse_typed_reg returned a register number and passed the register type back using a pointer parameter. It seems simpler to return the register entry instead, since that has both pieces of information in one place. The patch also replaces the boolean in_reg_list parameter with a mask of flags. This hopefully makes calls easier to read (more self-documenting than "true" or "false"), but more importantly, it allows a later patch to add a second flag. --- gas/config/tc-aarch64.c | 124 +++++++++++++++++----------------------- 1 file changed, 53 insertions(+), 71 deletions(-) diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 7de0f5c83f6..8c3d627a08b 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -1006,19 +1006,19 @@ parse_predication_for_operand (struct vector_type_el *parsed_type, char **str) /* Parse a register of the type TYPE. - Return PARSE_FAIL if the string pointed by *CCP is not a valid register + Return null if the string pointed to by *CCP is not a valid register name or the parsed register is not of TYPE. - Otherwise return the register number, and optionally fill in the actual - type of the register in *RTYPE when multiple alternatives were given, and - return the register shape and element index information in *TYPEINFO. + Otherwise return the register, and optionally return the register + shape and element index information in *TYPEINFO. - IN_REG_LIST should be set with TRUE if the caller is parsing a register - list. */ + FLAGS includes PTR_IN_REGLIST if the caller is parsing a register list. */ -static int -parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, - struct vector_type_el *typeinfo, bool in_reg_list) +#define PTR_IN_REGLIST (1U << 0) + +static const reg_entry * +parse_typed_reg (char **ccp, aarch64_reg_type type, + struct vector_type_el *typeinfo, unsigned int flags) { char *str = *ccp; const reg_entry *reg = parse_reg (&str); @@ -1036,14 +1036,14 @@ parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, if (typeinfo) *typeinfo = atype; set_default_error (); - return PARSE_FAIL; + return NULL; } if (! aarch64_check_reg_type (reg, type)) { DEBUG_TRACE ("reg type check failed"); set_default_error (); - return PARSE_FAIL; + return NULL; } type = reg->type; @@ -1053,12 +1053,12 @@ parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, if (*str == '.') { if (!parse_vector_type_for_operand (type, &parsetype, &str)) - return PARSE_FAIL; + return NULL; } else { if (!parse_predication_for_operand (&parsetype, &str)) - return PARSE_FAIL; + return NULL; } /* Register if of the form Vn.[bhsdq]. */ @@ -1092,13 +1092,13 @@ parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, if (!is_typed_vecreg) { first_error (_("this type of register can't be indexed")); - return PARSE_FAIL; + return NULL; } - if (in_reg_list) + if (flags & PTR_IN_REGLIST) { first_error (_("index not allowed inside register list")); - return PARSE_FAIL; + return NULL; } atype.defined |= NTA_HASINDEX; @@ -1108,19 +1108,19 @@ parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, if (exp.X_op != O_constant) { first_error (_("constant expression required")); - return PARSE_FAIL; + return NULL; } if (! skip_past_char (&str, ']')) - return PARSE_FAIL; + return NULL; atype.index = exp.X_add_number; } - else if (!in_reg_list && (atype.defined & NTA_HASINDEX) != 0) + else if (!(flags & PTR_IN_REGLIST) && (atype.defined & NTA_HASINDEX) != 0) { /* Indexed vector register expected. */ first_error (_("indexed vector register expected")); - return PARSE_FAIL; + return NULL; } /* A vector reg Vn should be typed or indexed. */ @@ -1132,44 +1132,25 @@ parse_typed_reg (char **ccp, aarch64_reg_type type, aarch64_reg_type *rtype, if (typeinfo) *typeinfo = atype; - if (rtype) - *rtype = type; - *ccp = str; - return reg->number; + return reg; } /* Parse register. - Return the register number on success; return PARSE_FAIL otherwise. - - If RTYPE is not NULL, return in *RTYPE the (possibly restricted) type of - the register (e.g. NEON double or quad reg when either has been requested). + Return the register on success; return null otherwise. If this is a NEON vector register with additional type information, fill in the struct pointed to by VECTYPE (if non-NULL). - This parser does not handle register list. */ + This parser does not handle register lists. */ -static int +static const reg_entry * aarch64_reg_parse (char **ccp, aarch64_reg_type type, - aarch64_reg_type *rtype, struct vector_type_el *vectype) + struct vector_type_el *vectype) { - struct vector_type_el atype; - char *str = *ccp; - int reg = parse_typed_reg (&str, type, rtype, &atype, - /*in_reg_list= */ false); - - if (reg == PARSE_FAIL) - return PARSE_FAIL; - - if (vectype) - *vectype = atype; - - *ccp = str; - - return reg; + return parse_typed_reg (ccp, type, vectype, 0); } static inline bool @@ -1239,14 +1220,15 @@ parse_vector_reg_list (char **ccp, aarch64_reg_type type, str++; /* skip over '-' */ val_range = val; } - val = parse_typed_reg (&str, type, NULL, &typeinfo, - /*in_reg_list= */ true); - if (val == PARSE_FAIL) + const reg_entry *reg = parse_typed_reg (&str, type, &typeinfo, + PTR_IN_REGLIST); + if (!reg) { set_first_syntax_error (_("invalid vector register in list")); error = true; continue; } + val = reg->number; /* reject [bhsd]n */ if (type == REG_TYPE_VN && typeinfo.defined == 0) { @@ -2271,18 +2253,18 @@ const pseudo_typeS md_pseudo_table[] = { static bool reg_name_p (char *str, aarch64_reg_type reg_type) { - int reg; + const reg_entry *reg; /* Prevent the diagnostics state from being spoiled. */ if (error_p ()) return false; - reg = aarch64_reg_parse (&str, reg_type, NULL, NULL); + reg = aarch64_reg_parse (&str, reg_type, NULL); /* Clear the parsing error that may be set by the reg parser. */ clear_error (); - if (reg == PARSE_FAIL) + if (!reg) return false; skip_whitespace (str); @@ -4957,8 +4939,8 @@ parse_sys_ins_reg (char **str, htab_t sys_ins_regs) } while (0) #define po_reg_or_fail(regtype) do { \ - val = aarch64_reg_parse (&str, regtype, &rtype, NULL); \ - if (val == PARSE_FAIL) \ + reg = aarch64_reg_parse (&str, regtype, NULL); \ + if (!reg) \ { \ set_default_error (); \ goto failure; \ @@ -6344,7 +6326,6 @@ parse_operands (char *str, const aarch64_opcode *opcode) int64_t val; const reg_entry *reg; int comma_skipped_p = 0; - aarch64_reg_type rtype; struct vector_type_el vectype; aarch64_opnd_qualifier_t qualifier, base_qualifier, offset_qualifier; aarch64_opnd_info *info = &inst.base.operands[i]; @@ -6443,16 +6424,17 @@ parse_operands (char *str, const aarch64_opcode *opcode) case AARCH64_OPND_SVE_Vd: case AARCH64_OPND_SVE_Vm: case AARCH64_OPND_SVE_Vn: - val = aarch64_reg_parse (&str, REG_TYPE_BHSDQ, &rtype, NULL); - if (val == PARSE_FAIL) + reg = aarch64_reg_parse (&str, REG_TYPE_BHSDQ, NULL); + if (!reg) { first_error (_(get_reg_expected_msg (REG_TYPE_BHSDQ))); goto failure; } - gas_assert (rtype >= REG_TYPE_FP_B && rtype <= REG_TYPE_FP_Q); + gas_assert (reg->type >= REG_TYPE_FP_B + && reg->type <= REG_TYPE_FP_Q); - info->reg.regno = val; - info->qualifier = AARCH64_OPND_QLF_S_B + (rtype - REG_TYPE_FP_B); + info->reg.regno = reg->number; + info->qualifier = AARCH64_OPND_QLF_S_B + (reg->type - REG_TYPE_FP_B); break; case AARCH64_OPND_SVE_Pd: @@ -6483,8 +6465,8 @@ parse_operands (char *str, const aarch64_opcode *opcode) case AARCH64_OPND_Vm: reg_type = REG_TYPE_VN; vector_reg: - val = aarch64_reg_parse (&str, reg_type, NULL, &vectype); - if (val == PARSE_FAIL) + reg = aarch64_reg_parse (&str, reg_type, &vectype); + if (!reg) { first_error (_(get_reg_expected_msg (reg_type))); goto failure; @@ -6492,7 +6474,7 @@ parse_operands (char *str, const aarch64_opcode *opcode) if (vectype.defined & NTA_HASINDEX) goto failure; - info->reg.regno = val; + info->reg.regno = reg->number; if ((reg_type == REG_TYPE_PN || reg_type == REG_TYPE_ZN) && vectype.type == NT_invtype) /* Unqualified Pn and Zn registers are allowed in certain @@ -6509,8 +6491,8 @@ parse_operands (char *str, const aarch64_opcode *opcode) case AARCH64_OPND_VdD1: case AARCH64_OPND_VnD1: - val = aarch64_reg_parse (&str, REG_TYPE_VN, NULL, &vectype); - if (val == PARSE_FAIL) + reg = aarch64_reg_parse (&str, REG_TYPE_VN, &vectype); + if (!reg) { set_first_syntax_error (_(get_reg_expected_msg (REG_TYPE_VN))); goto failure; @@ -6521,7 +6503,7 @@ parse_operands (char *str, const aarch64_opcode *opcode) (_("the top half of a 128-bit FP/SIMD register is expected")); goto failure; } - info->reg.regno = val; + info->reg.regno = reg->number; /* N.B: VdD1 and VnD1 are treated as an fp or advsimd scalar register here; it is correct for the purpose of encoding/decoding since only the register number is explicitly encoded in the related @@ -6545,8 +6527,8 @@ parse_operands (char *str, const aarch64_opcode *opcode) case AARCH64_OPND_SM3_IMM2: reg_type = REG_TYPE_VN; vector_reg_index: - val = aarch64_reg_parse (&str, reg_type, NULL, &vectype); - if (val == PARSE_FAIL) + reg = aarch64_reg_parse (&str, reg_type, &vectype); + if (!reg) { first_error (_(get_reg_expected_msg (reg_type))); goto failure; @@ -6554,7 +6536,7 @@ parse_operands (char *str, const aarch64_opcode *opcode) if (vectype.type == NT_invtype || !(vectype.defined & NTA_HASINDEX)) goto failure; - info->reglane.regno = val; + info->reglane.regno = reg->number; info->reglane.index = vectype.index; info->qualifier = vectype_to_qualifier (&vectype); if (info->qualifier == AARCH64_OPND_QLF_NIL) @@ -6576,13 +6558,13 @@ parse_operands (char *str, const aarch64_opcode *opcode) && get_opcode_dependent_value (opcode) == 1 && *str != '{') { - val = aarch64_reg_parse (&str, reg_type, NULL, &vectype); - if (val == PARSE_FAIL) + reg = aarch64_reg_parse (&str, reg_type, &vectype); + if (!reg) { first_error (_(get_reg_expected_msg (reg_type))); goto failure; } - info->reglist.first_regno = val; + info->reglist.first_regno = reg->number; info->reglist.num_regs = 1; } else