Esempio n. 1
0
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,
   }
Esempio n. 2
0
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
Esempio n. 3
0
def test_gates_zero8():
    assert gate_count(Zero8)['nands'] == 22  # gate_count(Zero16)/2 - 1
Esempio n. 4
0
def test_xor():
    assert gate_count(Xor)['nands'] == 4
Esempio n. 5
0
def test_ram4k_legit():
    """The challenge is to implement RAM4K from Registers."""
    assert gate_count(RAM4K).keys() == set(['nands', 'dffs'])
Esempio n. 6
0
def test_gates_and8():
    assert gate_count(And8)['nands'] == 16
Esempio n. 7
0
def test_and16():
    assert gate_count(And16)['nands'] == 32
Esempio n. 8
0
def test_gates_pc8():
    assert gate_count(PC8) == {
        'nands': 266,  # Compare to 287. Not much savings here.
        'dffs': 24,    # This is actually 8 _more_.
    }
Esempio n. 9
0
def test_dmux8way():
    assert gate_count(DMux8Way)['nands'] == 31  # optimal?
Esempio n. 10
0
def test_not16():
    assert gate_count(Not16)['nands'] == 16
Esempio n. 11
0
def test_dmux4way():
    assert gate_count(DMux4Way)['nands'] == 14  # optimal?
Esempio n. 12
0
def test_dmux():
    assert gate_count(DMux)['nands'] == 5
Esempio n. 13
0
def test_mux():
    assert gate_count(Mux)['nands'] == 4
Esempio n. 14
0
def test_gates_alu():
    assert gate_count(EightALU)['nands'] == 284  # gate_count(ALU)/2 + 4
Esempio n. 15
0
def test_mux16():
    assert gate_count(Mux16)['nands'] == 49  # optimal?
Esempio n. 16
0
def test_gates_register8():
    assert gate_count(Register8) == {
        'nands': 32,  # ?
        'dffs': 8
    }
Esempio n. 17
0
def test_mux4Way16():
    assert gate_count(Mux4Way16)['nands'] == 146  # optimal?
Esempio n. 18
0
def test_gates_not8():
    assert gate_count(Not8)['nands'] == 8
Esempio n. 19
0
def test_mux8Way16():
    assert gate_count(Mux8Way16)['nands'] == 339  # optimal?
Esempio n. 20
0
def test_gates_mux8():
    assert gate_count(Mux8)['nands'] == 25  # optimal?
Esempio n. 21
0
def test_nand():
    assert gate_count(Nand)['nands'] == 1
Esempio n. 22
0
def test_register_legit():
    """The challenge is to implement Register from Nand and DFF."""
    assert gate_count(Register).keys() == set(['nands', 'dffs'])
Esempio n. 23
0
def test_gates_inc8():
    assert gate_count(Inc8)['nands'] == 40  # gate_count(Inc16)/2 + 2
Esempio n. 24
0
def test_my_dff_legit():
    """The challenge is to implement DFF with only Nand gates."""
    assert list(gate_count(MyDFF).keys()) == ['nands']
Esempio n. 25
0
def test_gates_add8():
    assert gate_count(Add8)['nands'] == 72  # gate_count(Add16)/2 + 2
Esempio n. 26
0
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))
Esempio n. 27
0
def test_and():
    assert gate_count(And)['nands'] == 2