From patchwork Thu Mar 30 10:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 77067 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1030792vqo; Thu, 30 Mar 2023 03:46:44 -0700 (PDT) X-Google-Smtp-Source: AKy350bcT8KuDxrdWXqxj2L9v+PpgbIR0G+tH2EzOiVr4b+ysaRrshiil8AI8PKb+KH6wQ9FamXN X-Received: by 2002:a17:907:d40c:b0:933:3a65:67ed with SMTP id vi12-20020a170907d40c00b009333a6567edmr27212599ejc.75.1680173203878; Thu, 30 Mar 2023 03:46:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680173203; cv=none; d=google.com; s=arc-20160816; b=MV778Tr2uD5MDGv9zODOPZ4+pGmrcprINecDO/9baOTkk+kUiTBo+oBiqvfRHOiVst g4FpxYD/iJrmgolh+kklGnSVb0S1XklsCH1567Slhtnf2vexMEJ3jyFvDrMQv+w/XB7m ZrpRf0zOpbpZI2njD09XOocQpbIUvazelYf3+tkdoAAjDXtulcROGkzgebKKeYbdcVKV 2u7J0UpN1y/1wuzCoLrXKRTL2ZVyd6vlV+3ZKylfz1u90585gWYiA40uy6mLIramduJ9 D3FLsdIYlo2PQ4D8WKpIkqz0OkKb/Z04PlwkjH1AN3YFfsEVfN4ORwk1OLSpe9MPyyRU PdXQ== 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=HefGV/HyWWFEL5Tnij1hlbBcpVomUTodcr5LmsNQock=; b=0C+z6a1b92WRMHYcfHp6JdaCh4kr+4Uo2FokkEBnkxxrhf0Et0UXhP+oKSZbqm1Nld 2r1+gQUWjX6mBnoXqy4uCi1W/+b4/h7FklzG0K4lQ09WqEWPhfpdPhY0KgQtucKoz81Z T3V7MZfR3eWeXjuze1dyMfLRANMzw8FQ6NeLsNuXs53QEIg2bCsHdaUwOx76fCJmR3IR K/fZrIsxzA2IyMr5yVc8UvdXdn3C3iaLJ8Phqc3PRhFEYejDPWOWIPRpkpZ3E2DcPyug sx4ZI5Het7g+ek0TMUy5dgYqSBJXvF0jFsNPHve0Id5oEmhvYhEUuuC1G/5ENOTQ7M89 9R/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=U6RwQiao; 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 hv13-20020a17090760cd00b0093dd280a785si19773643ejc.897.2023.03.30.03.46.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 03:46:43 -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=U6RwQiao; 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 E8942381DDBC for ; Thu, 30 Mar 2023 10:34:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8942381DDBC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1680172472; bh=HefGV/HyWWFEL5Tnij1hlbBcpVomUTodcr5LmsNQock=; 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=U6RwQiaogKZsiMHiqnL51MymR53a8b4irQmaNCchrisBV/V37dMzPTC5bkAjHm8Le KQM9DrzYFX4QJbWDkMt3oI+6kYqZ17WwQOR7IsS9V0eAHBP/8XXthW/t6i/yolmlOG nrc9HM10TlMyEjiveTkgKhihRrn7x/Vuvn4fyr0A= 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 B50DB385B52D for ; Thu, 30 Mar 2023 10:24:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B50DB385B52D 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 ED55D2F4; Thu, 30 Mar 2023 03:25:20 -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 307D33F663; Thu, 30 Mar 2023 03:24:36 -0700 (PDT) To: binutils@sourceware.org Cc: Richard Sandiford Subject: [PATCH 31/43] aarch64: Make AARCH64_OPDE_REG_LIST take a bitfield Date: Thu, 30 Mar 2023 11:23:47 +0100 Message-Id: <20230330102359.3327695-32-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=-32.9 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?1761789297106107360?= X-GMAIL-MSGID: =?utf-8?q?1761789297106107360?= AARCH64_OPDE_REG_LIST took a single operand that specified the expected number of registers. However, there are quite a few SME2 instructions that have both 2-register forms and (separate) 4-register forms. If the user tries to use a 3-register list, it isn't obvious which opcode entry they meant. Saying that we expect 2 registers and saying that we expect 4 registers would both be wrong. This patch therefore switches the operand to a bitfield. If a AARCH64_OPDE_REG_LIST is reported against multiple opcode entries, the patch ORs up the expected lengths. This has no user-visible effect yet. A later patch adds more error strings, alongside tests that use them. --- gas/config/tc-aarch64.c | 54 ++++++++++++++++++++++++++--------------- opcodes/aarch64-opc.c | 2 +- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/gas/config/tc-aarch64.c b/gas/config/tc-aarch64.c index 145e241b13b..a57cc2bc080 100644 --- a/gas/config/tc-aarch64.c +++ b/gas/config/tc-aarch64.c @@ -4914,6 +4914,20 @@ parse_sys_ins_reg (char **str, htab_t sys_ins_regs) goto failure; \ } while (0) +/* A primitive log calculator. */ + +static inline unsigned int +get_log2 (unsigned int n) +{ + unsigned int count = 0; + while (n > 1) + { + n >>= 1; + count += 1; + } + return count; +} + /* encode the 12-bit imm field of Add/sub immediate */ static inline uint32_t encode_addsub_imm (uint32_t imm) @@ -5732,14 +5746,17 @@ output_operand_error_record (const operand_error_record *record, char *str) break; case AARCH64_OPDE_REG_LIST: - if (detail->data[0].i == 1) + if (detail->data[0].i == (1 << 1)) handler (_("invalid number of registers in the list; " "only 1 register is expected at operand %d -- `%s'"), idx + 1, str); - else + else if ((detail->data[0].i & -detail->data[0].i) == detail->data[0].i) handler (_("invalid number of registers in the list; " "%d registers are expected at operand %d -- `%s'"), - detail->data[0].i, idx + 1, str); + get_log2 (detail->data[0].i), idx + 1, str); + else + handler (_("invalid number of registers in the list" + " at operand %d -- `%s'"), idx + 1, str); break; case AARCH64_OPDE_UNALIGNED: @@ -5807,6 +5824,12 @@ output_operand_error_report (char *str, bool non_fatal_only) curr->detail.data[0].i, curr->detail.data[1].i, curr->detail.data[2].i); } + else if (curr->detail.kind == AARCH64_OPDE_REG_LIST) + { + DEBUG_TRACE ("\t%s [%x]", + operand_mismatch_kind_names[curr->detail.kind], + curr->detail.data[0].i); + } else { DEBUG_TRACE ("\t%s", operand_mismatch_kind_names[curr->detail.kind]); @@ -5847,6 +5870,13 @@ output_operand_error_report (char *str, bool non_fatal_only) curr->detail.data[0].i, curr->detail.data[1].i, curr->detail.data[2].i); } + else if (kind == AARCH64_OPDE_REG_LIST) + { + record->detail.data[0].i |= curr->detail.data[0].i; + DEBUG_TRACE ("\t--> %s [%x]", + operand_mismatch_kind_names[kind], + curr->detail.data[0].i); + } } } @@ -6191,22 +6221,6 @@ process_movw_reloc_info (void) return true; } -/* A primitive log calculator. */ - -static inline unsigned int -get_logsz (unsigned int size) -{ - const unsigned char ls[16] = - {0, 1, -1, 2, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1, 4}; - if (size > 16) - { - gas_assert (0); - return -1; - } - gas_assert (ls[size - 1] != (unsigned char)-1); - return ls[size - 1]; -} - /* Determine and return the real reloc type code for an instruction with the pseudo reloc type code BFD_RELOC_AARCH64_LDST_LO12. */ @@ -6271,7 +6285,7 @@ ldst_lo12_determine_real_reloc_type (void) 1, opd0_qlf, 0); gas_assert (opd1_qlf != AARCH64_OPND_QLF_NIL); - logsz = get_logsz (aarch64_get_qualifier_esize (opd1_qlf)); + logsz = get_log2 (aarch64_get_qualifier_esize (opd1_qlf)); if (inst.reloc.type == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12 || inst.reloc.type == BFD_RELOC_AARCH64_TLSLD_LDST_DTPREL_LO12_NC diff --git a/opcodes/aarch64-opc.c b/opcodes/aarch64-opc.c index dfffbf6f6e5..590d227fde3 100644 --- a/opcodes/aarch64-opc.c +++ b/opcodes/aarch64-opc.c @@ -1438,7 +1438,7 @@ set_reg_list_error (aarch64_operand_error *mismatch_detail, int idx, if (mismatch_detail == NULL) return; set_error (mismatch_detail, AARCH64_OPDE_REG_LIST, idx, NULL); - mismatch_detail->data[0].i = expected_num; + mismatch_detail->data[0].i = 1 << expected_num; } static inline void