mossprescott / pynand

Nand2Tetris in Python.
Other
12 stars 3 forks source link

In codegen, avoid evaluation that's not used #23

Open mossprescott opened 4 years ago

mossprescott commented 4 years ago

There are three obvious sub-graphs whose results are not used a lot of the time:

I tried converting each of these into if instr & 0x8000: by hand, and got ~25% speedup overall.

To automate that would involve analyzing the node graph to determine what parts of the graph need to be evaluated when. Something like: "what subgraphs are referenced only on one side of a conditional (i.e. Mux16), and what is the condition?" but it's tricky because the ALU output is referenced many times, with various conditions, all of which include the same bit of the instruction in some way.

Turns out CS is hard.