From patchwork Mon May 6 18:29:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 163447 Delivered-To: patch@linaro.org Received: by 2002:ac9:2a84:0:0:0:0:0 with SMTP id p4csp2849315oca; Mon, 6 May 2019 11:32:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPB2B5t5HJ8AFCb5wd4EJg5LhMH4UVkfj/BHfbHMluZIAABocciABPPqxQd+6dkasqqtG/ X-Received: by 2002:a7b:c743:: with SMTP id w3mr3690484wmk.22.1557167562737; Mon, 06 May 2019 11:32:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557167562; cv=none; d=google.com; s=arc-20160816; b=TC0KRrlQJNCMAZEhHAOfPT77TJbejwsJr7m6QaynAEymtIrVLTGtNDRK4aAoXIHh6m Ou/dIfu3ac4Izsot6EN4jujmU//GmpJR/sobwfrjmRtrSDSXHnGydT161nQ6knvgTPhx JuounbBNxBU9ob4Mqn0a4PeKyk7BNWOYxC9BjvP0FGeHTNB1eFGbjtIiqyHDmAf1kwkW 9ox6QJYt/mvXdHLCkzjwWlWR4IiB0wlfCdj1AajzBbXeQ6w2izwqXTOW0LsQ4Ck/rptr 31r5f21f27IIlGCZq7xymjo/Ey4TcPFwqQOWqsZ59WHCkcwd+2WoggOe2Tv+3RuXXZCu 20cQ== 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:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=tOB7k/2hv0qgDPmpyJIjmIejxWr898ct1NuzMnEJO5o=; b=wi2EKhil8Ty/89pJoBKBfrIfXszFQBFeaRjM5YqUK6KYSJioFcAZU+G9GwmQq/jKgz 0EVnckf8O3x4BVYNZ8A0afJNxWAey5oVfP+G6o1uJLAhQMRTbnR1RLNZTxwE+YnwlOQ0 BpqjyprqZiliUYbfFecfHSY6zkPsAMnRHXcSjDH4JtIHLpoBpXMM4R/ALTaMD+uMAe/B ecg5qRKh34mcBs3JhAEz5SFEmOuNeNjI4yvS2LiA85HMycJte9uxo2MAlAJqTwgqdEgs TNq2JLngt5SB8/9PBYjVAF8WLZxfK8wwWNi0mX/jcF5hMtLybjptZ/7RVAUAmt/w9use Bcdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=x+gDCQWr; 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 v4si7885826wrn.293.2019.05.06.11.32.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 06 May 2019 11:32:42 -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=x+gDCQWr; 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 ([127.0.0.1]:60637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNiPp-0000iP-K0 for patch@linaro.org; Mon, 06 May 2019 14:32:41 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hNiN1-0007Ds-MJ for qemu-devel@nongnu.org; Mon, 06 May 2019 14:29:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hNiN0-0000IE-Bp for qemu-devel@nongnu.org; Mon, 06 May 2019 14:29:47 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:41115) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hNiN0-0000HS-3X for qemu-devel@nongnu.org; Mon, 06 May 2019 14:29:46 -0400 Received: by mail-pl1-x629.google.com with SMTP id d9so6783276pls.8 for ; Mon, 06 May 2019 11:29: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; bh=tOB7k/2hv0qgDPmpyJIjmIejxWr898ct1NuzMnEJO5o=; b=x+gDCQWrb4dORd3sZG+iZE+WUrUZJGWBWhX3G2TBLHhQIlLjMK45xy54joOqsNVAhg 7TwVA4wWbI88Ys2rL+fS4SNPmyGoYrpcPZZ8OSXnR2YsdE1wecN2ui1CEP9gzXpiw3Oj 3el0ojP/U6nAFOXczberquzHpEqCRoqlJ7JN4jFYFE11vsOkxq8KY3Vown5Uiz6OrII2 pAoyeXt+jgROX6YEWSKoRNFdghasxJ3RngZ+06vSDAQ1hk5LHWLPQe+Edl5xYUzgZAlD ZYVkM8A2EQmyKqCqw6MzP7KPzJZPOsda2D4wP6iWuGBJEJsWqPi5hH/sLxG1P67XOBMW OE7A== 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; bh=tOB7k/2hv0qgDPmpyJIjmIejxWr898ct1NuzMnEJO5o=; b=Q6PFTXFc+5691ou4Sk0CtgX9ES1gWl2yBAaQ6y91KPXURbqHnrnnSp9pQDuRHbb0kp rq4jEyAZpHWrO4ugyY9i8dTNyXGC/rutOMUXj5GDO1RW3NGkMW7/CWzAoG6wTbmpmYMc bo77w9aMFK2gb52m8p9HBgx6T3E4stUezQ/QNlH/Unfn5pcgdda4E3acTrpd6ppWpi8l RxBnjPybMI2elFDaawpdSwY/BmhPoPm6bsnx/ZHtT+vT+6RbhUJPJaU+oi7LSfn5qg8h tasVaDN146CASqEbA4/tifTAcukmXMNykaA+rQ9/bJvomkhilYwxLqk3hD55TtDvOktw ibbw== X-Gm-Message-State: APjAAAWCQoC5Yb8T31zwjzyYmlMAnT+8dNwIOVC0NUA222qs8TXA9WCT eFriABNRlAB3dw2HzRcqDkRNj7W3psw= X-Received: by 2002:a17:902:e183:: with SMTP id cd3mr34356435plb.233.1557167384669; Mon, 06 May 2019 11:29:44 -0700 (PDT) Received: from localhost.localdomain (97-113-189-189.tukw.qwest.net. [97.113.189.189]) by smtp.gmail.com with ESMTPSA id j32sm12909924pgi.73.2019.05.06.11.29.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 May 2019 11:29:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Mon, 6 May 2019 11:29:38 -0700 Message-Id: <20190506182940.2200-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190506182940.2200-1-richard.henderson@linaro.org> References: <20190506182940.2200-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::629 Subject: [Qemu-devel] [PULL 1/3] decodetree: Initial support for variable-length ISAs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Assuming that the ISA clearly describes how to determine the length of the instruction, and the ISA has a reasonable maximum instruction length, the input to the decoder can be right-justified in an appropriate insn word. This is not 100% convenient, as out-of-line %fields are numbered relative to the maximum instruction length, but this appears to still be usable. Signed-off-by: Richard Henderson --- scripts/decodetree.py | 49 ++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 12 deletions(-) -- 2.17.1 diff --git a/scripts/decodetree.py b/scripts/decodetree.py index aa790b596a..555a46522b 100755 --- a/scripts/decodetree.py +++ b/scripts/decodetree.py @@ -27,6 +27,7 @@ import getopt insnwidth = 32 insnmask = 0xffffffff +variablewidth = False fields = {} arguments = {} formats = {} @@ -289,7 +290,7 @@ class Arguments: class General: """Common code between instruction formats and instruction patterns""" - def __init__(self, name, lineno, base, fixb, fixm, udfm, fldm, flds): + def __init__(self, name, lineno, base, fixb, fixm, udfm, fldm, flds, w): self.name = name self.file = input_file self.lineno = lineno @@ -299,6 +300,7 @@ class General: self.undefmask = udfm self.fieldmask = fldm self.fields = flds + self.width = w def __str__(self): return self.name + ' ' + str_match_bits(self.fixedbits, self.fixedmask) @@ -352,7 +354,7 @@ class Pattern(General): class MultiPattern(General): """Class representing an overlapping set of instruction patterns""" - def __init__(self, lineno, pats, fixb, fixm, udfm): + def __init__(self, lineno, pats, fixb, fixm, udfm, w): self.file = input_file self.lineno = lineno self.pats = pats @@ -360,6 +362,7 @@ class MultiPattern(General): self.fixedbits = fixb self.fixedmask = fixm self.undefmask = udfm + self.width = w def __str__(self): r = "{" @@ -502,7 +505,7 @@ def infer_argument_set(flds): return arg -def infer_format(arg, fieldmask, flds): +def infer_format(arg, fieldmask, flds, width): global arguments global formats global decode_function @@ -521,6 +524,8 @@ def infer_format(arg, fieldmask, flds): continue if fieldmask != fmt.fieldmask: continue + if width != fmt.width: + continue if not eq_fields_for_fmts(flds, fmt.fields): continue return (fmt, const_flds) @@ -529,7 +534,7 @@ def infer_format(arg, fieldmask, flds): if not arg: arg = infer_argument_set(flds) - fmt = Format(name, 0, arg, 0, 0, 0, fieldmask, var_flds) + fmt = Format(name, 0, arg, 0, 0, 0, fieldmask, var_flds, width) formats[name] = fmt return (fmt, const_flds) @@ -546,6 +551,7 @@ def parse_generic(lineno, is_format, name, toks): global re_ident global insnwidth global insnmask + global variablewidth fixedmask = 0 fixedbits = 0 @@ -633,8 +639,15 @@ def parse_generic(lineno, is_format, name, toks): error(lineno, 'invalid token "{0}"'.format(t)) width += shift + if variablewidth and width < insnwidth and width % 8 == 0: + shift = insnwidth - width + fixedbits <<= shift + fixedmask <<= shift + undefmask <<= shift + undefmask |= (1 << shift) - 1 + # We should have filled in all of the bits of the instruction. - if not (is_format and width == 0) and width != insnwidth: + elif not (is_format and width == 0) and width != insnwidth: error(lineno, 'definition has {0} bits'.format(width)) # Do not check for fields overlaping fields; one valid usage @@ -660,7 +673,7 @@ def parse_generic(lineno, is_format, name, toks): if name in formats: error(lineno, 'duplicate format name', name) fmt = Format(name, lineno, arg, fixedbits, fixedmask, - undefmask, fieldmask, flds) + undefmask, fieldmask, flds, width) formats[name] = fmt else: # Patterns can reference a format ... @@ -670,12 +683,14 @@ def parse_generic(lineno, is_format, name, toks): error(lineno, 'pattern specifies both format and argument set') if fixedmask & fmt.fixedmask: error(lineno, 'pattern fixed bits overlap format fixed bits') + if width != fmt.width: + error(lineno, 'pattern uses format of different width') fieldmask |= fmt.fieldmask fixedbits |= fmt.fixedbits fixedmask |= fmt.fixedmask undefmask |= fmt.undefmask else: - (fmt, flds) = infer_format(arg, fieldmask, flds) + (fmt, flds) = infer_format(arg, fieldmask, flds, width) arg = fmt.base for f in flds.keys(): if f not in arg.fields: @@ -687,7 +702,7 @@ def parse_generic(lineno, is_format, name, toks): if f not in flds.keys() and f not in fmt.fields.keys(): error(lineno, 'field {0} not initialized'.format(f)) pat = Pattern(name, lineno, fmt, fixedbits, fixedmask, - undefmask, fieldmask, flds) + undefmask, fieldmask, flds, width) patterns.append(pat) allpatterns.append(pat) @@ -727,6 +742,13 @@ def build_multi_pattern(lineno, pats): if p.lineno < lineno: lineno = p.lineno + width = None + for p in pats: + if width is None: + width = p.width + elif width != p.width: + error(lineno, 'width mismatch in patterns within braces') + repeat = True while repeat: if fixedmask == 0: @@ -742,7 +764,7 @@ def build_multi_pattern(lineno, pats): else: repeat = False - mp = MultiPattern(lineno, pats, fixedbits, fixedmask, undefmask) + mp = MultiPattern(lineno, pats, fixedbits, fixedmask, undefmask, width) patterns.append(mp) # end build_multi_pattern @@ -979,13 +1001,14 @@ def main(): global insntype global insnmask global decode_function + global variablewidth decode_scope = 'static ' long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=', - 'static-decode='] + 'static-decode=', 'varinsnwidth='] try: - (opts, args) = getopt.getopt(sys.argv[1:], 'o:w:', long_opts) + (opts, args) = getopt.getopt(sys.argv[1:], 'o:vw:', long_opts) except getopt.GetoptError as err: error(0, err) for o, a in opts: @@ -999,7 +1022,9 @@ def main(): elif o == '--translate': translate_prefix = a translate_scope = '' - elif o in ('-w', '--insnwidth'): + elif o in ('-w', '--insnwidth', '--varinsnwidth'): + if o == '--varinsnwidth': + variablewidth = True insnwidth = int(a) if insnwidth == 16: insntype = 'uint16_t'