From 779dddfb8565de82eda4053b9aaf685438db6c6b Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Wed, 6 May 2020 14:19:06 -0400 Subject: [PATCH] Add helper functions to replace direct comparison in generated code --- src/soc/decoder/helpers.py | 16 ++++++++++++++++ src/soc/decoder/isa/branch.patch | 11 ----------- src/soc/decoder/isa/sprset.patch | 15 ++++++++++----- src/soc/decoder/pseudo/parser.py | 12 ++++++------ src/soc/decoder/pseudo/pywriter.py | 3 ++- src/soc/decoder/selectable_int.py | 2 ++ 6 files changed, 36 insertions(+), 23 deletions(-) delete mode 100644 src/soc/decoder/isa/branch.patch diff --git a/src/soc/decoder/helpers.py b/src/soc/decoder/helpers.py index 65db26dd..ba3ca0a1 100644 --- a/src/soc/decoder/helpers.py +++ b/src/soc/decoder/helpers.py @@ -54,7 +54,23 @@ def MASK(x, y): mask_b = (~((1 << y) - 1)) & ((1 << 64) - 1) return mask_a ^ mask_b +def ne(a, b): + return SelectableInt((a != b), bits=1) +def eq(a, b): + return SelectableInt((a == b), bits=1) + +def gt(a, b): + return SelectableInt((a > b), bits=1) + +def ge(a, b): + return SelectableInt((a >= b), bits=1) + +def lt(a, b): + return SelectableInt((a < b), bits=1) + +def le(a, b): + return SelectableInt((a <= b), bits=1) # For these tests I tried to find power instructions that would let me # isolate each of these helper operations. So for instance, when I was # testing the MASK() function, I chose rlwinm and rldicl because if I diff --git a/src/soc/decoder/isa/branch.patch b/src/soc/decoder/isa/branch.patch deleted file mode 100644 index ac79f515..00000000 --- a/src/soc/decoder/isa/branch.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- branch.py.orig 2020-05-06 10:27:17.096835546 -0400 -+++ branch.py 2020-05-06 10:27:40.353752508 -0400 -@@ -141,7 +141,7 @@ - M = 32 - if ~BO[2]: - CTR = CTR - 1 -- ctr_ok = BO[2] | (CTR[M:64] != 0) ^ BO[3] -+ ctr_ok = BO[2] | SelectableInt((CTR[M:64] != 0), bits=1) ^ BO[3] - cond_ok = BO[0] | ~(CR[BI + 32] ^ BO[1]) - if ctr_ok & cond_ok: - NIA = concat(LR[0:62], SelectableInt(value=0x0, bits=2)) diff --git a/src/soc/decoder/isa/sprset.patch b/src/soc/decoder/isa/sprset.patch index dcdaf55e..adae5b1b 100644 --- a/src/soc/decoder/isa/sprset.patch +++ b/src/soc/decoder/isa/sprset.patch @@ -1,11 +1,16 @@ ---- sprset.py.orig 2020-05-06 11:36:45.228253359 -0400 -+++ sprset.py 2020-05-06 11:20:17.627640518 -0400 -@@ -18,7 +18,7 @@ +--- sprset.py.orig 2020-05-06 14:15:08.236887767 -0400 ++++ sprset.py 2020-05-06 14:15:51.757083567 -0400 +@@ -15,11 +15,11 @@ + if n in [13]: + see(Book_III_p974) + elif n in [808, 809, 810, 811]: +- if eq(length(SPR(n)), 64): ++ if eq(len(SPR(n)), 64): SPR[n] = RS else: SPR[n] = RS[32:64] -- elif length(SPR(n)) == 64: -+ elif len(SPR(n)) == 64: +- elif eq(length(SPR(n)), 64): ++ elif eq(len(SPR(n)), 64): SPR[n] = RS else: SPR[n] = RS[32:64] diff --git a/src/soc/decoder/pseudo/parser.py b/src/soc/decoder/pseudo/parser.py index b5803d88..b05b9760 100644 --- a/src/soc/decoder/pseudo/parser.py +++ b/src/soc/decoder/pseudo/parser.py @@ -83,32 +83,32 @@ def Assign(left, right, iea_mode): def make_le_compare(arg): (left, right) = arg - return ast.Compare(left, [ast.LtE()], [right]) + return ast.Call(ast.Name("le", ast.Load()), (left, right), []) def make_ge_compare(arg): (left, right) = arg - return ast.Compare(left, [ast.GtE()], [right]) + return ast.Call(ast.Name("ge", ast.Load()), (left, right), []) def make_lt_compare(arg): (left, right) = arg - return ast.Compare(left, [ast.Lt()], [right]) + return ast.Call(ast.Name("lt", ast.Load()), (left, right), []) def make_gt_compare(arg): (left, right) = arg - return ast.Compare(left, [ast.Gt()], [right]) + return ast.Call(ast.Name("gt", ast.Load()), (left, right), []) def make_eq_compare(arg): (left, right) = arg - return ast.Compare(left, [ast.Eq()], [right]) + return ast.Call(ast.Name("eq", ast.Load()), (left, right), []) def make_ne_compare(arg): (left, right) = arg - return ast.Compare(left, [ast.NotEq()], [right]) + return ast.Call(ast.Name("ne", ast.Load()), (left, right), []) binary_ops = { diff --git a/src/soc/decoder/pseudo/pywriter.py b/src/soc/decoder/pseudo/pywriter.py index 3cb6bef1..e7f2b344 100644 --- a/src/soc/decoder/pseudo/pywriter.py +++ b/src/soc/decoder/pseudo/pywriter.py @@ -19,7 +19,8 @@ header = """\ # auto-generated by pywriter.py, do not edit or commit from soc.decoder.isa.caller import inject, instruction_info -from soc.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32, MASK,) +from soc.decoder.helpers import (EXTS, EXTS64, EXTZ64, ROTL64, ROTL32, MASK, + ne, eq, gt, ge, lt, le) from soc.decoder.selectable_int import SelectableInt from soc.decoder.selectable_int import selectconcat as concat from soc.decoder.orderedset import OrderedSet diff --git a/src/soc/decoder/selectable_int.py b/src/soc/decoder/selectable_int.py index a052beb4..33cbb74e 100644 --- a/src/soc/decoder/selectable_int.py +++ b/src/soc/decoder/selectable_int.py @@ -7,6 +7,8 @@ from operator import (add, sub, mul, truediv, mod, or_, and_, xor, neg, inv) def check_extsign(a, b): if isinstance(b, FieldSelectableInt): b = b.get_range() + if isinstance(b, int): + return SelectableInt(b, a.bits) if b.bits != 256: return b return SelectableInt(b.value, a.bits) -- 2.30.2