Tuesday, 2021-07-13

programmerjakeThey appear to have requireMatrixJoined set to true for #libera, which causes tge bridge to perpetually stop relaying messages since the irc/matrix user lists are perpetually out of sync due to the sheer volume of users leaving/joining01:17
* lkcl waves to sasi8985 13:18
lkclsasi8985: apologies earlier for recommending that you pursue RISC-V. i explained to jacob that you're here because of Ganesan's IBM Power ISA Programme13:20
lkclwhilst technically correct that RISC-V is "easier", well... here is some reading material:13:20
lkclhttps://news.ycombinator.com/item?id=2445931413:20
sasi8985No problem i want know development the flow from rtl to os...so i thought i will be starting with simple things13:21
sasi8985since microwatt is in vhdl 2008 some fatures are not supported in vivado....so i am thinking to write rtl for power isa to sharpen my skills13:23
sasi8985by rtl i mean in verilog..13:23
sasi8985https://github.com/antonblanchard/microwatt/issues/29313:24
lkclyou can use GHDL and yosys with the yosys-ghdl plugin to convert microwatt to verilog13:24
lkclthis has been done a number of times, you can if you search online find pre-converted verilog HDL for microwatt13:25
sasi8985yeah i found it...but it is not understandable13:26
sasi8985https://git.libre-soc.org/?p=libresoc-litex.git;a=blob;f=microwatt/microwatt.v;h=87dfc352079465813f14c43bb8c0069a52a6b596;hb=6efd2e59703f6f0747435f97030e8a463233457f13:26
lkclindeed.  so you can learn to read VHDL.  it took me only a few weeks.13:26
lkcli still can't _write_ VHDL, but i can at least read it :)13:27
lkclthe difference between := and = was a bit of a pain, but i got there in the end13:27
lkclthe other one is A2O which *is* in verilog13:27
lkcland ChiselWatt is amazingly readable (and incredibly short)13:27
lkclAnton's a software engineer, so knows the value of writing readable code and including comments13:28
sasi8985okay...i will see it...but also i want to write on my own....for that i need to learn some things and there are lots of gaps in my knowledge13:29
sasi8985instead of following traditional rtl can i go with systemc as we can improve performance as well?13:47
lkclghostmansd|2, hello this is lkcl16:51
ghostmansd|2hello!16:51
*** ghostmansd|2 is now known as ghostmansd16:52
lkclsasi8985: systemc is a proprietary tool. Libre-SOC doesn't use proprietary tools (you are entirely free to choose whatever you want of course) because they could contain spying backdoors16:52
lkclghostmansd: so generally, the rule for IRC is: just write the question and leave the IRC client running 24x716:52
lkclthis way, you at least "eventually" complete a conversation :)16:53
ghostmansd:-)16:53
lkclwe have IRC logs here if you ever get disconnected16:53
ghostmansdis there some client recommended for Android?16:53
lkclhttps://libre-soc.org/irclog/index.html16:53
lkcli tried one by installing F-Droid16:53
lkclthen searching in there16:54
lkclit sucked :)16:54
lkclYMMV16:54
ghostmansdno doubts, it's Android, after all :-D16:54
lkclwe're bridged over to here https://chat.openpower.foundation/opf/channels/libre-soc16:54
lkclthanks to toshaan16:54
lkclwhich may be easier (it relies on the openpowerbot being active though, and sometimes it dies)16:55
lkclanyway, we're both here :)16:55
lkclbtw did you run this script for setting up the repos? https://git.libre-soc.org/?p=dev-env-setup.git;a=blob;f=hdl-dev-repos;hb=HEAD16:56
lkclbecause that installs c4m-jtag for you16:57
ghostmansdI think I followed manually via instructions from https://libre-soc.org/HDL_workflow/#index9h116:58
ghostmansdlet me check the script and try using it16:58
lkclthe important thing is to use the "git tag | xargs blah blah"16:58
lkclf****g f****g python setuptools-scm gets in the way.  sigh16:59
lkclthere is a workaround there: define some ENV VAR which tells setuptools-scm to stop trying to be clever16:59
lkcland use an explicit revision tag (defined in the ENV VAR) rather than inspect the git tags and get it hopelessly wrong17:00
lkclif you've already got some repos set up we can run a few tests and see what happens17:00
lkclthe primary one is openpower-isa17:00
lkclcan we please check that by running some unit tests (rather than re-cloning and waiting for that to complete)?17:01
ghostmansdit's already cloned, the script is doing some stuff in the background, though17:01
ghostmansdbut let's check17:01
lkclexcellent17:01
lkclok make sure you're in this directory:17:02
ghostmansdI'm at openpower-isa17:02
lkcllkcl@fizzy:~/src/libresoc/openpower-isa/src/openpower$17:02
lkclcan you check first run "python3 --version" for me?17:02
lkclshould be "Python 3.7.2" (or close)17:02
ghostmansdPython 3.7.317:03
lkclexcellent17:03
lkclok try this:17:03
ghostmansdeven more than close :-)17:03
lkclpython3 decoder/isa/test_caller.py > /tmp/f17:03
lkclthis runs quite a lot of tests17:03
lkcl...s..................17:04
lkcl----------------------------------------------------------------------17:04
lkclRan 22 tests in 54.213s17:04
lkclOK (skipped=1)17:04
ghostmansdwell, it's started17:04
lkclthat's a good sign :)17:04
lkclit's reaaaally verbose btw, hence why pipeline to a file17:04
lkclgetting dots, no "F" or "E" ?17:05
ghostmansd22 tests, 1 skipped, and a huge neat deprecation warning :-)17:05
lkclhurrah!17:05
lkclthat's fantastic!17:05
lkclcongratulations, you just ran a bunch of simulated Power ISA instructions17:05
lkcland they didn't break17:05
ghostmansdsuperb!17:05
ghostmansd7.4M of logs17:06
ghostmansdmy respect!17:06
lkcli know... :)17:06
lkclok so let's do some experimenting / messing about17:06
lkcledit that file (decoder/isa/test_caller.py)17:06
lkcland do a global search/replace "def test_" with "def notst_"17:07
lkcl(or something which basically doesn't have "test" in the function name)17:07
ghostmansds/notst_/notest/ ?17:07
lkclah notest has the word "test" in it :)17:07
lkcli made that mistake lol17:07
lkcltst or tt or "flibblebubble" - just anything *other* than "test" :)17:08
lkclsave it and then in a new console do "git diff" to make sure it's *only* the function names "def test_xxxx" that have changed to "def whatever"17:09
ghostmansd-    def test_add(self):17:09
ghostmansd+    def notest_add(self):17:09
ghostmansdand similar17:09
ghostmansdlooks like OK, let's re-run?17:09
lkclnotest will still be picked up by the python unittest module17:09
ghostmansdthis should skip some tests, right?17:10
lkclit does have to *not* contain - at all - the word "test" - *anywhere* in the function name17:10
lkclyes, that's what we're trying to achieve17:10
ghostmansdre-run the suite, 0 tests are run17:10
lkcli usually use "tst"17:10
lkclah brilliant!17:10
ghostmansddeprecation warning is still there17:10
lkclok i will remember that.17:10
lkclok good17:10
lkclnow17:10
lkclhttps://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/isa/test_caller.py;h=edc9c2bba8f85ca331bc8f8a6bad432bb3bbdde7;hb=e4f69ca4ae12eca4f29c63742621aba5447ae013#l8317:10
lkcljust after DecoderTestCase, put "test" back17:11
lkcldef test_add(self):17:11
lkclso we only run one unit test17:11
ghostmansdyep, re-run Ran 1 test in 1.710s17:11
lkcl(much quicker, saves some time)17:11
lkclexcccellent17:11
lkclok, now the log output should be much shorter17:12
lkclso, in the log output, search for "call add"17:12
ghostmansdint_op 217:12
ghostmansdcall add add17:12
ghostmansdgetitem 14 64 0x0 017:12
lkcland at the same time (in another window) open up decoder/isa/caller.py17:12
lkclbrilliant.  so now, in decoder/isa/caller.py search for "def call(self, name)"17:13
lkclsurpriise, this is the function which is "called" to execute an instruction17:13
lkclthis is terribly lazy programming style, btw, liberally throwing "log()" calls into the program :)17:14
lkclbut it's not designed for "end-user" interaction, it's designed to make it easy to see what the hell is going on when implementing research and HDL17:15
ghostmansdyou mean `log("call", name, asmop)`?17:15
lkclso do not be afraid to commit extra log() debug prints that you need to find things ok!17:15
lkclyes17:15
ghostmansdaha, got it17:16
lkclso, now you are sync'd between the log output and the code17:16
lkclgood17:16
lkclnow in the log output search "reading reg RA"17:16
lkclbut17:16
lkclfirst17:16
lkclnote in def test_add unit test, the instruction listing is17:16
lkcllst = ["add 1, 3, 2"]17:17
lkcland if you look *here*: https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=openpower/isa/fixedarith.mdwn;h=bff81b428bcb3d8a37134e2c02a29a36dc36705b;hb=e4f69ca4ae12eca4f29c63742621aba5447ae013#l5217:17
lkclyou can see the definition for the pseudocode for the "add" instruction17:18
lkcl52 * add RT,RA,RB17:18
ghostmansd3 and 2 are register numbers?17:18
lkclyes.17:18
ghostmansdand these map to RA and RB respectively?17:18
lkcladd 1, 3, 217:18
lkclmaps to RT RA and RB respectively17:18
lkclso we *expect*;17:19
lkclRT=117:19
lkclRA=317:19
lkclRB=217:19
ghostmansdgot it17:19
lkclso, when searching in the logs, first we searched "call add"17:19
lkclthen searched (from that point) for "reading read RA"17:19
lkclwe *expect* it to say, "reading reg RA 3"17:19
lkcland, ta-daaa, that's exactly what it says17:20
ghostmansdaha, I see, and next it takes RB 217:20
lkclyees17:20
ghostmansdwhat 0 stands for?17:20
ghostmansdreading reg RA 3 017:20
lkclwell, let's look in the source code back in caller.py17:20
ghostmansdinitial value?17:21
lkcl                log('reading reg %s %s' % (name, str(regnum)), is_vec)17:21
ghostmansdinitial_regs = [0] * 3217:21
lkcldecoder/isa/caller.py17:21
lkclno: it's whether the register has been marked as "Vectorised" or not17:21
lkcl(we're extending the Power ISA to add Cray-style vectors)17:22
ghostmansdah, OK17:22
lkclso in this case, because it is a v3.0B 32-bit instruction, is_vec is expected to be zero17:22
lkclwe can do an SVP64 unit test later, at some point17:22
lkclor you can try it yourself - test_caller_svp64.py17:22
lkclok so17:22
lkclthe next thing we should expect in the log is "writing 1 gpr"17:23
lkcli really should invert that, make it easier to search for17:23
lkcldone :)17:24
lkclif you "git pull" you should get that17:24
lkclin caller.py you should see this:17:25
lkcl                        log('writing %s %s %s' % (ftype, regnum, str(output)),17:25
lkcl                                                     is_vec)17:25
lkcland the corresponding log output is:17:25
lkclwriting gpr 1 SelectableInt(value=0x5555, bits=64) 017:26
lkclGPR setitem 1 SelectableInt(value=0x5555, bits=64)17:26
lkclwith me so far? :)17:26
ghostmansdjust a moment, I have to stash changes in test_caller.py17:26
ghostmansdbefore the pull17:26
lkclok.  btw feel free to commit comments (meaningful ones!) and extra log() statements17:27
ghostmansdaaah, `git config` is needed17:27
lkclbut you know the rules about adding comments, don't add _too many_ comments :)17:27
ghostmansdI believe I did it before schroot17:27
ghostmansdthe best comments are those which are not present, since the code speaks for itself :-)17:28
lkclmmm clearly you've not read rocket-chip's source code :)17:28
lkclonly people with an IQ well north of 160 can understand it17:28
ghostmansdah, the good ol' "you are not expected to understand this" from 6th edition17:29
lkclthe OO abstraction is clean and clear... and so deep in the number of levels it's almost impossible to comprehend.  annoyingly, we risk the same thing with libre-soc's HDL17:29
lkclone of the downsides of OO class inheritance17:30
ghostmansdok, I believe we're synced now at f3c6dc517:30
ghostmansdlet me unstash and re-run17:30
lkclexcellent. ok so all i did was a 1-line change swapping "writing 1 gpr" to "writing gpr 1"17:30
lkclok17:30
ghostmansdgpr stands for general-purpose register, right?17:31
lkclyes.17:31
lkclfpr Floating Point Register17:31
lkclCR - Condition Register17:31
ghostmansdOK, I'm at writing `gpr 1 SelectableInt(value=0x5555, bits=64) 0`17:31
lkclexcellent!17:31
lkclok, now look at the unit test again17:32
lkcl        initial_regs[3] = 0x123417:32
lkcl        initial_regs[2] = 0x432117:32
lkcland it's an "add" operation on 3 and 217:32
lkclso17:32
lkclduh17:32
lkclwe expect the answer 0x555517:32
lkclwhich is why the unit test does17:32
lkcl            self.assertEqual(sim.gpr(1), SelectableInt(0x5555, 64))17:32
lkcland, ta-daaaaa, it passes!17:32
lkclnow, to double-check, if you look _right_ at the end of the regfile, you see this:17:33
lkclexecute one, CIA NIA 4 817:33
lkclreg  0 00000000 00005555 00004321 00001234 00000000 00000000 00000000 0000000017:33
lkclso again you can "triple-check" the contents of the "regfile" (simulated)17:33
ghostmansd"regfile" stands for log?17:34
ghostmansdexecute one, CIA NIA 4 817:34
ghostmansdreg  0 00000000 00005555 00004321 00001234 00000000 00000000 00000000 0000000017:34
ghostmansdreg  8 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000017:34
ghostmansdreg 16 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000017:34
ghostmansdreg 24 00000000 00000000 00000000 00000000 00000000 00000000 00000000 0000000017:34
ghostmansd__eq__ SelectableInt(value=0x5555, bits=64) SelectableInt(value=0x5555, bits=64)17:34
ghostmansd    eq 21845 21845 True17:34
lkclregfile i mean "register file", in this case, the gpr.17:34
lkclyes.17:34
ghostmansdaha, that's the gpr dump17:34
lkclbtw do be careful not to paste too many lines, IRC servers get unhappy17:34
lkclyes17:34
ghostmansdsorry, I didn't know :-(17:35
lkclso keep it to maximum... around.... 5 lines17:35
lkclthey rate-limit you17:35
ghostmansdquite a strict limitation!17:35
lkclanything over that it's a good idea to use pastebin17:35
lkclif you're handling 100,000 users (like libera is) it's a gooood idea :)17:35
ghostmansdI already got banned by gitolite, please, let IRC have mercy :-)17:35
lkclhaha17:36
ghostmansdOK, will use pastebin next time17:36
lkclit's a tricky one, we're under "audit" conditions, and pastebin is transitory. sigh17:36
lkclreally we should run our own pastebin and make it permanent.  but then (sigh) have to deal with spammers17:37
lkclurrrr17:37
lkclanyway17:37
lkclso you see the chain connecting log to unit test to caller.py17:37
lkcland to the MDWN file with the specification17:37
lkclfixedarith.mdwn17:37
ghostmansdhm, I see only fixedarith.py in decoder/isa17:38
lkclah open a new terminal17:39
lkcland go to the openpower-isa directory17:39
ghostmansdah, I see17:39
ghostmansd../../openpower/isa/fixedarith.mdwn17:39
lkcllkcl@fizzy:~/src/libresoc/openpower-isa17:39
lkclyes.17:39
lkclexcellent17:39
lkclbecause it's, well, not-exactly-source (src)17:39
lkclbut... actually, it is :)17:39
lkclso, good, you found fixedarith.py, that's excellent17:40
lkclif you open up both files side-by-side that's a very useful exercise17:40
lkclthis is where it gets fascinating (for me)17:40
lkclwe did NOT write fixedarith.py by hand17:40
lkclit was *COMPILED*... from fixedarith.mdwn17:41
lkcl(!!!!!)17:41
ghostmansdwhat???17:41
lkclyes.17:41
lkclteehee17:41
ghostmansdI thought it's usually vice-versa :-D17:41
lkcli actually took the OpenPOWER v3.0B ISA pseudocode17:41
lkclwhich says, "warning this pseudocode is not supposed to be executable"17:41
lkcland... well... made it executable17:41
lkclor... language-translatable17:42
lkclBoris Shingarov, of Labware, is REALLY happy with that17:42
lkclbecause he is going to use these markdown files to create Formal Proofs of the Power ISA17:42
lkcl(!!!)17:42
ghostmansd:-D17:43
lkclhave you heard of python-ply at all?17:43
ghostmansdnever17:43
lkclhttps://www.dabeaz.com/ply/17:43
ghostmansdah, lex-yacc17:44
lkcli love it.  it's.. yes17:44
ghostmansdwell, that one I used once17:44
lkclso... next rabbithole? :)17:44
ghostmansdbut not in python form for sure17:44
lkclyeah.  it's out of fashion because it's not as efficient as doing the parser manually yourself17:44
ghostmansdthey give classes, lol17:44
ghostmansdhttps://www.dabeaz.com/compiler.html17:44
lkclgcc dropped lex/yacc (flex / bison) some time ago17:44
lkcldavid's great, i really like his work17:45
ghostmansdyou mean, they switched to hand-written grammar?17:45
ghostmansdI bet C++ was the reason17:45
lkclhand-written parsers17:45
lkclthey're faster than anything LALR parsers can achieve17:45
ghostmansdC++ is extremely awful in parseability anyway17:46
lkclok so if you open up decoder/pseudo/parser.py17:46
lkclif you've ever looked at flex/bison stuff, you should easily and instantly recognise the BNF in the python comments17:46
lkclthis is how ply works: it uses the *comment* field to house the BNF syntax to create the LALR parser17:47
lkclwhen i first encountered PLY like... 10+ years ago.. i loved this idea :)17:47
lkclyou'll particularly like this: i originally started the compiler from the GardenSnake.py python-ply example!17:48
lkclso the grammar is *only slightly* python-like.  the syntax (the symbols) are what have changed.17:48
lkcl"<-" for assignment operator17:48
lkclinstead of "="17:48
lkclbut this is in the OpenPOWER v3.0B pseudo-code specification, so we can't change it17:49
lkclor if we try, we meet with strong resistance17:49
ghostmansdwould it help if you suggest ":="? :-)17:49
lkclthe OpenPOWER spec is now under the control of the OpenPOWER Foundation Working Group. changes are controlled by a "proper process"17:50
lkclit's all posh and everything :)17:50
lkclso anyway, if you scroll down to the bottom of parser.py, you can see it still says "GardenSnakeCompiler" :)17:51
lkclso here's an experiment, to see how this fits together17:51
ghostmansdlet's check17:52
lkclin fixedarith.mdwn find this line:17:52
lkclPseudo-code:17:52
lkcl17:52
lkcl    RT <- (RA) + (RB)17:52
lkcl(line 59)17:52
lkcland change that "+" to a "-"17:53
ghostmansddone17:53
lkclok so in fixedarith.py, look for "def op_add(...)17:54
lkcl"17:54
lkcland check it says RT = RA + RB17:54
lkcl     return (RT,)17:54
ghostmansdaha17:54
lkclwhich, we expected, given that the unmodified version is RT <- (RA) + (RB)17:54
lkclso now run the following command:17:54
lkclpywriter noall fixedarith17:55
lkclor17:55
lkclpywriter noall fixedarith > /tmp/verboseloadofcrud17:55
lkclthis takes a while (it has to compile about 100+ instructions)17:55
lkclthe "noall" btw is to stop pywriter.py from overwriting decoder/isa/all.py17:57
lkclthis should be a lot less klunky but hey17:57
ghostmansdok, it's completed17:58
lkcldang that was a while :)17:58
lkcli forget how ridiculously fast my laptop is17:59
lkclokay!17:59
lkclso now if you inspect fixedarith.py again17:59
lkcl    def op_add(self, RA, RB):17:59
lkcl        RT = RA - RB17:59
lkclta-daaaaa!17:59
ghostmansdit might actually completed a bit ago, I was looking at parser.py :-)17:59
lkclah lol17:59
lkclparser.py is _basically_ a subset of python... just with different symbols18:00
ghostmansdaha, yes, it's changed18:00
lkcland, crucially, it's a single-pass compiler18:00
lkclexccellent18:00
lkclok so now if we re-run the unit test18:00
lkcltest_caller.py18:00
lkclit should FAIL18:00
lkclAssertionError: SelectableInt(value=0xffffffffffffcf13, bits=64) != SelectableInt(value=0x5555, bits=64)18:00
ghostmansdAssertionError: SelectableInt(value=0xffffffffffffcf13, bits=64) != SelectableInt(value=0x5555, bits=64)18:01
lkclta-daaaa!18:01
lkclbest to revert that change to fixedarith.mdwn, you don't want _all_ unit tests failing that involve arithmetic :)18:01
ghostmansdlet's recap, OK?18:01
lkclsure18:02
ghostmansdwe have markdown which is parsed by parser.py18:02
lkclif you summarise, i can check18:02
lkclyes.18:02
ghostmansdit, in turn, generates some python files, which generate the ISA based on contents of markdown18:02
lkcl(which is a python-based compiler with an altered set of tokens)18:03
lkclyes18:03
ghostmansdI don't get, how does code from fixedarith.py makes its way into the ISA18:04
lkclok, that goes through decoder/isa/all.py18:04
ghostmansdI mean, where's the mapping between `def op_add(...)` and "add ..."18:04
lkclwhich is also auto-generated18:04
lkclso if you open decoder/isa/all.py as well18:04
ghostmansdah, `self.instrs = `?18:05
lkclyou see it's blindingly obvious: it basically "imports" aaalll of fixedarith.py. ... blah blahh...18:05
lkclyeeeess.18:05
ghostmansdok, we have dict'o'dicts18:05
lkclah no, it's a dict *merged* from dicts18:05
lkclthat's the **18:05
ghostmansdah, sorry, I meant this18:05
ghostmansdyep18:05
lkclok18:05
lkclso now if you look in caller.py18:05
lkclor... sorry, all.py18:06
lkclnotice this:18:06
ghostmansdI have one more question18:06
lkclclass ISA(ISACaller,18:06
lkclyes, sure18:06
ghostmansdI don't understand where `class fixedarith` is used18:07
lkclok, that's in all.py18:07
ghostmansdah, OK, that's in inheritance18:08
lkclclass ISA(ISACaller, ..... --->fixedarith<----, ....)18:08
lkclyes18:08
ghostmansdfixedarith_instrs['add'] = instruction_info(func=op_add,18:08
lkclblah blah, yes18:08
ghostmansdOK, so we inherit class fixedarith and "add" gets associated with one of its methods18:08
ghostmansdright?18:08
lkclso each fixedarith.py adds a factory dictionary of functions18:08
lkclyeees.18:08
lkcland theeeen18:08
lkclback in caller.py def call(....)18:09
lkclline 113918:09
lkcl        info = self.instrs[name]18:09
lkclta-daaa18:09
lkclwe have the function associated with the instruction.18:09
lkclperformance here is *not* a high priority18:10
ghostmansdaha, got it18:10
lkclthe idea is to have "something that works"18:10
lkcli get i think.... 2,000 instructions per second out of this simulator?18:10
lkcland i'm astounded and delighted it's that fast18:10
ghostmansdwhere are the opcodes?18:10
lkclah, i'm so glad you asked :)18:11
ghostmansdI mean, I got the disasm part18:11
lkclready for the next rabbithole? :)18:11
ghostmansdbut there for sure should be opcodes18:11
ghostmansdyes, sure18:11
lkclyes.18:11
lkclso there are two parts to this.18:11
lkclfirst, if you grab the v3.0B PDF18:11
lkclhttps://ftp.libre-soc.org/18:11
lkclhttps://ftp.libre-soc.org/PowerISA_public.v3.0B.pdf18:11
ghostmansdthere's .C18:11
ghostmansdshould I use .B?18:12
lkcl.B is the one that's "approved" by the OPF EULA18:12
lkclbut i think they updated to C18:12
lkcllet's go with C18:12
lkclthis is not a good idea to read all at once btw :)18:13
lkclnote page 6 section 1.3.4 contains the pseudo-code syntax?18:13
ghostmansdok, I got it18:13
lkclthis is where we had to change the GardenSnake.py python symbols, "=", into "<-" etc. etc.18:14
ghostmansdaha, I see18:14
lkclnow... let's jump to.... 1.618:14
lkclp1218:14
lkclso if you find XO-Form18:15
lkclwhich is err.. 1.6.19, page 1518:15
ghostmansdaha18:15
ghostmansdthis is bitwise, right?18:15
ghostmansdis it little or big?18:15
lkclnow if you look back in fixedarith.mdwn, line 50?18:15
lkclit's... MSB0 order18:16
lkclbit/little endian is *separate* from MSB0 order numbering18:16
lkclMSB0 ordering: the MOST significant bit is numbered ZERO18:16
* lkcl sob18:16
ghostmansdok18:16
lkcli spent 4 months getting used to that and i still get it wrong18:16
lkclBE/LE is just that the instruction fetch automatically byte-reverses the data.18:17
lkclMicrowatt added BE/LE support in a patch that was only 80 lines!18:17
lkclBE/LE is *selectable* at runtime with a bit in the Machine Status Register (MSR)18:18
lkclbut let's ignore that one for now :)18:18
lkclso, section 1.6.19 you see the table?18:18
lkclPO RT RA RB XO18:18
ghostmansdlet's take 0xdeadbeef18:18
lkcland some bit-fields OE and Rc (OE is "overflow enable", Rc is "Result condition")18:19
ghostmansd[1]101111010101101101111101110111118:19
lkclso that is 32-bit18:19
ghostmansdthe bit I selected is MSB0?18:19
ghostmansdso they move l2r?18:19
lkclso... err.. you're asking someone who is slightly logic-dyslexic, but yes, i believe so.18:19
ghostmansdor right to left?18:19
lkclthe total opposite of what everyone else in computer science uses and expects, basically18:20
lkclwhy the hell they chose this is beyond me18:20
ghostmansd:-D18:20
ghostmansdOK, left-to-right, right?18:20
lkcli so did *NOT* want to deal with this that we created a class called SelectableInt18:20
lkclleft being numbered zero (because it's first, i assume that's the logic)18:21
lkclSelectableInt is really important to the python-based simulator.  decoder/selectable_int.py18:21
ghostmansd            # NOTE: POWER 3.0B annotation order!  see p4 1.3.218:22
ghostmansd            # MSB is indexed **LOWEST** (sigh)18:22
ghostmansdOK, I see :-)18:22
lkclafter 6 months you get used to it, i'm told.18:22
ghostmansdlol18:22
lkcli am still having kittens :)18:22
lkclok so where were we.18:22
lkclyes. fixedarith,mdwn, line 5018:22
ghostmansdat XO-FORM18:23
lkclyes.18:23
lkclso back to v3.0B PDF, XO-Form, ta-daaa, now we know what bit-fields to read for the opcode18:23
lkcland you now jump tooOooo... 1sec...18:24
lkclp6718:24
ghostmansdOK, we basically have 4 options wrt OE and RC bits18:24
lkclSection 3.3.9 v3.0B18:24
lkclyes.18:24
ghostmansdthese are enumerated at mdwn18:24
ghostmansdwhat / stands for?18:24
ghostmansdand ///?18:25
lkclOE is "overflow enable" which affects XER register bits18:25
ghostmansdat XO form patterns18:25
ghostmansdno, I mean, the instruction pattern18:25
lkclthat means "there's some bits that are separated but ignored"18:25
lkclso "/" means "there are 2 bits"18:25
lkcl"///" means "there are 4 bits  something / {ignored} / {ignored} / {ignored} / something18:26
ghostmansdehm, how could it be? shouldn't it be 1 and 3 respectively?18:26
ghostmansdI see / under bit 2118:26
lkcl1 sec let me find the page again18:26
ghostmansdthat's the only one18:26
ghostmansdpage 1518:26
ghostmansd1.6.1918:26
lkclok yes, they missed out one "/" there from the spec :)18:27
lkclok so i was slightly wrong, "/" means "this bit is ignored"18:28
lkcl"///" means "all bits are ignored"18:28
ghostmansdso we have 4 types of instructions in XO-FORM, right?18:29
lkclyes.18:29
ghostmansdtwo take into account OE and Rc18:29
lkclluckily, all fields with the same name are all in the same position.18:29
lkclidiotically, there are some fields in the same "Form" which are *not* the same.18:29
lkclgrrr18:29
lkclready for the next surprise? :)18:30
ghostmansdOK, let's move on to the next part. I don't quite yet understand the pattern matching, especially for how it maps to add[###] variants, but OK.18:30
lkclhttps://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=openpower/isatables/fields.text;hb=HEAD18:30
lkclor, if you want to see the local copy, openpower-isa/openpower/isatables/fields.txt in your checked out copy18:31
lkcllook familiar?18:31
ghostmansdyep, that's a copy of pdf :-)18:31
lkclthe surprise: it's been made machine-readable18:31
lkclhttps://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=src/openpower/decoder/power_fields.py;hb=HEAD18:32
ghostmansdday of surprises, lol :-D18:32
lkcl:)18:32
lkclyou notice how the "|"s all line up in the fields.txt file?18:32
ghostmansd 161             "OE": self.FormXO.OE,18:33
ghostmansd 164             "CR": self.FormXL.XO,18:33
lkclthat's so that the power_fields.py can determine *exactly* where the bits start, by matching up the character count with the header at the top of each section18:33
ghostmansdyep, I see the magic :-)18:33
lkclthose are a bit of a cheat, they really shouldn't be there18:33
lkcli copied those from Microwatt18:33
lkclthey're all unique (fortunately)18:33
lkclcaller.py does *not* use them, it *only* grabs the fields from the Form (self.FormXO) and drops them into the ISACaller function18:34
lkcloh btw, one important thing: that's done with a very very special decorator, @inject18:34
lkclat the end of caller.py18:35
lkcli found that code-snippet on stackexchange18:35
lkclit's a massive cheat18:35
ghostmansdjust a moment, I need to take a deeper look at powerfields18:35
lkclso that the pseudo-code doesn't have to be... ok :)18:35
lkcli must apologise, power_fields.py is not properly commented18:36
ghostmansdthere are some comments :-)18:36
ghostmansd201                 # if heading.startswith('1.6.28'): # skip instr fields for now18:36
ghostmansd 202                 #     break18:36
ghostmansd:-D18:36
lkclmercifully it's short :)18:36
ghostmansdlet's simply check how I suppose it works...18:37
lkclline 254: you can actually run it18:37
lkcland it will dump what it parses18:37
ghostmansdah, ok, let's go this way18:37
lkclthen you can compare what it produces against the original, fields.txt18:38
lkclmost of these we do not - and will not - actually use18:38
lkclbut note that there are *two* phases.18:38
ghostmansdhm18:38
lkclPhase 1: parse everything befoer 1.6.2818:38
ghostmansdI'm not sure how it works18:39
lkclPhase 2: parse section 1.6.2818:39
ghostmansdyou mean 1.6.16?18:39
lkclno, 1.6.2818:39
ghostmansdwe're looking at XO-FORM I thought18:39
ghostmansd# 1.6.16 XO-FORM18:39
lkcloh right, ok.18:39
lkclright, i was talking about power_fields.py in general.18:40
lkclit does two phases.18:40
lkclPhase 1: read sections with headers 1.6.1....2718:40
lkclPhase 2: read *only* section "1.6.28 Instruction Fields"18:40
ghostmansdAh, OK18:40
lkclbasically, they are *exactly* the same information18:41
lkcljust expressed in 2 different ways.18:41
lkcli parse them both in order to cross-check each other18:41
ghostmansdI don't get why we had OE (21)18:41
ghostmansdbut in logs we have "        field OE BitRange([(0, 21)])"18:41
ghostmansdshouldn't it be (21, 21)?18:42
lkclerrr... i don't know either :)18:42
lkclah! because it's a map18:42
lkclBit 0 of OE is *MAPPED* to Bit 21 of the opcode18:43
ghostmansdah, ok, got it18:43
lkcland because it's an OrderedDict, the "print" statement prints out tuples of (key, value), (key, value)18:43
ghostmansdI'd have expected a simple thing like start-end18:43
ghostmansdbut OK18:44
lkclbecause... 1 sec....18:44
lkclthere is a reason...18:44
ghostmansdor [21]18:44
lkclok found one18:44
lkcllook at v3.0C p2918:44
lkcl    Formats: X18:44
lkclSX,S (28,6:10)18:44
lkcl    Fields SX18:44
lkclno hang on... a better one...18:45
lkclp2118:45
lkclXO (21:24,26:28)18:45
lkclthat says:18:45
lkclXO is (24-21+1 + 28-26-1) bits18:45
lkclwhich is18:45
ghostmansdI must be missing the place18:46
lkcl4+3=718:46
lkcl7 bits18:46
lkclv3.0C p2118:46
ghostmansdI'm at chapter 2 branch facility18:46
ghostmansdthat's p2918:46
lkclChapter 1 Introduction18:46
lkclp2118:46
lkclor if you prefer, line 902 of fields.txt18:47
lkclFormats: XX2,     XO (21:24,26:28)18:47
lkclthis says:18:47
lkcl"XO is 7 bits.  bit 0 of XO is bit 21.18:48
lkclbit 1 of XO is bit 22 in the opcode18:48
lkclbit 2 of XO is bit 23 in the opcode18:48
lkclbit 3 of XO is bit 24 in the opcode18:48
lkclbit 4 of XO is bit *26* of the opcode18:48
lkclbit 5 of XO is bit *27* of the opcode18:48
ghostmansdah, I see, it's split18:48
lkclbit 6 of XO is bit *28* ....18:49
lkclyeeeees.18:49
lkclhence, you cannot just have a list.18:49
lkclannoying, isn't it?18:49
ghostmansdso it uses 21:24, and 26:2818:49
lkclyeeees.18:49
ghostmansdyep, but still beter than x8618:49
lkcllol18:49
ghostmansdat least the encoding format can be comprehended by mortals18:49
lkclbear in mind, those are MSB0 numbers!18:49
ghostmansdwell, nothing's perfect18:49
ghostmansd:-D18:49
lkclso it's actually, in "normal mortals" language:18:49
lkclbit 0 is (31-21) of the opcode18:50
lkcl...18:50
lkcl...18:50
lkclbit 6 of XO is bit (31-28)18:50
ghostmansdno wonder you have a specialized class for this, lol18:50
lkclhence, again, why SelectableInt exists18:50
lkclyes :)18:50
ghostmansdOK, one mystery is solved18:51
ghostmansdnow I get why we have a map18:51
lkclso, your mission, should you choose to accept it, is over the next few months to create a version of parser.py that outputs *c* code instead of *python* code.18:51
lkclfixedarith.c rather than fixedarith.py18:51
ghostmansdhm, but, still, one question...18:51
lkclyah.  there is one more part of the puzzle btw :)18:52
lkclgo for it18:52
ghostmansd21:24,26:28 can be mapped as [[0,21], [1,22], ...]18:52
lkclyes18:52
ghostmansdbut cannot it be mapped as [21, 22, ...]?18:52
ghostmansdand len() would give the total number of bits18:52
lkclit could, but for whatever reason i chose an OrderedDict.18:52
ghostmansdOK18:53
lkcllen(dict) also returns the number of items.18:53
ghostmansdthat's not a critics, I'm just trying to get how it works :-)18:53
lkcli think probably for speed, given that python list accesses are an O(N) lookup18:53
lkclbut dicts are O(1)18:53
lkclgiven that accessing even just simple fields requires *bit-level* reconstruction of the actual number.18:54
lkcl*gibber*18:54
lkclbtw i have to get up and walk about, soon. been sitting too long.18:54
ghostmansdOK, let's continue next days, then18:55
lkcli leave you with this: https://git.libre-soc.org/?p=openpower-isa.git;a=blob;f=openpower/isatables/minor_31.csv;hb=HEAD18:55
ghostmansdnot the best goodbye I saw, BTW!18:55
lkclwhich, if you check power_decoder.py (not too deeply, it's pretty intense)18:56
lkcllol18:56
lkclthat's how we *actually* decode the opcode.18:56
lkcleverything and i mean everything is machine-readable files18:56
lkclthe entire spec18:56
ghostmansdfrankly? it's damn good idea!18:57
lkclok now i am at least standing up, this is progress18:57
ghostmansdI like it18:57
lkcli am amazed it's not more commonly done18:57
ghostmansdthank you for this intro!18:57
lkclno problem :)18:57
ghostmansdsorry it took that much time18:57
lkclno it's fine, it's really useful, someone else can look at this irc log now18:57
lkcltalk soon :)18:57
ghostmansdI think in the next few days I'll have to work at primary work mostly, but anyway, I'll ping here in IRC when I have some time18:58
ghostmansdonly one question before you leave18:58
ghostmansdwhat _31 stands for before .csv?18:59
openpowerbot[irc] <programmerjake> btw, this room on libera.chat has had the matrix bridge blocking messages for the last 5 or so hours -- maybe we should move to the oftc room?19:53
programmerjakecopying so hopefully people on matrix see: btw, this room on libera.chat has had the matrix bridge blocking messages for the last 5 or so hours -- maybe we should move to the oftc room?20:03
openpowerbot[irc] <programmerjake> https://matrix.to/#/#_oftc_#libre-soc:matrix.org20:08
lkclghostmansd: see power_decoder.py - minor_31.csv is the Primary Opcode 3121:01
lkclall instructions with bits 0..5 equal to 31 are in minor.31.csv21:02
lkclprogrammerjake: openpowerbot bridges between oftc and libera for us, thanks to toshaan21:02
lkclghostmansd: you can see the full opcode map starting at p1162 of v3.0C with Table 10 ("Primary Opcode Map")21:03
openpowerbot[irc] <programmerjake> yup, thx toshywoshy!21:04
lkcland you'll see the green box "EXT31" which is minor_31.csv21:04
lkclthen, jump to p1176, Table 22 "EXT31" and you should see the operations there match up.21:04
lkclexample, cmpi is 00001 000021:04
lkclcmpl sorry, screen's too small :)21:05
lkcland, surpriise, line 18 in minor_31.csv is "0b0000100000,ALU,OP_CMP,RA,RB,...."21:06
programmerjakeweekly meeting in a few min22:49
lkcllxo rsc cesar klysm richardwilbur[m] ^22:54

Generated by irclog2html.py 2.17.1 by Marius Gedminas - find it at https://mg.pov.lt/irclog2html/!