Esempio n. 1
0
 def execute_bcond(s, inst):
     """
     B<COND>:
         IF (Passed)<COND>)) then
         PC = PC + (SignExtend(SIMM) << 1)
     BL:
         LR = next PC;
         PC = PC + (SignExtend(SIMM) << 1)
     """
     if is16bit:
         inst.bits &= 0xFFFF
     cond = inst.cond
     imm = inst.bcond_imm
     if cond == 0 and imm == 0:
         raise RuntimeError(
             (
                 "Epiphany simulator caught infinite loop at runtime. "
                 + "Instruction at pc=%s is attempting to "
                 + "branch unconditionally to itself."
             )
             % hex(s.pc)
         )
     if cond == 0b1111:  # Branch and link (BL).
         s.rf[epiphany.isa.reg_map["LR"]] = s.pc + (2 if is16bit else 4)
     if condition_passed(s, cond):
         offset = (signed(sext_8(imm)) << 1) if is16bit else (signed(sext_24(imm)) << 1)
         s.pc = trim_32(s.pc + offset)
     else:
         s.pc += 2 if is16bit else 4
     s.debug_flags()
Esempio n. 2
0
 def execute_movcond(s, inst):
     """
     IF (Passed) <COND> then
         RD = RN
     """
     if is16bit:
         inst.bits &= 0xffff
     rd = inst.rd
     rn = inst.rn
     if condition_passed(s, inst.cond):
         s.rf[rd] = s.rf[rn]
     s.debug_flags()
     s.pc += 2 if is16bit else 4
def test_condition_passed():
    state = new_state(AZ=1)
    assert condition_passed(state, 0b0000)
    state.AZ = 0
    assert condition_passed(state, 0b0001)
    state.AZ = 0
    state.AC = 1
    assert condition_passed(state, 0b0010)
    state.AC = 1
    assert condition_passed(state, 0b0011)
    state.AZ = 1
    state.AC = 0
    assert condition_passed(state, 0b0100)
    state.AC = 0
    assert condition_passed(state, 0b0101)
    state.AZ = 0
    state.AV = state.AN = 2
    assert condition_passed(state, 0b0110)
    state.AZ = 1
    state.AV = state.AN = 3
    assert condition_passed(state, 0b0111)
    state.AV = 4
    state.AN = 3
    assert condition_passed(state, 0b1000)
    state.AZ = 1
    state.AV = 3
    state.AN = 4
    assert condition_passed(state, 0b1001)
    state.BZ = 1
    assert condition_passed(state, 0b1010)
    state.BZ = 0
    assert condition_passed(state, 0b1011)
    state.BN = 1
    state.BZ = 0
    assert condition_passed(state, 0b1100)
    state.BN = 1
    state.BZ = 1
    assert condition_passed(state, 0b1101)
    assert condition_passed(state, 0b1110)
    assert condition_passed(state, 0b1111)
    with pytest.raises(ValueError):
        condition_passed(state, 0b11111)