From 44b8bed409bec26f05011a0490cb8909616874f9 Mon Sep 17 00:00:00 2001 From: Mikael Pettersson Date: Thu, 23 Jul 2020 14:39:34 +0200 Subject: [PATCH] sim: sim_boolean: handle ANDCAI, add unit test --- erlang/apps/sim/src/sim_boolean.erl | 9 +++++++++ erlang/apps/sim/src/sim_core.erl | 1 + erlang/apps/sim/test/sim_boolean_tests.erl | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/erlang/apps/sim/src/sim_boolean.erl b/erlang/apps/sim/src/sim_boolean.erl index 371d1b2..19c8be0 100644 --- a/erlang/apps/sim/src/sim_boolean.erl +++ b/erlang/apps/sim/src/sim_boolean.erl @@ -27,6 +27,7 @@ -export([ handle_AND/4 , handle_ANDB/4 , handle_ANDCA/4 + , handle_ANDCAI/4 , handle_ANDI/4 , handle_ANDM/4 , handle_SETZ/4 @@ -152,6 +153,14 @@ handle_ANDCA(Core, Mem, IR, EA) -> fun(Core1, Mem1) -> handle_ANDCA(Core1, Mem1, IR, EA) end) end. +-spec handle_ANDCAI(#core{}, sim_mem:mem(), IR :: word(), #ea{}) + -> {#core{}, sim_mem:mem(), {ok, integer()} | {error, {module(), term()}}}. +handle_ANDCAI(Core, Mem, IR, EA) -> + AC = IR band 8#17, + CA = sim_core:get_ac(Core, AC), + Word = EA#ea.offset band bnot CA, + 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 fca9611..b6f61f7 100644 --- a/erlang/apps/sim/src/sim_core.erl +++ b/erlang/apps/sim/src/sim_core.erl @@ -262,6 +262,7 @@ dispatch(Core, Mem, IR, EA) -> 8#406 -> sim_boolean:handle_ANDM(Core, Mem, IR, EA); 8#407 -> sim_boolean:handle_ANDB(Core, Mem, IR, EA); 8#410 -> sim_boolean:handle_ANDCA(Core, Mem, IR, EA); + 8#411 -> sim_boolean:handle_ANDCAI(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 2d7c9c1..99b5426 100644 --- a/erlang/apps/sim/test/sim_boolean_tests.erl +++ b/erlang/apps/sim/test/sim_boolean_tests.erl @@ -52,6 +52,7 @@ -define(OP_ANDM, 8#406). -define(OP_ANDB, 8#407). -define(OP_ANDCA, 8#410). +-define(OP_ANDCAI, 8#411). %% 2.4 Boolean Functions ======================================================= @@ -158,6 +159,16 @@ andca_test() -> [ {#ea{section = 1, offset = 1, islocal = false}, ?COMMA2(-1, 8#030303)} % AC1 = -1,,030303 ]). +andcai_test() -> + Prog = + [ {1, 8#100, ?INSN(?OP_MOVEI, 1, 0, 0, 8#707070)} % 1,,100/ MOVEI 1,707070 + , {1, 8#101, ?INSN(?OP_ANDCAI, 1, 0, 0, 8#333333)} % 1,,101/ ANDCAI 1,333333 + , {1, 8#102, ?INSN_INVALID} % 1,,102/ + ], + expect(Prog, [], {1, 8#102}, ?DEFAULT_FLAGS, + [ {#ea{section = 1, offset = 1, islocal = false}, 8#030303} % AC1 = 0,,030303 + ]). + %% Common code to run short sequences ========================================== expect(Prog, ACs, ExpectedPC, ExpectedFlags, ExpectedEs) ->