Filter: remove interpreter dynamic typing
[lttng-ust.git] / liblttng-ust / lttng-filter-interpreter.c
index 2982e52c78a8b42c04188895be0ac90901f7e4f1..347704685a40d355de928b07502dde685b8bec59 100644 (file)
@@ -216,6 +216,21 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                [ FILTER_OP_GE_DOUBLE ] = &&LABEL_FILTER_OP_GE_DOUBLE,
                [ FILTER_OP_LE_DOUBLE ] = &&LABEL_FILTER_OP_LE_DOUBLE,
 
+               /* Mixed S64-double binary comparators */
+               [ FILTER_OP_EQ_DOUBLE_S64 ] = &&LABEL_FILTER_OP_EQ_DOUBLE_S64,
+               [ FILTER_OP_NE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_NE_DOUBLE_S64,
+               [ FILTER_OP_GT_DOUBLE_S64 ] = &&LABEL_FILTER_OP_GT_DOUBLE_S64,
+               [ FILTER_OP_LT_DOUBLE_S64 ] = &&LABEL_FILTER_OP_LT_DOUBLE_S64,
+               [ FILTER_OP_GE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_GE_DOUBLE_S64,
+               [ FILTER_OP_LE_DOUBLE_S64 ] = &&LABEL_FILTER_OP_LE_DOUBLE_S64,
+
+               [ FILTER_OP_EQ_S64_DOUBLE ] = &&LABEL_FILTER_OP_EQ_S64_DOUBLE,
+               [ FILTER_OP_NE_S64_DOUBLE ] = &&LABEL_FILTER_OP_NE_S64_DOUBLE,
+               [ FILTER_OP_GT_S64_DOUBLE ] = &&LABEL_FILTER_OP_GT_S64_DOUBLE,
+               [ FILTER_OP_LT_S64_DOUBLE ] = &&LABEL_FILTER_OP_LT_S64_DOUBLE,
+               [ FILTER_OP_GE_S64_DOUBLE ] = &&LABEL_FILTER_OP_GE_S64_DOUBLE,
+               [ FILTER_OP_LE_S64_DOUBLE ] = &&LABEL_FILTER_OP_LE_S64_DOUBLE,
+
                /* unary */
                [ FILTER_OP_UNARY_PLUS ] = &&LABEL_FILTER_OP_UNARY_PLUS,
                [ FILTER_OP_UNARY_MINUS ] = &&LABEL_FILTER_OP_UNARY_MINUS,
@@ -302,7 +317,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (stack_strcmp(stack, "==") == 0);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -313,7 +327,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (stack_strcmp(stack, "!=") != 0);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -324,7 +337,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (stack_strcmp(stack, ">") > 0);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -335,7 +347,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (stack_strcmp(stack, "<") < 0);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -346,7 +357,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (stack_strcmp(stack, ">=") >= 0);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -357,7 +367,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (stack_strcmp(stack, "<=") <= 0);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -369,7 +378,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (estack_bx(stack)->u.v == estack_ax(stack)->u.v);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -380,7 +388,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (estack_bx(stack)->u.v != estack_ax(stack)->u.v);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -391,7 +398,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (estack_bx(stack)->u.v > estack_ax(stack)->u.v);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -402,7 +408,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (estack_bx(stack)->u.v < estack_ax(stack)->u.v);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -413,7 +418,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (estack_bx(stack)->u.v >= estack_ax(stack)->u.v);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -424,7 +428,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        res = (estack_bx(stack)->u.v <= estack_ax(stack)->u.v);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -433,14 +436,9 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                {
                        int res;
 
-                       if (unlikely(estack_ax(stack)->type == REG_S64))
-                               estack_ax(stack)->u.d = (double) estack_ax(stack)->u.v;
-                       else if (unlikely(estack_bx(stack)->type == REG_S64))
-                               estack_bx(stack)->u.d = (double) estack_bx(stack)->u.v;
-                       res = (estack_bx(stack)->u.v == estack_ax(stack)->u.v);
+                       res = (estack_bx(stack)->u.d == estack_ax(stack)->u.d);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -448,14 +446,9 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                {
                        int res;
 
-                       if (unlikely(estack_ax(stack)->type == REG_S64))
-                               estack_ax(stack)->u.d = (double) estack_ax(stack)->u.v;
-                       else if (unlikely(estack_bx(stack)->type == REG_S64))
-                               estack_bx(stack)->u.d = (double) estack_bx(stack)->u.v;
-                       res = (estack_bx(stack)->u.v != estack_ax(stack)->u.v);
+                       res = (estack_bx(stack)->u.d != estack_ax(stack)->u.d);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -463,14 +456,9 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                {
                        int res;
 
-                       if (unlikely(estack_ax(stack)->type == REG_S64))
-                               estack_ax(stack)->u.d = (double) estack_ax(stack)->u.v;
-                       else if (unlikely(estack_bx(stack)->type == REG_S64))
-                               estack_bx(stack)->u.d = (double) estack_bx(stack)->u.v;
-                       res = (estack_bx(stack)->u.v > estack_ax(stack)->u.v);
+                       res = (estack_bx(stack)->u.d > estack_ax(stack)->u.d);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -478,14 +466,9 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                {
                        int res;
 
-                       if (unlikely(estack_ax(stack)->type == REG_S64))
-                               estack_ax(stack)->u.d = (double) estack_ax(stack)->u.v;
-                       else if (unlikely(estack_bx(stack)->type == REG_S64))
-                               estack_bx(stack)->u.d = (double) estack_bx(stack)->u.v;
-                       res = (estack_bx(stack)->u.v < estack_ax(stack)->u.v);
+                       res = (estack_bx(stack)->u.d < estack_ax(stack)->u.d);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -493,14 +476,9 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                {
                        int res;
 
-                       if (unlikely(estack_ax(stack)->type == REG_S64))
-                               estack_ax(stack)->u.d = (double) estack_ax(stack)->u.v;
-                       else if (unlikely(estack_bx(stack)->type == REG_S64))
-                               estack_bx(stack)->u.d = (double) estack_bx(stack)->u.v;
-                       res = (estack_bx(stack)->u.v >= estack_ax(stack)->u.v);
+                       res = (estack_bx(stack)->u.d >= estack_ax(stack)->u.d);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -508,14 +486,132 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                {
                        int res;
 
-                       if (unlikely(estack_ax(stack)->type == REG_S64))
-                               estack_ax(stack)->u.d = (double) estack_ax(stack)->u.v;
-                       else if (unlikely(estack_bx(stack)->type == REG_S64))
-                               estack_bx(stack)->u.d = (double) estack_bx(stack)->u.v;
-                       res = (estack_bx(stack)->u.v <= estack_ax(stack)->u.v);
+                       res = (estack_bx(stack)->u.d <= estack_ax(stack)->u.d);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+
+               /* Mixed S64-double binary comparators */
+               OP(FILTER_OP_EQ_DOUBLE_S64):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.d == estack_ax(stack)->u.v);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_NE_DOUBLE_S64):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.d != estack_ax(stack)->u.v);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_GT_DOUBLE_S64):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.d > estack_ax(stack)->u.v);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_LT_DOUBLE_S64):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.d < estack_ax(stack)->u.v);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_GE_DOUBLE_S64):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.d >= estack_ax(stack)->u.v);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_LE_DOUBLE_S64):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.d <= estack_ax(stack)->u.v);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+
+               OP(FILTER_OP_EQ_S64_DOUBLE):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.v == estack_ax(stack)->u.d);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_NE_S64_DOUBLE):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.v != estack_ax(stack)->u.d);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_GT_S64_DOUBLE):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.v > estack_ax(stack)->u.d);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_LT_S64_DOUBLE):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.v < estack_ax(stack)->u.d);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_GE_S64_DOUBLE):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.v >= estack_ax(stack)->u.d);
+                       estack_pop(stack);
+                       estack_ax(stack)->u.v = res;
+                       next_pc += sizeof(struct binary_op);
+                       PO;
+               }
+               OP(FILTER_OP_LE_S64_DOUBLE):
+               {
+                       int res;
+
+                       res = (estack_bx(stack)->u.v <= estack_ax(stack)->u.d);
                        estack_pop(stack);
                        estack_ax(stack)->u.v = res;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct binary_op);
                        PO;
                }
