Skip to content

Commit

Permalink
Unconditional jumps
Browse files Browse the repository at this point in the history
  • Loading branch information
lisphacker committed Oct 29, 2023
1 parent d9e4c30 commit 4bfd71c
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions test/Sim/T21.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ testADDI = testADDSUBI True
testSUBI :: Spec
testSUBI = testADDSUBI False

testConditionalJump :: String -> Value -> Value -> JumpCondition -> Spec
testConditionalJump insName trueAcc falseAcc jc = describe ("Testing " ++ insName) $ do
testFalse (JCC jc (Address 5)) (Address 4)
testTrue "without overflow/underflow" (JCC jc (Address 5)) (Address 5)
testTrue "underflow" (JCC jc (Address (-5))) (Address 0)
testTrue "overflow" (JCC jc (Address 10)) (Address 6)
where
testFalse ins tgtAddr = do
let next = step $ init falseAcc ins

describe "Testing false" $ do
it "Status" $ do
pc (tileState next) `shouldBe` tgtAddr

testTrue desc ins tgtAddr = do
let next = step $ init trueAcc ins

describe ("Testing " ++ desc) $ do
it "Status" $ do
pc (tileState next) `shouldBe` tgtAddr

init initAcc ins = mkT21TileWithPC 3 initAcc 0 [NOP, NOP, NOP, ins, NOP, NOP, NOP]

testUnconditionalJump :: Spec
testUnconditionalJump = describe "Testing JMP" $ do
testUnconditionalJump' "without overflow/underflow" (JMP (Address 5)) (Address 5)
Expand All @@ -98,13 +121,13 @@ testUnconditionalJump = describe "Testing JMP" $ do
init ins = mkT21TileWithPC 3 2 0 [NOP, NOP, NOP, ins, NOP, NOP, NOP]

testJEZ :: Spec
testJEZ = undefined
testJEZ = testConditionalJump "JEZ" (Value 0) (Value 10) EZ
testJGZ :: Spec
testJGZ = undefined
testJGZ = testConditionalJump "JGZ" (Value 10) (Value 0) GZ
testJLZ :: Spec
testJLZ = undefined
testJLZ = testConditionalJump "JLZ" (Value (-10)) (Value 0) LZ
testJNZ :: Spec
testJNZ = undefined
testJNZ = testConditionalJump "JNZ" (Value 10) (Value 0) NZ
testJMP :: Spec
testJMP = testUnconditionalJump
testJRO :: Spec
Expand Down Expand Up @@ -191,10 +214,10 @@ simTestsSpec :: Spec
simTestsSpec = describe "Intra-T21 tests" $ parallel $ do
testADD
testADDI
-- testJEZ
-- testJGZ
-- testJLZ
-- testJNZ
testJEZ
testJGZ
testJLZ
testJNZ
testJMP
-- testJRO
testMOV
Expand Down

0 comments on commit 4bfd71c

Please sign in to comment.