Skip to content

Commit af31637

Browse files
committed
CHB:ARM: add MOV-NE conditional expression
1 parent 2a63251 commit af31637

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

CodeHawk/CHB/bchlibarm32/bCHARMConditionalExpr.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ let cc_expr
299299
(XOp (XLOr, [XOp (XLt, [XOp (XPlus, [v x; v y]); zero_constant_expr]);
300300
XOp (XGe, [v x; zero_constant_expr])]), [x; y])
301301

302+
(* ------------------------------------------------------------- Move --- *)
303+
304+
| (Move (true, ACCAlways, _, y, _, _), ACCNotEqual) ->
305+
(XOp (XNe, [v y; zero_constant_expr]), [y])
306+
302307
(* --------------------------------------------------------- Subtract --- *)
303308

304309
| (Subtract (true, ACCAlways, _, x, y, _, _), ACCEqual) ->

CodeHawk/CHT/CHB_tests/bchlibarm32_tests/txbchlibarm32/bCHARMConditionalExprTest.ml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ open BCHAnalyzeApp
6161

6262

6363
let testname = "bCHARMConditionalExprTest"
64-
let lastupdated = "2024-05-25"
64+
let lastupdated = "2024-10-31"
6565

6666

6767
let make_dw (s: string) = TR.tget_ok (string_to_doubleword s)
@@ -183,6 +183,41 @@ let compare_negative_tests () =
183183
end
184184

185185

186+
let move_tests () =
187+
let tests = [
188+
("move-bne", "0x100b0", "0x100b4", "0500b0e1bcffff1a", 3, "(R5 != 0)")
189+
] in
190+
begin
191+
TS.new_testsuite (testname ^ "_subtract_tests") lastupdated;
192+
193+
system_info#set_elf_is_code_address wordzero codemax;
194+
ARMU.arm_instructions_setup (make_dw "0x100b0") 0x10000;
195+
List.iter (fun (title, cfaddr, ccaddr, bytes, iterations, expectedcond) ->
196+
197+
TS.add_simple_test
198+
~title
199+
(fun () ->
200+
let _ = functions_data#reset in
201+
let _ = arm_assembly_functions#reset in
202+
let faddr = make_dw cfaddr in
203+
let bytes = bytes ^ bxlr_bxlr in
204+
let fn = ARMU.arm_function_setup faddr bytes in
205+
(* let _ = CHPretty.pr_debug [fn#toPretty; NL] in *)
206+
let _ =
207+
for _i = 1 to iterations do
208+
analyze_arm_function faddr fn 0
209+
done in
210+
let _ = testsupport#request_arm_conditional_expr in
211+
let _ = translate_arm_assembly_function fn in
212+
let (_, _, optxpr) =
213+
TR.tget_ok (testsupport#retrieve_arm_conditional_expr ccaddr) in
214+
ARMA.equal_arm_conditional_expr
215+
~expected:expectedcond ~received:optxpr ())
216+
) tests;
217+
218+
TS.launch_tests ()
219+
end
220+
186221

187222
(** Subtract subtracts the second argument from the first, writes the result to the
188223
destination and optionally updates the condition flags.
@@ -293,6 +328,7 @@ let () =
293328
TS.new_testfile testname lastupdated;
294329
compare_tests ();
295330
compare_negative_tests ();
331+
move_tests ();
296332
subtract_tests ();
297333
test_tests ();
298334
TS.exit_file()

0 commit comments

Comments
 (0)