From 18324851394c871f344f19de013577f5931fa3ae Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sat, 4 Apr 2020 13:44:04 +0100 Subject: [PATCH] identify [0]*16 pattern and produce repeat-of-int --- libreriscv | 2 +- src/soc/decoder/power_pseudo.py | 8 +++++++- src/soc/decoder/pseudo/parser.py | 19 +++++++++++++++++++ src/soc/decoder/selectable_int.py | 10 +++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/libreriscv b/libreriscv index 6c7c3167..36ca9489 160000 --- a/libreriscv +++ b/libreriscv @@ -1 +1 @@ -Subproject commit 6c7c31673fad55da82c22fbbcac3f9b5c49e6cc7 +Subproject commit 36ca948926f4c13b6e121948606a4d1aed8394f6 diff --git a/src/soc/decoder/power_pseudo.py b/src/soc/decoder/power_pseudo.py index cab7321f..d66d3f2b 100644 --- a/src/soc/decoder/power_pseudo.py +++ b/src/soc/decoder/power_pseudo.py @@ -96,8 +96,14 @@ addpcis = """ D <- d0||d1||d2 """ +testmul = """ +x <- [0] * 16 +RT <- (RA) + EXTS(SI || [0]*16) +""" + +code = testmul #code = testreg -code = cnttzd +#code = cnttzd #code = cmpi #code = cmpeqb #code = addpcis diff --git a/src/soc/decoder/pseudo/parser.py b/src/soc/decoder/pseudo/parser.py index 6c7ea8f6..6c67265b 100644 --- a/src/soc/decoder/pseudo/parser.py +++ b/src/soc/decoder/pseudo/parser.py @@ -133,9 +133,24 @@ def check_concat(node): # checks if the comparison is already a concat print("func", node.func.id) if node.func.id != 'concat': return [node] + if node.keywords: # a repeated list-constant, don't optimise + return [node] return node.args +# identify SelectableInt pattern +def identify_sint_mul_pattern(p): + if not isinstance(p[3], ast.Constant): + return False + if not isinstance(p[1], ast.List): + return False + l = p[1].elts + if len(l) != 1: + return False + elt = l[0] + return isinstance(elt, ast.Constant) + + ########## Parser (tokens -> AST) ###### # also part of Ply @@ -401,6 +416,10 @@ class PowerParser: p[0] = ast.Call(ast.Name("concat"), l, []) elif p[2] in ['<', '>', '=', '<=', '>=']: p[0] = binary_ops[p[2]]((p[1], p[3])) + elif identify_sint_mul_pattern(p): + keywords=[ast.keyword(arg='repeat', value=p[3])] + l = p[1].elts + p[0] = ast.Call(ast.Name("concat"), l, keywords) else: p[0] = ast.BinOp(p[1], binary_ops[p[2]], p[3]) elif len(p) == 3: diff --git a/src/soc/decoder/selectable_int.py b/src/soc/decoder/selectable_int.py index 8b5715bb..b8998b89 100644 --- a/src/soc/decoder/selectable_int.py +++ b/src/soc/decoder/selectable_int.py @@ -179,12 +179,20 @@ def selectassign(lhs, idx, rhs): lhs[t] = rhs[f] -def selectconcat(*args): +def selectconcat(*args, repeat=1): + if repeat != 1 and len(args) == 1 and isinstance(args[0], int): + args = [SelectableInt(args[0], 1)] + if repeat != 1: # multiplies the incoming arguments + tmp = [] + for i in range(repeat): + tmp += args + args = tmp res = copy(args[0]) for i in args[1:]: assert isinstance(i, SelectableInt), "can only concat SIs, sorry" res.bits += i.bits res.value = (res.value << i.bits) | i.value + print ("concat", repeat, res) return res -- 2.30.2