Skip to content

Commit

Permalink
Specialize operands depending on bitwidth.
Browse files Browse the repository at this point in the history
  • Loading branch information
Török Edvin committed Aug 17, 2009
1 parent 700cc7f commit 82ca2ab
Show file tree
Hide file tree
Showing 3 changed files with 323 additions and 147 deletions.
20 changes: 20 additions & 0 deletions libclamav/bytecode.c
Expand Up @@ -482,6 +482,16 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
case OP_TRUNC:
inst.u.cast.source = readOperand(bcfunc, buffer, &offset, len, &ok);
inst.u.cast.mask = bcfunc->types[inst.u.cast.source];
if (inst.u.cast.mask == 1)
inst.u.cast.size = 0;
else if (inst.u.cast.mask <= 8)
inst.u.cast.size = 1;
else if (inst.u.cast.mask <= 16)
inst.u.cast.size = 2;
else if (inst.u.cast.mask <= 32)
inst.u.cast.size = 3;
else if (inst.u.cast.mask <= 64)
inst.u.cast.size = 4;
/* calculate mask */
if (inst.opcode != OP_SEXT)
inst.u.cast.mask = inst.u.cast.mask != 64 ?
Expand Down Expand Up @@ -533,6 +543,15 @@ static int parseBB(struct cli_bc *bc, unsigned func, unsigned bb, unsigned char
inst.type = bcfunc->types[inst.u.binop[0]];
break;
}
inst.interp_op = inst.opcode*5;
if (inst.type > 1 && inst.type <= 8)
inst.interp_op += 1;
else if (inst.type <= 16)
inst.interp_op += 2;
else if (inst.type <= 32)
inst.interp_op += 3;
else if (inst.type <= 64)
inst.interp_op += 4;
BB->insts[BB->numInsts++] = inst;
}
if (bb+1 == bc->funcs[func].numBB) {
Expand Down Expand Up @@ -636,6 +655,7 @@ int cli_bytecode_run(const struct cli_bc *bc, struct cli_bc_ctx *ctx)
func.numValues = 1;

inst.opcode = OP_CALL_DIRECT;
inst.interp_op = OP_CALL_DIRECT*5;
inst.dest = func.numArgs;
inst.type = 0;/* TODO: support toplevel functions with return values */
inst.u.ops.numOps = ctx->numParams;
Expand Down
6 changes: 5 additions & 1 deletion libclamav/bytecode_priv.h
Expand Up @@ -47,12 +47,16 @@ struct cli_bc_value {
};

struct cli_bc_cast {
operand_t source;
uint64_t mask;
operand_t source;
uint8_t size;/* 0: 1-bit, 1: 8b, 2: 16b, 3: 32b, 4: 64b */
};

typedef uint8_t interp_op_t;
struct cli_bc_inst {
enum bc_opcode opcode;
uint16_t type;
interp_op_t interp_op;/* opcode for interpreter */
operand_t dest;
union {
operand_t unaryop;
Expand Down

0 comments on commit 82ca2ab

Please sign in to comment.