-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disassembler adjustments, attempt #2 #7
base: master
Are you sure you want to change the base?
Conversation
The aliases of fsgnj (fmv, fabs, and fneg) have a floating-point destination register; the old code displayed this as an integer register.
Do not needlessly disassemble "blt rs1, rs2, LABEL" as "bgt rs2, rs1, LABEL". Likewise, disassemble "blt zero, zero, label" as "blt zero, LABEL" and not "bgtz zero, LABEL" even though they are equivalent, and disassemble "bge zero, zero, LABEL" as "bgez zero, LABEL" and not "blez zero, LABEL".
oh cool. it mostly looks good from eyeballing the changes. I will check it out and test it. tests are a bit thin in this repo because we originally tested this code by interpreting what we decoded so appreciate if you can share results. the only thing is with the pseudos, I was semi-deliberate about reversing branch directions and using the branch {gt|lt} zero shorthands. iirc it applies all possible pseudo lifts. I have a memory of writing code that goes in both directions and this disassembler is an extract from that code which was largely machine-generated. I guess we could label the branch direction pseudos as forward-only - i.e. assemble them but don't lift them. I have a feeling that binutils also decodes pseudos in its disassembly output. so if you have a preference to not decode pseudos it might be better to add an option to disable them. disabling the branch label reversing is less contentious than disabling the zero shorthands. what does binutils do there? also when I read the pseudo-instruction cleanup commit fragment I only see a re-ordering of one constraint so I'll have to take a closer look at that. if you want to disable pseudo wholesale you could add a flags parameter or maybe add an integer set to each of the pseudos that check_constraints could filter on.
or
the other changes all look good. can I merge it without the pseudos cleanup fragment? as that's kind of a user preference thing. |
I asked version 2.39 of the GNU's RISC-V binutils to assemble and then disassemble this sequence:
The result was:
All the non-branch instructions at the bottom got disassembled into pseudoinstructions as expected so let's look at the branches.
My code agrees with the GNU disassembler except on part of point 3: I disassemble to To be clear---my changes to your code don't affect any psuedoinstruction disassembly except for branches, and in general I make your code behave more like GNU binutils than before by preferring What is your stance on the pseudoinstructions after reading this? Are you sold on the idea of preferring One other completely unrelated thing---I think one of my commits added a hard tab to the file. (I use tabs instead of spaces and the muscle memory is hard to break.) But GitHub is a pain to figure out so I'll try to sort this out if/when I update the other commits. |
The format string change fixes a bug: fsgnj instructions write to floating registers, not integer registers.
I add half-precision floating point instructions because they were recently approved by the RISC-V Foundation and their formats are similar to the other three precisions that you already support. The RISC-V Foundation has approved other extensions (particularly the bit manipulation and vector extensions) but they're more complicated so I haven't added them yet.
The pseudoinstruction cleanup fixes some regressions from last October in which branch instructions were needlessly disassembling to pseudoinstructions. The worst offender was "blt rs1, rs2, LABEL" expanding to "bgt rs1, rs2, LABEL" but there was also a quirk where "bge zero, zero, LABEL" was expanding to "blez zero, LABEL" when "bgez zero, LABEL" is arguably better.
The O(n^2) string builder improvement seems unnecessary but I've been using your disassembler as a reference implementation against which I compare my own output on all 1 billion possible 32-bit instructions. Those repeated calls to strlen were killing me.