mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 19:44:01 +02:00
Start implementing BBV primitives
This commit is contained in:
parent
f7717b1d46
commit
20f5b7426e
5 changed files with 70 additions and 27 deletions
64
ujit_core.c
64
ujit_core.c
|
@ -2,35 +2,56 @@
|
|||
#include "ujit_asm.h"
|
||||
#include "ujit_iface.h"
|
||||
#include "ujit_core.h"
|
||||
|
||||
|
||||
|
||||
#include "ujit_codegen.h"
|
||||
|
||||
// Table of block versions indexed by (iseq, index) tuples
|
||||
st_table * version_tbl;
|
||||
|
||||
/*
|
||||
struct st_hash_type {
|
||||
int (*compare)(st_data_t, st_data_t); // st_compare_func*
|
||||
st_index_t (*hash)(st_data_t); // st_hash_func*
|
||||
};
|
||||
|
||||
static const struct st_hash_type st_hashtype_num = {
|
||||
st_numcmp,
|
||||
st_numhash,
|
||||
};
|
||||
|
||||
strcasehash(st_data_t arg)
|
||||
int blockid_cmp(st_data_t arg0, st_data_t arg1)
|
||||
{
|
||||
register const char *string = (const char *)arg;
|
||||
...
|
||||
const blockid_t *block0 = (const blockid_t*)arg0;
|
||||
const blockid_t *block1 = (const blockid_t*)arg1;
|
||||
return block0->iseq == block1->iseq && block0->idx == block1->idx;
|
||||
}
|
||||
|
||||
*/
|
||||
st_index_t blockid_hash(st_data_t arg)
|
||||
{
|
||||
const blockid_t *blockid = (const blockid_t*)arg;
|
||||
st_index_t hash0 = st_numhash((st_data_t)blockid->iseq);
|
||||
st_index_t hash1 = st_numhash((st_data_t)blockid->idx);
|
||||
|
||||
// Use XOR to combine the hashes
|
||||
return hash0 ^ hash1;
|
||||
}
|
||||
|
||||
static const struct st_hash_type hashtype_blockid = {
|
||||
blockid_cmp,
|
||||
blockid_hash,
|
||||
};
|
||||
|
||||
// Retrieve a basic block version for an (iseq, idx) tuple
|
||||
// TODO: we need to add a versioning context here
|
||||
uint8_t* get_block_version(const rb_iseq_t *iseq, unsigned int idx /*, ctx_t* ctx */)
|
||||
{
|
||||
blockid_t blockid = { iseq, idx };
|
||||
|
||||
// If there exists a version for this block id
|
||||
st_data_t st_version;
|
||||
if (rb_st_lookup(version_tbl, (st_data_t)&blockid, &st_version)) {
|
||||
return (uint8_t*)st_version;
|
||||
}
|
||||
|
||||
uint8_t* code_ptr = ujit_compile_block(iseq, idx, false);
|
||||
|
||||
st_insert(version_tbl, (st_data_t)&blockid, (st_data_t)code_ptr);
|
||||
|
||||
return code_ptr;
|
||||
}
|
||||
|
||||
//
|
||||
// Method to generate stubs for branches
|
||||
// TODO: get_branch_stub() or get_branch() function
|
||||
//
|
||||
|
||||
// Get the current instruction opcode from the context object
|
||||
int
|
||||
|
@ -96,3 +117,10 @@ ctx_stack_opnd(ctx_t* ctx, int32_t idx)
|
|||
|
||||
return opnd;
|
||||
}
|
||||
|
||||
void
|
||||
ujit_init_core(void)
|
||||
{
|
||||
// Initialize the version hash table
|
||||
version_tbl = st_init_table(&hashtype_blockid);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue