File tree Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Expand file tree Collapse file tree 3 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -59,7 +59,11 @@ typedef void (*exec_t2c_func_t)(riscv_t *);
59
59
* instructions generated by T2C. Like hardware cache, the old jit-cache will be
60
60
* replaced by the new one which uses the same slot.
61
61
*/
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)
63
67
64
68
struct jit_cache {
65
69
uint64_t pc ; /* program counter, easy to build LLVM IR with 64-bit width */
Original file line number Diff line number Diff line change @@ -318,7 +318,7 @@ void t2c_compile(riscv_t *rv, block_t *block)
318
318
#if RV32_HAS (JIT_CACHE )
319
319
struct jit_cache * jit_cache_init ()
320
320
{
321
- return calloc (MAX_JIT_CACHE_TABLE_ENTRIES , sizeof (struct jit_cache ));
321
+ return calloc (N_JIT_CACHE_ENTRIES , sizeof (struct jit_cache ));
322
322
}
323
323
324
324
void jit_cache_exit (struct jit_cache * cache )
@@ -328,14 +328,14 @@ void jit_cache_exit(struct jit_cache *cache)
328
328
329
329
void jit_cache_update (struct jit_cache * cache , uint32_t pc , void * entry )
330
330
{
331
- uint32_t pos = pc & (MAX_JIT_CACHE_TABLE_ENTRIES - 1 );
331
+ uint32_t pos = pc & (N_JIT_CACHE_ENTRIES - 1 );
332
332
333
333
cache [pos ].pc = pc ;
334
334
cache [pos ].entry = entry ;
335
335
}
336
336
337
337
void jit_cache_clear (struct jit_cache * cache )
338
338
{
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 ));
340
340
}
341
341
#endif
Original file line number Diff line number Diff line change @@ -54,8 +54,7 @@ FORCE_INLINE void t2c_jit_cache_helper(LLVMBuilderRef *builder,
54
54
/* get index */
55
55
LLVMValueRef hash = LLVMBuildAnd (
56
56
* builder , addr ,
57
- LLVMConstInt (LLVMInt32Type (), MAX_JIT_CACHE_TABLE_ENTRIES - 1 , false),
58
- "" );
57
+ LLVMConstInt (LLVMInt32Type (), N_JIT_CACHE_ENTRIES - 1 , false), "" );
59
58
60
59
/* get jit_cache_t::pc */
61
60
LLVMValueRef cast =
You can’t perform that action at this time.
0 commit comments