def test_computer_gates(): assert gate_count(EightComputer) == { 'nands': 1032, # ??? compare to 1262 'dffs': 67, # 3*16 bits (as in the standard CPU), plus two more half-words to hold results between half-cycles, plus a handful more to track some odd bits 'roms': 1, 'rams': 2, 'inputs': 1, 'outputs': 1, }
def main(): std = measure(BUNDLED_PLATFORM) print_result("solutions", std) print_relative_result("project_0x.py", std, measure(USER_PLATFORM)) print_relative_result("alt/lazy.py", std, measure(LAZY_PLATFORM)) print_relative_result("alt/sp.py", std, measure(SP_PLATFORM)) print_relative_result("alt/threaded.py", std, measure(THREADED_PLATFORM)) print_relative_result("alt/shift.py", std, measure(SHIFT_PLATFORM)) print_relative_result("alt/reg.py", std, measure(REG_PLATFORM)) print_relative_result("alt/reduce.py", std, measure(REDUCE_PLATFORM)) # print_relative_result("alt/eight.py", std, measure(EIGHT_PLATFORM, "vector")) print_relative_result("alt/eight.py", std, (gate_count(EIGHT_PLATFORM.chip)['nands'], std[1], std[2] * 2, std[3] * 2)) # Cheeky
def test_gates_zero8(): assert gate_count(Zero8)['nands'] == 22 # gate_count(Zero16)/2 - 1
def test_xor(): assert gate_count(Xor)['nands'] == 4
def test_ram4k_legit(): """The challenge is to implement RAM4K from Registers.""" assert gate_count(RAM4K).keys() == set(['nands', 'dffs'])
def test_gates_and8(): assert gate_count(And8)['nands'] == 16
def test_and16(): assert gate_count(And16)['nands'] == 32
def test_gates_pc8(): assert gate_count(PC8) == { 'nands': 266, # Compare to 287. Not much savings here. 'dffs': 24, # This is actually 8 _more_. }
def test_dmux8way(): assert gate_count(DMux8Way)['nands'] == 31 # optimal?
def test_not16(): assert gate_count(Not16)['nands'] == 16
def test_dmux4way(): assert gate_count(DMux4Way)['nands'] == 14 # optimal?
def test_dmux(): assert gate_count(DMux)['nands'] == 5
def test_mux(): assert gate_count(Mux)['nands'] == 4
def test_gates_alu(): assert gate_count(EightALU)['nands'] == 284 # gate_count(ALU)/2 + 4
def test_mux16(): assert gate_count(Mux16)['nands'] == 49 # optimal?
def test_gates_register8(): assert gate_count(Register8) == { 'nands': 32, # ? 'dffs': 8 }
def test_mux4Way16(): assert gate_count(Mux4Way16)['nands'] == 146 # optimal?
def test_gates_not8(): assert gate_count(Not8)['nands'] == 8
def test_mux8Way16(): assert gate_count(Mux8Way16)['nands'] == 339 # optimal?
def test_gates_mux8(): assert gate_count(Mux8)['nands'] == 25 # optimal?
def test_nand(): assert gate_count(Nand)['nands'] == 1
def test_register_legit(): """The challenge is to implement Register from Nand and DFF.""" assert gate_count(Register).keys() == set(['nands', 'dffs'])
def test_gates_inc8(): assert gate_count(Inc8)['nands'] == 40 # gate_count(Inc16)/2 + 2
def test_my_dff_legit(): """The challenge is to implement DFF with only Nand gates.""" assert list(gate_count(MyDFF).keys()) == ['nands']
def test_gates_add8(): assert gate_count(Add8)['nands'] == 72 # gate_count(Add16)/2 + 2
def measure(platform, simulator="codegen"): return (gate_count(platform.chip)['nands'], test_optimal_08.count_pong_instructions(platform), test_optimal_08.count_pong_cycles_first_iteration( platform, simulator), test_optimal_08.count_cycles_to_init(platform, simulator))
def test_and(): assert gate_count(And)['nands'] == 2