Skip to content

Commit 82ca2ab

Browse files
author
Török Edvin
committed
Specialize operands depending on bitwidth.
1 parent 700cc7f commit 82ca2ab

3 files changed

Lines changed: 323 additions & 147 deletions

File tree

libclamav/bytecode.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
482482
case OP_TRUNC:
483483
inst.u.cast.source = readOperand(bcfunc, buffer, &offset, len, &ok);
484484
inst.u.cast.mask = bcfunc->types[inst.u.cast.source];
485+
if (inst.u.cast.mask == 1)
486+
inst.u.cast.size = 0;
487+
else if (inst.u.cast.mask <= 8)
488+
inst.u.cast.size = 1;
489+
else if (inst.u.cast.mask <= 16)
490+
inst.u.cast.size = 2;
491+
else if (inst.u.cast.mask <= 32)
492+
inst.u.cast.size = 3;
493+
else if (inst.u.cast.mask <= 64)
494+
inst.u.cast.size = 4;
485495
/* calculate mask */
486496
if (inst.opcode != OP_SEXT)
487497
inst.u.cast.mask = inst.u.cast.mask != 64 ?
@@ -533,6 +543,15 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
533543
inst.type = bcfunc->types[inst.u.binop[0]];
534544
break;
535545
}
546+
inst.interp_op = inst.opcode*5;
547+
if (inst.type > 1 && inst.type <= 8)
548+
inst.interp_op += 1;
549+
else if (inst.type <= 16)
550+
inst.interp_op += 2;
551+
else if (inst.type <= 32)
552+
inst.interp_op += 3;
553+
else if (inst.type <= 64)
554+
inst.interp_op += 4;
536555
BB->insts[BB->numInsts++] = inst;
537556
}
538557
if (bb+1 == bc->funcs[func].numBB) {
@@ -636,6 +655,7 @@ int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx)
636655
func.numValues = 1;
637656

638657
inst.opcode = OP_CALL_DIRECT;
658+
inst.interp_op = OP_CALL_DIRECT*5;
639659
inst.dest = func.numArgs;
640660
inst.type = 0;/* TODO: support toplevel functions with return values */
641661
inst.u.ops.numOps = ctx->numParams;

libclamav/bytecode_priv.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ struct cli_bc_value {
4747
};
4848

4949
struct cli_bc_cast {
50-
operand_t source;
5150
uint64_t mask;
51+
operand_t source;
52+
uint8_t size;/* 0: 1-bit, 1: 8b, 2: 16b, 3: 32b, 4: 64b */
5253
};
54+
55+
typedef uint8_t interp_op_t;
5356
struct cli_bc_inst {
5457
enum bc_opcode opcode;
5558
uint16_t type;
59+
interp_op_t interp_op;/* opcode for interpreter */
5660
operand_t dest;
5761
union {
5862
operand_t unaryop;

0 commit comments

Comments
 (0)