Skip to content

Commit c328a8a

Browse files
committed
Avoid generating machine code for infrequently used indirect jumps
We set 256 as the threshold because we recorded 16 indirect jumps, and the threshold for launching T1C is 4096. This modification also saves code cache space by avoiding storing the machine code with less usage.
1 parent 2671ffd commit c328a8a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/jit.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#define STACK_SIZE 512
5959
#define MAX_INSNS 1024
60+
#define IN_JUMP_THRESHOLD 256
6061
#if defined(__x86_64__)
6162
#define JUMP_LOC jump_loc + 2
6263
/* Special values for target_pc in struct jump */
@@ -1349,7 +1350,7 @@ void parse_branch_history_table(struct jit_state *state, rv_insn_t *ir)
13491350
if (bt->times[max_idx] < bt->times[i])
13501351
max_idx = i;
13511352
}
1352-
if (bt->PC[max_idx]) {
1353+
if (bt->PC[max_idx] && bt->times[max_idx] >= IN_JUMP_THRESHOLD) {
13531354
emit_load_imm(state, register_map[0], bt->PC[max_idx]);
13541355
emit_cmp32(state, temp_reg, register_map[0]);
13551356
uint32_t jump_loc = state->offset;
@@ -1564,7 +1565,8 @@ static void translate_chained_block(struct jit_state *state,
15641565
if (bt->times[max_idx] < bt->times[i])
15651566
max_idx = i;
15661567
}
1567-
if (bt->PC[max_idx] && !set_has(set, bt->PC[max_idx])) {
1568+
if (bt->PC[max_idx] && bt->times[max_idx] >= IN_JUMP_THRESHOLD &&
1569+
!set_has(set, bt->PC[max_idx])) {
15681570
block_t *block1 =
15691571
cache_get(rv->block_cache, bt->PC[max_idx], false);
15701572
if (block1 && block1->translatable)

0 commit comments

Comments
 (0)