@@ -572,6 +668,8 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                                        (unsigned int) insn->skip_offset);
                                next_pc = start_pc + insn->skip_offset;
                        } else {
+                               /* Pop 1 when jump not taken */
+                               estack_pop(stack);
                                next_pc += sizeof(struct logical_op);
                        }
                        PO;
@@ -588,6 +686,8 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                                        (unsigned int) insn->skip_offset);
                                next_pc = start_pc + insn->skip_offset;
                        } else {
+                               /* Pop 1 when jump not taken */
+                               estack_pop(stack);
                                next_pc += sizeof(struct logical_op);
                        }
                        PO;
@@ -610,7 +710,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                                ret = -EINVAL;
                                goto end;
                        }
-                       estack_ax(stack)->type = REG_STRING;
                        estack_ax(stack)->u.s.seq_len = UINT_MAX;
                        estack_ax(stack)->u.s.literal = 0;
                        dbg_printf("ref load string %s\n", estack_ax(stack)->u.s.str);
@@ -636,7 +735,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                                ret = -EINVAL;
                                goto end;
                        }
-                       estack_ax(stack)->type = REG_STRING;
                        estack_ax(stack)->u.s.literal = 0;
                        next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
                        PO;
@@ -652,7 +750,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        estack_push(stack);
                        memcpy(&estack_ax(stack)->u.v, &filter_stack_data[ref->offset],
                                sizeof(struct literal_numeric));
