[libre-riscv-dev] [Bug 269] auto-conversion / parser of POWER ISA Spec v3.0B

bugzilla-daemon at libre-riscv.org bugzilla-daemon at libre-riscv.org
Fri Apr 3 20:11:26 BST 2020


--- Comment #9 from Luke Kenneth Casson Leighton <lkcl at lkcl.net> ---
(In reply to Michael Nolan from comment #8)
> (In reply to Luke Kenneth Casson Leighton from comment #7)
> > can you take a look, see what the code "actually" would need to
> > look like?  i'd like to keep it really clean and simple.
> What do you mean? I'm looking at the code in fixedarith.py and it looks
> pretty good...

i know, right! :)

ok so take a look at... mmm... where is it...  power_pseudo.py
and do this:

diff --git a/src/soc/decoder/power_pseudo.py b/src/soc/decoder/power_pseudo.py
index 86306b0..d05ca25 100644
--- a/src/soc/decoder/power_pseudo.py
+++ b/src/soc/decoder/power_pseudo.py
@@ -96,10 +96,10 @@ D <- d0||d1||d2

 #code = testreg
-#code = cnttzd
+code = cnttzd
 #code = cmpi
 #code = cmpeqb
-code = addpcis
+#code = addpcis
 #code = bpermd

 def tolist(num):

then that should modify register 17 to be an (incorrect *sigh*) value
except, arse, right now it doesn't work :)

oh i know why.  forgot to add __bool__.  sorted.  working now.

ok so, if you look at the bits that go round the "exec (code, d)",
you see that the registers are "pre-prepared" (pre-read) into
variables that are dropped into the dictionary (d).

this creates *local* variables (in d) named RA, RT, RB, RS, which can
end up being modified in the code-fragment.

following code-execution, the *modified* variables have to be "extracted"
for storage into the register file.  if they're in fact registers.

when *not* using exec() but instead writing out the code-fragments to
an actual file, we need some pre- and post- functions which are called
before and after each function, that do the exact same thing.

several ways to do that:

1) pass in a dictionary of variables that are
to be added to locals():


then *return* a copy of locals() from the function.

2) make everything class-based (yuk) self.RA, self.RT, blah blah.

this one i feel looks messy.

3) use exec() treating the code as a string

   however using exec() means that if you get a syntax error it's
   impossible to work out where the hell it was.  it's also really slow.

4) do everything as modules (!) yes really.  modules can be executed on-demand


   it then becomes possible to drop the global variables into the module
   and also "extract" them afterwards.  will need investigation.

   also might need an __main__submodule.  maybe.   have to test it.

5) other

You are receiving this mail because:
You are on the CC list for the bug.

More information about the libre-riscv-dev mailing list