Skip to content

Commit 733bd84

Browse files
committed
CHB:ARM: add conditional expressions
1 parent b4d8651 commit 733bd84

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CodeHawk/CHB/bchlibarm32/bCHARMConditionalExpr.ml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ module TR = CHTraceResult
9494
CMP x, 0 GE (x >= 0 & x < e31) (N = 0, V = 0)
9595
9696
HI (x > y) (C = 1 and Z = 0)
97+
98+
99+
CMN x, y:
100+
---------
101+
(result, carry, overflow) = AddWithCarry(x, y, 0)
102+
N = result<31> signed(x + y) < 0
103+
Z = result == 0 x + y = 0 , mod(x + y) = e32
104+
C = carry unsigned(x + y) >= e32
105+
V = overflow signed(x + y) >= e31 \/ signed(x + y) <= -e31
106+
107+
setter condition predicate (on unsigned)
108+
CMN x, 1 LE x < 0
109+
CMN x, 1 GT x >= 0
110+
97111
*)
98112

99113
let x2p = xpr_formatter#pr_expr
@@ -178,6 +192,9 @@ let cc_expr
178192
(testopc: arm_opcode_t)
179193
(cc: arm_opcode_cc_t): (bool * xpr_t option * arm_operand_int list) =
180194
let found = ref true in
195+
let is_one (x: xpr_t) =
196+
match x with
197+
| XConst (IntConst n) -> n#equal CHNumerical.numerical_one | _ -> false in
181198
let (expr, opsused) =
182199
match (testopc, cc) with
183200

@@ -189,6 +206,9 @@ let cc_expr
189206
| (BitwiseAnd (true, ACCAlways, _, x, y, _), ACCEqual) ->
190207
(XOp (XEq, [XOp (XBAnd, [vu x; vu y]); zero_constant_expr]), [x; y])
191208

209+
| (BitwiseAnd (true, ACCAlways, _, x, y, _), ACCNotEqual) ->
210+
(XOp (XNe, [XOp (XBAnd, [vu x; vu y]); zero_constant_expr]), [x; y])
211+
192212
(* ---------------------------------------------------------- Compare --- *)
193213

194214
| (Compare (ACCAlways, x, y, _), ACCEqual) ->
@@ -304,6 +324,12 @@ let cc_expr
304324
| (CompareNegative (ACCAlways, x, y), ACCUnsignedHigher) ->
305325
(XOp (XGt, [XOp (XPlus, [vu x; vu y]); max32_constant_expr]), [x; y])
306326

327+
| (CompareNegative (ACCAlways, x, y), ACCSignedGT) when (is_one (v y)) ->
328+
(XOp (XGe, [v x; zero_constant_expr]), [x; y])
329+
330+
| (CompareNegative (ACCAlways, x, y), ACCSignedLE) when (is_one (v y)) ->
331+
(XOp (XLt, [v x; zero_constant_expr]), [x; y])
332+
307333
| (CompareNegative (ACCAlways, x, y), ACCCarryClear) ->
308334
(XOp (XLOr, [XOp (XLt, [XOp (XPlus, [v x; v y]); zero_constant_expr]);
309335
XOp (XGe, [v x; zero_constant_expr])]), [x; y])

0 commit comments

Comments
 (0)