From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by sourceware.org (Postfix) with ESMTPS id 0557F385702E for ; Thu, 23 Jun 2022 20:08:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0557F385702E Received: by mail-lj1-x234.google.com with SMTP id s14so434167ljs.3 for ; Thu, 23 Jun 2022 13:08:48 -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=hC/vmwWJ6Y5A72eg1qg7Uu2SdSEqBhjg+HhobtJK4yFNAfLJLJsvnLRZ/k8UAGKipH UBizvbHaMhisyiqou8sek8NvG7Ty+eHlIwc4YLX/LcrlsviJr0OJ+LfnE1P8RAPbsRTE bh+XBEDhVuKAeHoUS7sxnfF15cPX58MdvSYfSRID/mO6gHfpycoJYGzxZYsD54ApOtmQ elJWra0/jDn4PJt7Bh5oiic4YQUiOe5+TODKIzgdeld9/HEZThHwD5t3Qz/AWAn/Lc2l 2duy6zv7yrKipOnuFnF5y1KgMSG1BOtL8V/JDgNx887ktIlGxGINzVCrWmioRG5ML013 q+ig== X-Gm-Message-State: AJIora8NNCfQ/11gFe1MyAAD11JuT0hG8Jj5Ey4Hgjnz2TgPyOPH5vl8 VxGV5vMTcCAoNmVXVFUaoN+Wns3q5PE= X-Google-Smtp-Source: AGRyM1srR1TpbYFIXrley6LeTmPakLyugzgyZ8IMH8EVurf6EU0IOmZvE8rIAmv42fpEmyi5Z/0aRg== X-Received: by 2002:a05:651c:981:b0:253:b87e:ba6c with SMTP id b1-20020a05651c098100b00253b87eba6cmr5930070ljq.530.1656014927448; Thu, 23 Jun 2022 13:08:47 -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 d17-20020ac25ed1000000b0047f666011e4sm20483lfq.26.2022.06.23.13.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jun 2022 13:08:46 -0700 (PDT) Sender: Dmitry Selyutin From: Dmitry Selyutin To: binutils@sourceware.org Cc: Alan Modra , Luke Kenneth Casson Leighton , Dmitry Selyutin Subject: [PATCH v4 2/6] ppc: introduce non-zero operand flag Date: Thu, 23 Jun 2022 23:08:34 +0300 Message-Id: <20220623200838.1247734-3-ghostmansd@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623200838.1247734-1-ghostmansd@gmail.com> References: <20220623193734.1245650-1-ghostmansd@gmail.com> <20220623200838.1247734-1-ghostmansd@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.7 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: Thu, 23 Jun 2022 20:08:55 -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