Skip to content

Commit aa6201d

Browse files
committed
Refine "N_JIT_CACHE_ENTRIES"
1 parent 6f2c7f0 commit aa6201d

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/jit.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ typedef void (*exec_t2c_func_t)(riscv_t *);
5959
* instructions generated by T2C. Like hardware cache, the old jit-cache will be
6060
* replaced by the new one which uses the same slot.
6161
*/
62-
#define MAX_JIT_CACHE_TABLE_ENTRIES (1 << 12)
62+
63+
/* The size of jit-cache table should be the power of 2, thus, we can easily
64+
* access the element by masking the program counter.
65+
*/
66+
#define N_JIT_CACHE_ENTRIES (1 << 12)
6367

6468
struct jit_cache {
6569
uint64_t pc; /* program counter, easy to build LLVM IR with 64-bit width */

src/t2c.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void t2c_compile(riscv_t *rv, block_t *block)
318318
#if RV32_HAS(JIT_CACHE)
319319
struct jit_cache *jit_cache_init()
320320
{
321-
return calloc(MAX_JIT_CACHE_TABLE_ENTRIES, sizeof(struct jit_cache));
321+
return calloc(N_JIT_CACHE_ENTRIES, sizeof(struct jit_cache));
322322
}
323323

324324
void jit_cache_exit(struct jit_cache *cache)
@@ -328,14 +328,14 @@ void jit_cache_exit(struct jit_cache *cache)
328328

329329
void jit_cache_update(struct jit_cache *cache, uint32_t pc, void *entry)
330330
{
331-
uint32_t pos = pc & (MAX_JIT_CACHE_TABLE_ENTRIES - 1);
331+
uint32_t pos = pc & (N_JIT_CACHE_ENTRIES - 1);
332332

333333
cache[pos].pc = pc;
334334
cache[pos].entry = entry;
335335
}
336336

337337
void jit_cache_clear(struct jit_cache *cache)
338338
{
339-
memset(cache, 0, MAX_JIT_CACHE_TABLE_ENTRIES * sizeof(struct jit_cache));
339+
memset(cache, 0, N_JIT_CACHE_ENTRIES * sizeof(struct jit_cache));
340340
}
341341
#endif

src/t2c_template.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
5454
/* get index */
5555
LLVMValueRef hash = LLVMBuildAnd(
5656
*builder, addr,
57-
LLVMConstInt(LLVMInt32Type(), MAX_JIT_CACHE_TABLE_ENTRIES - 1, false),
58-
"");
57+
LLVMConstInt(LLVMInt32Type(), N_JIT_CACHE_ENTRIES - 1, false), "");
5958

6059
/* get jit_cache_t::pc */
6160
LLVMValueRef cast =

0 commit comments

Comments
 (0)