aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Sokolovsky2014-12-14 03:24:17 +0200
committerPaul Sokolovsky2014-12-14 03:24:17 +0200
commitc0bc3bd736a3442d6fecaf54bd09139f3801551f (patch)
treecd4a3a82e57a49aa362469f7197cb77fb954f888
parent83d27b0f0bad6a5138d0a0984a9de16e34b93c76 (diff)
asmarm: Fix bug with encoding small negative ints using MVN instruction.
-rw-r--r--py/asmarm.c5
-rw-r--r--tests/micropython/viper_binop_comp_imm.py9
-rw-r--r--tests/micropython/viper_binop_comp_imm.py.exp4
3 files changed, 16 insertions, 2 deletions
diff --git a/py/asmarm.c b/py/asmarm.c
index 60286d55c..51852df5f 100644
--- a/py/asmarm.c
+++ b/py/asmarm.c
@@ -282,8 +282,9 @@ void asm_arm_mov_reg_i32(asm_arm_t *as, uint rd, int imm) {
// TODO: There are more variants of immediate values
if ((imm & 0xFF) == imm) {
emit_al(as, asm_arm_op_mov_imm(rd, imm));
- } else if (imm < 0 && ((-imm) & 0xFF) == -imm) {
- emit_al(as, asm_arm_op_mvn_imm(rd, -imm));
+ } else if (imm < 0 && imm >= -256) {
+ // mvn is "move not", not "move negative"
+ emit_al(as, asm_arm_op_mvn_imm(rd, ~imm));
} else {
//Insert immediate into code and jump over it
emit_al(as, 0x59f0000 | (rd << 12)); // ldr rd, [pc]
diff --git a/tests/micropython/viper_binop_comp_imm.py b/tests/micropython/viper_binop_comp_imm.py
new file mode 100644
index 000000000..c7c040895
--- /dev/null
+++ b/tests/micropython/viper_binop_comp_imm.py
@@ -0,0 +1,9 @@
+# comparisons with immediate boundary values
+@micropython.viper
+def f(a: int):
+ print(a == -1, a == -255, a == -256, a == -257)
+
+f(-1)
+f(-255)
+f(-256)
+f(-257)
diff --git a/tests/micropython/viper_binop_comp_imm.py.exp b/tests/micropython/viper_binop_comp_imm.py.exp
new file mode 100644
index 000000000..3da9d09fb
--- /dev/null
+++ b/tests/micropython/viper_binop_comp_imm.py.exp
@@ -0,0 +1,4 @@
+True False False False
+False True False False
+False False True False
+False False False True