From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by sourceware.org (Postfix) with ESMTPS id C650D385829F for ; Sun, 26 Jun 2022 19:00:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C650D385829F Received: by mail-lf1-x131.google.com with SMTP id c2so13195513lfk.0 for ; Sun, 26 Jun 2022 12:00:30 -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=9xmWKAbk1jZNuT0lRfRWJpWeqbN/W4p6rf9dHtJSRp4=; b=41YaCzTPtJgBYFGukFKezwqnhXuEDVILstRKLfwCznx+eECGmJRqAHpFGbfr8OmLAG gELA8G4yj7DBv9jMlhfawpahwPtTSw5NBA7z7WNOX3K/9jEe7LaYvup1R6vvd8LU69bf MODmL6vGkQOKlWwHiTd604ciDS2kr4F4Y2Yk5MWE1a5PqNM+8j9r8+v8pD4XsklHL3BP FpjEiGWKZKBnRPzrPnT5sFhNjpjnwnucaDp952GmVaTNgMekYtxkJ5dJQ505K94hIaRv nA1SKx2I3JIajbctDIV1ndfluABkp7g46IzXLSVm2S+1meXDcen4Bvqng33MoLkp789F wi7w== X-Gm-Message-State: AJIora/pMd0IG1p9P7XEUYsxXZGvKpOrXWLMPwZ/o6df1eNxPaEGaKxH 90Sd1Uo68sAgPTVn5qgL6m6aCa6Si8o= X-Google-Smtp-Source: AGRyM1sxHLQ7UewWM/ZTATvWlSkqH4xu0vODqNurVXTGz6J579CT9Ygg6bDemPntn0AlrTH5GNSG7w== X-Received: by 2002:a05:6512:1110:b0:47f:86fb:bd92 with SMTP id l16-20020a056512111000b0047f86fbbd92mr5918310lfg.333.1656270029160; Sun, 26 Jun 2022 12:00:29 -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 g1-20020a0565123b8100b0047255d21179sm1453952lfv.168.2022.06.26.12.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jun 2022 12:00:28 -0700 (PDT) Sender: Dmitry Selyutin From: Dmitry Selyutin To: binutils@sourceware.org Cc: Alan Modra , Luke Leighton , Jan Beulich , Nick Alcock , Richard Earnshaw , Andreas Schwab , Dmitry Selyutin Subject: [PATCH v5 2/7] ppc: introduce non-zero operand flag Date: Sun, 26 Jun 2022 22:00:00 +0300 Message-Id: <20220626190005.7727-3-ghostmansd@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220626190005.7727-1-ghostmansd@gmail.com> References: <20220623200838.1247734-1-ghostmansd@gmail.com> <20220626190005.7727-1-ghostmansd@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 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, 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: 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: Sun, 26 Jun 2022 19:00:32 -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 76bdfb2e35..c048721ed0 100644 --- a/gas/config/tc-ppc.c +++ b/gas/config/tc-ppc.c @@ -1643,10 +1643,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; @@ -1968,6 +1974,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++; @@ -2018,10 +2029,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.36.1