Skip to content

Commit

Permalink
Renamed should_branch to condition_passed. New name is more consisten…
Browse files Browse the repository at this point in the history
…t with the Epiphany documentation and does not imply use with a particular instruction.
  • Loading branch information
snim2 committed Jun 28, 2015
1 parent 4dde4f9 commit c0e3410
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion epiphany/condition_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
we_are_translated = lambda : False


def should_branch(s, cond):
def condition_passed(s, cond):
if cond == 0b0000: # BEQ
return bool(s.AZ)
elif cond == 0b0001: # BNE
Expand Down
4 changes: 2 additions & 2 deletions epiphany/execute_branch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from epiphany.condition_codes import should_branch
from epiphany.condition_codes import condition_passed
from epiphany.utils import signed_8, signed_24, sext_8, sext_24

import epiphany.isa
Expand All @@ -22,7 +22,7 @@ def execute_bcond(s, inst):
imm = inst.bcond_imm
if cond == 0b1111: # Branch and link (BL).
s.rf[epiphany.isa.reg_map['LR']] = (s.pc + 2) if is16bit else (s.pc + 4)
if should_branch(s, cond):
if condition_passed(s, cond):
s.pc += (sext_8(signed_8(imm)) << 1) if is16bit else (sext_24(signed_24(imm)) << 1)
else:
s.pc += 2 if is16bit else 4
Expand Down
4 changes: 2 additions & 2 deletions epiphany/execute_mov.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from epiphany.condition_codes import should_branch
from epiphany.condition_codes import condition_passed


#-----------------------------------------------------------------------
Expand All @@ -14,7 +14,7 @@ def execute_movcond(s, inst):
inst.bits &= 0xffff
rd = inst.rd
rn = inst.rn
if should_branch(s, inst.cond):
if condition_passed(s, inst.cond):
s.rf[rd] = s.rf[rn]
s.pc += 2 if is16bit else 4
return execute_movcond
Expand Down
48 changes: 48 additions & 0 deletions epiphany/test/test_condition_passed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from epiphany.condition_codes import condition_passed
from epiphany.test.machine import new_state

import pytest


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)
48 changes: 0 additions & 48 deletions epiphany/test/test_should_branch.py

This file was deleted.

0 comments on commit c0e3410

Please sign in to comment.