Skip to content

Commit

Permalink
generate_jit: Refactor to deduplicate custom call generation
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaanC authored and copy committed Jul 22, 2020
1 parent b2e44e2 commit b36a03c
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions gen/generate_jit.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ function get_nonfaulting_mem_reg_postfix(encoding)
};
}

function gen_custom_call(encoding, size, args)
{
console.assert(!encoding.nonfaulting, "Prefix/custom instructions cannot be marked as nonfaulting.");

const instruction_name = make_instruction_name(encoding, size) + "_jit";
const imm_read = gen_read_imm_call(encoding, size);

if(imm_read)
{
args.push(imm_read);
}

return gen_call(instruction_name, args);
}

function gen_instruction_body(encodings, size)
{
const encoding = encodings[0];
Expand Down Expand Up @@ -207,19 +222,11 @@ function gen_instruction_body(encodings, size)
const instruction_postfix = case_.jump ? ["instr_flags |= JIT_INSTR_JUMP_FLAG;"] : [];
if(case_.custom)
{
console.assert(!case_.nonfaulting, "Unsupported: custom fixed_g instruction as nonfaulting");
const instruction_name = make_instruction_name(case_, size) + "_jit";
const imm_read = gen_read_imm_call(case_, size);
const args = ["modrm_byte"];

if(imm_read)
{
args.push(imm_read);
}
const custom_call = gen_custom_call(case_, size, ["modrm_byte"]);

return {
conditions: [fixed_g],
body: [gen_call(instruction_name, args)].concat(instruction_postfix),
body: [custom_call].concat(instruction_postfix),
};
}

Expand Down Expand Up @@ -417,20 +424,10 @@ function gen_instruction_body(encodings, size)
}
else if(encoding.prefix || encoding.custom)
{
console.assert(!encoding.nonfaulting, "Prefix/custom instructions cannot be marked as nonfaulting.");

const instruction_name = make_instruction_name(encoding, size) + "_jit";
const imm_read = gen_read_imm_call(encoding, size);
const args = [];

if(imm_read)
{
args.push(imm_read);
}

const custom_call = gen_custom_call(encoding, size, []);
const call_prefix = encoding.prefix ? "instr_flags |= " : "";
// Prefix calls can add to the return flags
return [call_prefix + gen_call(instruction_name, args)].concat(instruction_postfix);
return [call_prefix + custom_call].concat(instruction_postfix);
}
else
{
Expand Down

0 comments on commit b36a03c

Please sign in to comment.