From patchwork Fri Apr 30 01:15:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 429722 Delivered-To: patch@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp2102279jao; Thu, 29 Apr 2021 18:16:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzxxocuYrEixw9+JUrkJm5caEmGAcMXVKzCrwc+p2wib6fgor4wEvnulix+WVnoNK/4bY5M X-Received: by 2002:a92:d38e:: with SMTP id o14mr2149764ilo.160.1619745415046; Thu, 29 Apr 2021 18:16:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619745415; cv=none; d=google.com; s=arc-20160816; b=uYCN2NYIZLUoDMl/H6o9HCchDbGW1/u9JKJrlRS+M78DxMH60pra9UqOLRLIXWJ32S oyGSQdHEEbJnvYX6mkEgqoKL3tA8BQ28nuqlyxKLIZvD/ag8rbP8QwaPfvMbbFlUbhSN J5Okt3ah8dY74OM4uwQajyPfiFg6vefsoZRgPdWDbvsmu063VGGG7Z1qg3cSJtxf9NNN ne8Jdn5Uk2u8GP9n7eDoyiKC8vnZNtnpsZTuFM+iQyY7wySFLzBr9PcPnyedDlvTJNfm Fk+sOSre18GnfmZMy+Iu2JcsjUA1noLM3VAcFDAKHt3OobyOIU6YjVazlqQqNKcpkN43 Lirw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=lUjIcZ7tDPA2pVLJ4XGtPvwfZ6yYWNyletjpFzr8LcY=; b=REf1TIgbKUvG9qooadNsdembo0EpAm4ukbW/E6dwO59YqnusAHDhYQX2gLDJl0FnuL DiCn7VKdFmHBJpCO+2QjnzrmM0ZhXblzw/h/oGD5omjqJTvi+r64Mw7PUTbJ6Y/JkC7p i05Sg/bJTcOiVAOIXpH0Xw7d6lXrJzE1uzFAXx9Obt0ggZk/ZuHu4rRXKq66CIJOQ0/0 1pIMCYn7GPage4ZFqiWebynStcCsO0LpgQNqt/vcZ1LnPH8xacofI+BSJgz0VGDXz/+9 7O/iKU5uXYJKhew9A+cwPS3T5pEfvPsOncGGyxhLQ6JHnB3ByzXQgWmkL1vkRpbJsdXa LjXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bHd7WOgF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i1si518350jaj.87.2021.04.29.18.16.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Apr 2021 18:16:55 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bHd7WOgF; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lcHm2-0003Lr-F0 for patch@linaro.org; Thu, 29 Apr 2021 21:16:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lcHlB-0002kL-FL for qemu-devel@nongnu.org; Thu, 29 Apr 2021 21:16:01 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:36472) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lcHky-0007TD-20 for qemu-devel@nongnu.org; Thu, 29 Apr 2021 21:16:01 -0400 Received: by mail-pg1-x532.google.com with SMTP id j7so38953057pgi.3 for ; Thu, 29 Apr 2021 18:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lUjIcZ7tDPA2pVLJ4XGtPvwfZ6yYWNyletjpFzr8LcY=; b=bHd7WOgF8e3a/qYhevor+lNwrYd6d4mRLm+nj7jY8y68/zbWVnp6l6KDbUCB0H/865 jZscwS+vO6PnDIsQiv0jBtpPF6QSlB30cJq/sQ4HQdFYy+fRpJwK342D4hfse5MgNQrZ nSpyGuhcWB2Js6UjqnQ3oTyx3WaonhVYczxh2hrnv4tf7sAlNxahYVmvzbH9UUBZK2BR CdAutvYQwPi/Qy2fuYC4Qjy/8t+C5UeocmmMkolN3m1icz1Lq4QyyYofE7zx9uL+Qf2W O2HQmDHYVsU2B3O/kevAfR0X75vkVqm0CmlHo1mPpDqJUOLCfLHinCgr6E5ZYBg1XLvT S1fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lUjIcZ7tDPA2pVLJ4XGtPvwfZ6yYWNyletjpFzr8LcY=; b=SGShHWVabup2/iFckDxILte//ZeEgbw/TzVjfPpYc2tSKnTe75tfEsRAdRaLeG+1I+ G3aQycMlzISAbfdpt67LDMJOuBP7IwJryMee1e3EvNz5MfIzurxlTsfUWqD+QumEdECO +5KYlPR8qAUJP3/8O/tetzKTLSd2SNocS5NV2EAweGlhJcgvblJYUyblI6R/1ECAbB4Y fwh+2bUL6VSjjLIBYzdNEIwJNwOiVjCyomI3zXf/WwmZwc36yJ0mHxYjuDHrxW+aENz+ 0cm1207SKF0HYRGgYWG5KROup1YM+uxmiYdqiqxKkVAZEYBJ0yK6yEW6US4FvXbSY3O2 KIKQ== X-Gm-Message-State: AOAM533FeshQIgOpLVcCGFK/Q12ME0jOTYkbDRR+mPQj5JFzOyonYhQN NeqGnR7huwIr1qZGMnylFaI4Y0aUSKUM2g== X-Received: by 2002:a62:dd50:0:b029:27a:69c8:55b6 with SMTP id w77-20020a62dd500000b029027a69c855b6mr2451954pff.6.1619745345439; Thu, 29 Apr 2021 18:15:45 -0700 (PDT) Received: from localhost.localdomain ([71.212.144.24]) by smtp.gmail.com with ESMTPSA id 1sm161277pjx.46.2021.04.29.18.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Apr 2021 18:15:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v3 01/30] decodetree: Introduce whex and whexC helpers Date: Thu, 29 Apr 2021 18:15:14 -0700 Message-Id: <20210430011543.1017113-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210430011543.1017113-1-richard.henderson@linaro.org> References: <20210430011543.1017113-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: f4bug@amsat.org, luis.pires@eldorado.org.br, qemu-ppc@nongnu.org, lagarcia@br.ibm.com, bruno.larsen@eldorado.org.br, matheus.ferst@eldorado.org.br, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Form a hex constant of the appropriate insnwidth. Begin using f-strings on changed lines. Signed-off-by: Richard Henderson --- scripts/decodetree.py | 66 +++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 28 deletions(-) -- 2.25.1 Reviewed-by: Luis Pires Reviewed-by: Philippe Mathieu-Daudé diff --git a/scripts/decodetree.py b/scripts/decodetree.py index 4637b633e7..0861e5d503 100644 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -102,6 +102,21 @@ def str_fields(fields): return r[1:] +def whex(val): + """Return a hex string for val padded for insnwidth""" + global insnwidth + return f'0x{val:0{insnwidth // 4}x}' + + +def whexC(val): + """Return a hex string for val padded for insnwidth, + and with the proper suffix for a C constant.""" + suffix = '' + if val >= 0x80000000: + suffix = 'u' + return whex(val) + suffix + + def str_match_bits(bits, mask): """Return a string pretty-printing BITS/MASK""" global insnwidth @@ -477,11 +492,8 @@ def output_code(self, i, extracted, outerbits, outermask): if outermask != p.fixedmask: innermask = p.fixedmask & ~outermask innerbits = p.fixedbits & ~outermask - output(ind, 'if ((insn & ', - '0x{0:08x}) == 0x{1:08x}'.format(innermask, innerbits), - ') {\n') - output(ind, ' /* ', - str_match_bits(p.fixedbits, p.fixedmask), ' */\n') + output(ind, f'if ((insn & {whexC(innermask)}) == {whexC(innerbits)}) {{\n') + output(ind, f' /* {str_match_bits(p.fixedbits, p.fixedmask)} */\n') p.output_code(i + 4, extracted, p.fixedbits, p.fixedmask) output(ind, '}\n') else: @@ -500,12 +512,12 @@ def __init__(self, fm, tm): def str1(self, i): ind = str_indent(i) - r = '{0}{1:08x}'.format(ind, self.fixedmask) + r = ind + whex(self.fixedmask) if self.format: r += ' ' + self.format.name r += ' [\n' for (b, s) in self.subs: - r += '{0} {1:08x}:\n'.format(ind, b) + r += ind + f' {whex(b)}:\n' r += s.str1(i + 4) + '\n' r += ind + ']' return r @@ -529,16 +541,16 @@ def output_code(self, i, extracted, outerbits, outermask): if sh > 0: # Propagate SH down into the local functions. def str_switch(b, sh=sh): - return '(insn >> {0}) & 0x{1:x}'.format(sh, b >> sh) + return f'(insn >> {sh}) & {b >> sh:#x}' def str_case(b, sh=sh): - return '0x{0:x}'.format(b >> sh) + return hex(b >> sh) else: def str_switch(b): - return 'insn & 0x{0:08x}'.format(b) + return f'insn & {whexC(b)}' def str_case(b): - return '0x{0:08x}'.format(b) + return whexC(b) output(ind, 'switch (', str_switch(self.thismask), ') {\n') for b, s in sorted(self.subs): @@ -962,19 +974,19 @@ def parse_generic(lineno, parent_pat, name, toks): # Validate the masks that we have assembled. if fieldmask & fixedmask: - error(lineno, 'fieldmask overlaps fixedmask (0x{0:08x} & 0x{1:08x})' - .format(fieldmask, fixedmask)) + error(lineno, 'fieldmask overlaps fixedmask ', + f'({whex(fieldmask)} & {whex(fixedmask)})') if fieldmask & undefmask: - error(lineno, 'fieldmask overlaps undefmask (0x{0:08x} & 0x{1:08x})' - .format(fieldmask, undefmask)) + error(lineno, 'fieldmask overlaps undefmask ', + f'({whex(fieldmask)} & {whex(undefmask)})') if fixedmask & undefmask: - error(lineno, 'fixedmask overlaps undefmask (0x{0:08x} & 0x{1:08x})' - .format(fixedmask, undefmask)) + error(lineno, 'fixedmask overlaps undefmask ', + f'({whex(fixedmask)} & {whex(undefmask)})') if not is_format: allbits = fieldmask | fixedmask | undefmask if allbits != insnmask: - error(lineno, 'bits left unspecified (0x{0:08x})' - .format(allbits ^ insnmask)) + error(lineno, 'bits left unspecified ', + f'({whex(allbits ^ insnmask)})') # end parse_general @@ -1104,10 +1116,9 @@ def __init__(self, m, w): def str1(self, i): ind = str_indent(i) - r = '{0}{1:08x}'.format(ind, self.mask) - r += ' [\n' + r = ind + whex(self.mask) + ' [\n' for (b, s) in self.subs: - r += '{0} {1:08x}:\n'.format(ind, b) + r += ind + f' {whex(b)}:\n' r += s.str1(i + 4) + '\n' r += ind + ']' return r @@ -1131,16 +1142,16 @@ def output_code(self, i, extracted, outerbits, outermask): if sh > 0: # Propagate SH down into the local functions. def str_switch(b, sh=sh): - return '(insn >> {0}) & 0x{1:x}'.format(sh, b >> sh) + return f'(insn >> {sh}) & {b >> sh:#x}' def str_case(b, sh=sh): - return '0x{0:x}'.format(b >> sh) + return hex(b >> sh) else: def str_switch(b): - return 'insn & 0x{0:08x}'.format(b) + return f'insn & {whexC(b)}' def str_case(b): - return '0x{0:08x}'.format(b) + return whexC(b) output(ind, 'switch (', str_switch(self.mask), ') {\n') for b, s in sorted(self.subs): @@ -1162,8 +1173,7 @@ def __init__(self, m, w): self.width = w def str1(self, i): - ind = str_indent(i) - return '{0}{1:08x}'.format(ind, self.mask) + return str_indent(i) + whex(self.mask) def __str__(self): return self.str1(0)