From 55f87673e36ac2962180dca3db4ece5f31dd3455 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Sat, 25 Jul 2020 16:47:54 +0200 Subject: [PATCH] sim: sim_boolean: handle SETCMI, add unit test --- erlang/apps/sim/src/sim_boolean.erl | 8 ++++++++ erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/test/sim_boolean_tests.erl | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index 2da88dc..2ec4555 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -56,6 +56,7 @@ , handle_SETCAB/4 , handle_SETCAM/4 , handle_SETCM/4 + , handle_SETCMI/4 , handle_SETMB/4 , handle_SETMI/4 , handle_SETMM/4 @@ -614,6 +615,13 @@ handle_SETCM(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_SETCM(Core1, Mem1, IR, EA) end) end. +-spec handle_SETCMI(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_SETCMI(Core, Mem, IR, EA) -> + AC = IR band 8#17, + Word = (bnot EA#ea.offset) band ((1 bsl 36) - 1), + sim_core:next_pc(sim_core:set_ac(Core, AC, Word), Mem). + %% Miscellaneous =============================================================== ea_address(#ea{section = Section, offset = Offset}) -> diff --git a/erlang/apps/sim/src/sim_core.erl b/erlang/apps/sim/src/sim_core.erl index fd6b294..510652d 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -302,6 +302,7 @@ dispatch(Core, Mem, IR, EA) -> 8#456 -> sim_boolean:handle_ORCAM(Core, Mem, IR, EA); 8#457 -> sim_boolean:handle_ORCAB(Core, Mem, IR, EA); 8#460 -> sim_boolean:handle_SETCM(Core, Mem, IR, EA); + 8#461 -> sim_boolean:handle_SETCMI(Core, Mem, IR, EA); _ -> PC = (Core#core.pc_section bsl 18) bor Core#core.pc_offset, {Core, Mem, {error, {?MODULE, {dispatch, PC, IR, EA}}}} diff --git a/erlang/apps/sim/test/sim_boolean_tests.erl b/erlang/apps/sim/test/sim_boolean_tests.erl index 23e5cc7..baecfbc 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -93,6 +93,7 @@ -define(OP_ORCAM, 8#456). -define(OP_ORCAB, 8#457). -define(OP_SETCM, 8#460). +-define(OP_SETCMI, 8#461). %% 2.4 Boolean Functions ======================================================= @@ -686,6 +687,15 @@ setcm_test() -> [ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#070707)} % AC1 = -1,,070707 ]). +setcmi_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_SETCMI, 1, 0, 0, 8#707070)} % 1,,100/ SETCMI 1,707070 + , {1, 8#101, ?INSN_INVALID} % 1,,101/ + ], + expect(Prog, [], {1, 8#101}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#070707)} % AC1 = -1,,070707 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->