(August 12, 2022 at 6:34 pm)bennyboy Wrote:(August 12, 2022 at 7:26 am)FlatAssembler Wrote: @bennyboy , you say you are an experienced web developer. Could you please look into my PicoBlaze Simulator in JavaScript and tell me how I could speed it up? I cannot diagnose why it is so slow.
Yes, I think so. This is not really a web issue, though-- it would be the same in any language running under any framework.
In `assembler.js`, your main loop, "assemble", has 2 problems:
1) From an engineering perspective, it is absolutely unreadable. I've never seen that many if/else statements on a single page in my life. Let's say you have one or two mistakes in all those statements-- hell if you'll find ANYONE willing to go through that pile of spaghetti to find them.
2) From an efficiency perspective, you seem to be doing dozens (hundreds?) of conditional operations on each node. You need to use switch statements or some other type of logic to reduce unnecessary checks.
Also: you have this
multiple times. Why not just assign that equation to a bool and use that? (Again, I don't really use JavaScript, so you can fix the syntax if it's not right)Code:if (node.children[0].getRegisterNumber(context.namedRegisters) === "none") DoErrorStuff{};
Then your poor CPU doesn't have to keep running the same eqaulity check 1000 times.Code:var IsRegister = node.children[0].getRegisterNumber(context.namedRegisters) !== "none"
. . .
if (!IsRegister) DoErrorStuff{}; // Use this the next 1000 times you need the same exact check
Thank you, it would be a good thing to speed up the assembler a bit. But the assembler is, at least for the test programs, already running at an acceptable speed. It is the simulator that is running way too slowly.