summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorPepijn de Vos <pepijndevos@gmail.com>2023-02-25 17:01:28 +0100
committerDamien George <damien@micropython.org>2023-02-27 10:25:39 +1100
commit72e93183253586b4b1bb502287e67b58470f7a5c (patch)
tree2f0415f8f1ae50f3da9ecc407a29370ef7a2d5b1 /py
parent2e4dda3c2072c4de15ac8d51ddb471b9c3833db7 (diff)
py/emitnative: Explicitly compare comparison ops in binary_op emitter.
Without this it's possible to get a compiler error about the comparison always being true, because MP_BINARY_OP_LESS is 0. And it seems that gcc optimises these 6 equality comparisons into the same size machine code as before.
Diffstat (limited to 'py')
-rw-r--r--py/emitnative.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index b02559ad7..3cb003315 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -2365,14 +2365,13 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
} else if (op == MP_BINARY_OP_MULTIPLY) {
ASM_MUL_REG_REG(emit->as, REG_ARG_2, reg_rhs);
emit_post_push_reg(emit, vtype_lhs, REG_ARG_2);
- } else if (MP_BINARY_OP_LESS <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
- // comparison ops are (in enum order):
- // MP_BINARY_OP_LESS
- // MP_BINARY_OP_MORE
- // MP_BINARY_OP_EQUAL
- // MP_BINARY_OP_LESS_EQUAL
- // MP_BINARY_OP_MORE_EQUAL
- // MP_BINARY_OP_NOT_EQUAL
+ } else if (op == MP_BINARY_OP_LESS
+ || op == MP_BINARY_OP_MORE
+ || op == MP_BINARY_OP_EQUAL
+ || op == MP_BINARY_OP_LESS_EQUAL
+ || op == MP_BINARY_OP_MORE_EQUAL
+ || op == MP_BINARY_OP_NOT_EQUAL) {
+ // comparison ops
if (vtype_lhs != vtype_rhs) {
EMIT_NATIVE_VIPER_TYPE_ERROR(emit, MP_ERROR_TEXT("comparison of int and uint"));