[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libjit] What does jit_insn_jump_table do, exactly?

From: Aleksey Demakov
Subject: Re: [Libjit] What does jit_insn_jump_table do, exactly?
Date: Sun, 3 Nov 2013 11:35:34 +0400

Hi Sam,

2013/11/3 Sam Wilson <address@hidden>:
> Is jit_insn_jump_table what I need, and if so, how can I use it from C++?

Yes, jump table can be used like this. The function accepts as
arguments a table of jump labels and a value that will be used as the
index for a jump that needs to be taken. The generated code also makes
a range check of the index value, if it is greater than the table size
then no jump is taken and the next instruction after the jump table is

So you would do something like this:

jit_label_t destinations[] = {
jit_label_t default_label;
jit_value_t target;
jit_value_t one, two, minus_one;

jit_insn_jump_table(func, target, destinations, 3);
jit_isnn_branch(func, &default_label);

jit_insn_label(func, &destiantions[0]);
jit_insn_return(func, one);

jit_insn_label(func, &destiantions[1]);
jit_insn_return(func, two);

jit_insn_label(func, &destiantions[2]);
jit_insn_return(func, minus_one);

jit_insn_label(func, &default_label);
// ignore, abort, raise an exception, whatever appropriate


reply via email to

[Prev in Thread] Current Thread [Next in Thread]