From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id B58D63875A22 for ; Mon, 25 Jul 2022 13:10:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B58D63875A22 Received: by mail-lf1-x12b.google.com with SMTP id d17so15865889lfa.12 for ; Mon, 25 Jul 2022 06:10:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jJ0CdgFQTdM+EaUVuotn5IKVN1zRH0VdBU0UMSEPJDA=; b=za6zfr1RMeqyKFdzqlsNy8E02dP8/3MYU39xJJGkifnUpudZtbscROfDxj6F58rBdd 3eCfhxlrIokqXrHtUZdsZG400OBEsBP+RAXKIPHNF09CWD71hMrzzQ6fsPB+mwQg3ruF jDse9RzNxLij+Dg8wIvx2nmVEXVT6+lCvWdjSTr/4C9GlLFVLNJydMIiEbnSoRRo5pNd 4V/FNk2Mn1Zp9dkfKc+FCF5jHibdbFdehkbYN/bKxZlPOZualNhCFls5it5IRTofytQ6 kgBqSe4ZzYgFNWs8AFMY1h4VEOoAr93jMTZbH3O4kOi9fPlBoPN2VUd4oPevAipL9ZRo H+DQ== X-Gm-Message-State: AJIora9qovSAbN+2Do98exWkxdK7GS4P1gpCuZw+StVOrZQIo/jxkcdz HFng5FmIa3MKGVHsFJcO0ehUeNTnfhM= X-Google-Smtp-Source: AGRyM1vXYOv+HmRE99VPkhGsEQgfiMKlFgaty/7EqGpFmoQkIPYEWphCy9+x15yCngUKCNWXQh5Qdw== X-Received: by 2002:a05:6512:1102:b0:48a:8f11:f094 with SMTP id l2-20020a056512110200b0048a8f11f094mr1853397lfg.648.1658754651146; Mon, 25 Jul 2022 06:10:51 -0700 (PDT) Received: from localhost.localdomain (broadband-188-32-220-156.ip.moscow.rt.ru. [188.32.220.156]) by smtp.gmail.com with ESMTPSA id q10-20020a19f20a000000b00489dd78bdacsm2664565lfh.299.2022.07.25.06.10.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 06:10:50 -0700 (PDT) Sender: Dmitry Selyutin From: Dmitry Selyutin To: binutils@sourceware.org Cc: Alan Modra , Luke Kenneth Casson Leighton , Dmitry Selyutin Subject: [PATCH v6 2/7] ppc: introduce non-zero operand flag Date: Mon, 25 Jul 2022 16:10:15 +0300 Message-Id: <20220725131020.128550-3-ghostmansd@gmail.com> X-Mailer: git-send-email 2.37.0 In-Reply-To: <20220725131020.128550-1-ghostmansd@gmail.com> References: <20220626190005.7727-1-ghostmansd@gmail.com> <20220725131020.128550-1-ghostmansd@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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-List-Received-Date: Mon, 25 Jul 2022 13:10:54 -0000 svstep and svshape instructions subtract 1 before encoding some of the operands. Obviously zero is not supported for these operands. Whilst PPC_OPERAND_PLUS1 fits perfectly to mark that maximal value should be incremented, there is no flag which marks the fact that zero values are not allowed. This patch adds a new flag, PPC_OPERAND_NONZERO, for this purpose. --- gas/config/tc-ppc.c | 22 +++++++++++++++++++--- include/opcode/ppc.h | 7 +++++++ opcodes/ppc-dis.c | 3 +++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/gas/config/tc-ppc.c b/gas/config/tc-ppc.c index ffc99857e3..7bd2fe785d 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -1656,10 +1656,16 @@ ppc_setup_opcodes (void) all the 1's in the mask are contiguous. */ for (i = 0; i < num_powerpc_operands; ++i) { + uint64_t mask = powerpc_operands[i].bitm; + unsigned long flags = powerpc_operands[i].flags; uint64_t right_bit; unsigned int j; + if ((flags & (PPC_OPERAND_PLUS1 | PPC_OPERAND_NONZERO)) == + (PPC_OPERAND_PLUS1 | PPC_OPERAND_NONZERO)) + as_bad ("mutually exclusive operand flags"); + right_bit = mask & -mask; mask += right_bit; right_bit = mask & -mask; @@ -1992,6 +1998,11 @@ ppc_insert_operand (uint64_t insn, max = (max >> 1) & -right; min = ~max & -right; } + else if ((operand->flags & PPC_OPERAND_NONZERO) != 0) + { + ++min; + ++max; + } if ((operand->flags & PPC_OPERAND_PLUS1) != 0) max++; @@ -2042,10 +2053,15 @@ ppc_insert_operand (uint64_t insn, if (errmsg != (const char *) NULL) as_bad_where (file, line, "%s", errmsg); } - else if (operand->shift >= 0) - insn |= (val & operand->bitm) << operand->shift; else - insn |= (val & operand->bitm) >> -operand->shift; + { + if ((operand->flags & PPC_OPERAND_NONZERO) != 0) + --val; + if (operand->shift >= 0) + insn |= (val & operand->bitm) << operand->shift; + else + insn |= (val & operand->bitm) >> -operand->shift; + } return insn; } diff --git a/include/opcode/ppc.h b/include/opcode/ppc.h index d5752a42e6..df06671db4 100644 --- a/include/opcode/ppc.h +++ b/include/opcode/ppc.h @@ -463,6 +463,13 @@ extern const unsigned int num_powerpc_operands; #define PPC_OPERAND_FCR (0x1000000) #define PPC_OPERAND_UDI (0x2000000) +/* + * Valid range of operand is 1..n rather than 0..n-1. + * Before encoding, the operand value is decremented. + * After decoding. the operand value is incremented. + */ +#define PPC_OPERAND_NONZERO 0x4000000 + extern ppc_cpu_t ppc_parse_cpu (ppc_cpu_t, ppc_cpu_t *, const char *); static inline int64_t diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c index f61e6518f1..d5b23c8a75 100644 --- a/opcodes/ppc-dis.c +++ b/opcodes/ppc-dis.c @@ -545,6 +545,9 @@ operand_value_powerpc (const struct powerpc_operand *operand, } } + if ((operand->flags & PPC_OPERAND_NONZERO) != 0) + ++value; + return value; } -- 2.37.0