Skip to content

Commit 3706645

Browse files
committed
Improve the performance of indirect jump for T1C
Considering the T1C ends with the indirect jump, our interpreter mode now records the target of the indirect jump, identifying the most frequent jump target for T1C. The T1 generated code for the indirect jump compares the selected jump target and executes the jump if the comparison results in equality. With this enhancement, T1C and T2C which are integrated later can proceed with an indirect jump if the target PC matches the selected jump target. Based on the performance analysis, the benchmarks with significant number of indirect jump effectively improve the performance. | Metric | N_in_jmp | Original | Propused | Speedup | |----------+-----------+----------+----------+---------| |miniz | 2098313| 1.266 s| 1.225 s| +3.35%| |sha512 | 10500727| 1.905 s| 1.861 s| +2.36%| |dhrystone | 20000618| 0.325 s| 0.253 s| +28.46%| |nqueens | 44658722| 1.051 s| 0.79 s| +33.04%| |qsort | 275000250| 1.978 s| 1.517 s| +30.39%|
1 parent ef29d7d commit 3706645

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/jit.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,18 +1339,19 @@ static void ra_load2_sext(struct jit_state *state,
13391339
void parse_branch_history_table(struct jit_state *state, rv_insn_t *ir)
13401340
{
13411341
int max_idx = 0;
1342+
branch_history_table_t *bt = ir->branch_table;
13421343
for (int i = 0; i < HISTORY_SIZE; i++) {
1343-
if (!ir->branch_table->times[i])
1344+
if (!bt->times[i])
13441345
break;
1345-
if (ir->branch_table->times[max_idx] < ir->branch_table->times[i])
1346+
if (bt->times[max_idx] < bt->times[i])
13461347
max_idx = i;
13471348
}
1348-
if (ir->branch_table->PC[max_idx]) {
1349-
emit_load_imm(state, register_map[0], ir->branch_table->PC[max_idx]);
1349+
if (bt->PC[max_idx]) {
1350+
emit_load_imm(state, register_map[0], bt->PC[max_idx]);
13501351
emit_cmp32(state, temp_reg, register_map[0]);
13511352
uint32_t jump_loc = state->offset;
13521353
emit_jcc_offset(state, 0x85);
1353-
emit_jmp(state, ir->branch_table->PC[max_idx]);
1354+
emit_jmp(state, bt->PC[max_idx]);
13541355
emit_jump_target_offset(state, JUMP_LOC, state->offset);
13551356
}
13561357
}
@@ -1551,18 +1552,18 @@ static void translate_chained_block(struct jit_state *state,
15511552
if (block1->translatable)
15521553
translate_chained_block(state, rv, block1, set);
15531554
}
1554-
if (ir->branch_table) {
1555+
branch_history_table_t *bt = ir->branch_table;
1556+
if (bt) {
15551557
int max_idx = 0;
15561558
for (int i = 0; i < HISTORY_SIZE; i++) {
1557-
if (!ir->branch_table->times[i])
1559+
if (!bt->times[i])
15581560
break;
1559-
if (ir->branch_table->times[max_idx] < ir->branch_table->times[i])
1561+
if (bt->times[max_idx] < bt->times[i])
15601562
max_idx = i;
15611563
}
1562-
if (ir->branch_table->PC[max_idx] &&
1563-
!set_has(set, ir->branch_table->PC[max_idx])) {
1564-
block_t *block1 = cache_get(rv->block_cache,
1565-
ir->branch_table->PC[max_idx], false);
1564+
if (bt->PC[max_idx] && !set_has(set, bt->PC[max_idx])) {
1565+
block_t *block1 =
1566+
cache_get(rv->block_cache, bt->PC[max_idx], false);
15661567
if (block1 && block1->translatable)
15671568
translate_chained_block(state, rv, block1, set);
15681569
}

src/rv32_template.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,16 @@
107107
* | | store the result into dst. |
108108
* | cond, src; | set condition if (src) |
109109
* | end; | set the end of condition if (src) |
110+
* | parsebt; | parse the branch table of indirect |
111+
* | | jump and search the jump target with |
112+
* | | maxiumal frequency. Then, comparing |
113+
* | | and jumping to the target if the |
114+
* | | program counter matches. |
110115
* | break; | In the end of a basic block, we need |
111116
* | | to store all VM register value to rv |
112117
* | | data, becasue the register allocation |
113118
* | | is only applied on a basic block. |
114-
*/
119+
* /
115120
116121
/* Internal */
117122
RVOP(
@@ -276,7 +281,7 @@ RVOP(
276281
alu32imm, 32, 0x81, 0, TMP, imm;
277282
alu32imm, 32, 0x81, 4, TMP, ~1U;
278283
break;
279-
bht;
284+
parsebt;
280285
st, S32, TMP, PC;
281286
exit;
282287
}))

0 commit comments

Comments
 (0)