-                       estack_ax(stack)->type = REG_S64;
                        dbg_printf("ref load s64 %" PRIi64 "\n", estack_ax(stack)->u.v);
                        next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
                        PO;
@@ -668,7 +765,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        estack_push(stack);
                        memcpy(&estack_ax(stack)->u.d, &filter_stack_data[ref->offset],
                                sizeof(struct literal_double));
-                       estack_ax(stack)->type = REG_DOUBLE;
                        dbg_printf("ref load double %g\n", estack_ax(stack)->u.d);
                        next_pc += sizeof(struct load_op) + sizeof(struct field_ref);
                        PO;
@@ -680,7 +776,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
 
                        dbg_printf("load string %s\n", insn->data);
                        estack_push(stack);
-                       estack_ax(stack)->type = REG_STRING;
                        estack_ax(stack)->u.s.str = insn->data;
                        estack_ax(stack)->u.s.seq_len = UINT_MAX;
                        estack_ax(stack)->u.s.literal = 1;
@@ -696,7 +791,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        memcpy(&estack_ax(stack)->u.v, insn->data,
                                sizeof(struct literal_numeric));
                        dbg_printf("load s64 %" PRIi64 "\n", estack_ax(stack)->u.v);
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct load_op)
                                        + sizeof(struct literal_numeric);
                        PO;
@@ -710,7 +804,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                        memcpy(&estack_ax(stack)->u.d, insn->data,
                                sizeof(struct literal_double));
                        dbg_printf("load s64 %g\n", estack_ax(stack)->u.d);
-                       estack_ax(stack)->type = REG_DOUBLE;
                        next_pc += sizeof(struct load_op)
                                        + sizeof(struct literal_double);
                        PO;
@@ -726,7 +819,6 @@ int lttng_filter_interpret_bytecode(void *filter_data,
                OP(FILTER_OP_CAST_DOUBLE_TO_S64):
                {
                        estack_ax(stack)->u.v = (int64_t) estack_ax(stack)->u.d;
-                       estack_ax(stack)->type = REG_S64;
                        next_pc += sizeof(struct cast_op);
                        PO;
                }
This page took 0.030601 seconds and 4 git commands to generate.