Skip to content

Commit

Permalink
Merge pull request #264 from flaviojs/add-more-checks-ilt_create
Browse files Browse the repository at this point in the history
Add more checks to ilt_create.
  • Loading branch information
grossmj authored Oct 6, 2024
2 parents aa8b40b + 309331a commit 2227de0
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 20 deletions.
27 changes: 24 additions & 3 deletions common/insn_lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,11 @@ static void ilt_store_table(FILE *fd,insn_lookup_t *ilt)
{
int i;

/* Store compile info */
fwrite(&ilt->crc32_insn,sizeof(ilt->crc32_insn),1,fd);
fwrite(&ilt->nr_insn,sizeof(ilt->nr_insn),1,fd);
fwrite(&ilt->cbm_size,sizeof(ilt->cbm_size),1,fd);

for(i=0;i<RFC_ARRAY_NUMBER;i++)
if (ilt->rfct[i] != NULL)
ilt_store_rfct(fd,i,ilt->rfct[i]);
Expand Down Expand Up @@ -461,6 +466,14 @@ static insn_lookup_t *ilt_load_table(FILE *fd)
memset(ilt,0,sizeof(*ilt));
fseek(fd,0,SEEK_SET);

/* Read compile info */
if ((fread(&ilt->crc32_insn,sizeof(ilt->crc32_insn),1,fd) != 1) ||
(fread(&ilt->nr_insn,sizeof(ilt->nr_insn),1,fd) != 1) ||
(fread(&ilt->cbm_size,sizeof(ilt->cbm_size),1,fd) != 1)) {
ilt_destroy(ilt);
return NULL;
}

for(i=0;i<RFC_ARRAY_NUMBER;i++) {
if (ilt_load_rfct(fd,ilt) == -1) {
ilt_destroy(ilt);
Expand Down Expand Up @@ -524,23 +537,31 @@ static int ilt_cache_store(char *table_name,insn_lookup_t *ilt)
}

/* Create an instruction lookup table */
insn_lookup_t *ilt_create(char *table_name,
insn_lookup_t *ilt_create(char *table_name,m_uint32_t crc32_insn,
int nr_insn,ilt_get_insn_cbk_t get_insn,
ilt_check_cbk_t chk_lo,ilt_check_cbk_t chk_hi)
{
insn_lookup_t *ilt;

/* Try to load a cached table from disk */
if ((ilt = ilt_cache_load(table_name))) {
printf("ILT: loaded table \"%s\" from cache.\n",table_name);
return ilt;
if (ilt->crc32_insn == crc32_insn && ilt->nr_insn == nr_insn && ilt->cbm_size == normalize_size(nr_insn,CBM_SIZE,CBM_SHIFT)) {
ilt->get_insn = get_insn;
ilt->chk_lo = chk_lo;
ilt->chk_hi = chk_hi;
printf("ILT: loaded table \"%s\" from cache.\n",table_name);
return ilt;
}
/* cached table is no longer valid */
ilt_destroy(ilt);
}

/* We have to build the full table... */
ilt = malloc(sizeof(*ilt));
assert(ilt);
memset(ilt,0,sizeof(*ilt));

ilt->crc32_insn = crc32_insn;
ilt->cbm_size = normalize_size(nr_insn,CBM_SIZE,CBM_SHIFT);
ilt->nr_insn = nr_insn;
ilt->get_insn = get_insn;
Expand Down
3 changes: 2 additions & 1 deletion common/insn_lookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct rfc_eqclass {

/* Instruction lookup table */
struct insn_lookup {
m_uint32_t crc32_insn; /* crc32 of the mask and value of all the instructions */
int nr_insn; /* Number of instructions */
int cbm_size; /* Size of Class Bitmaps */

Expand Down Expand Up @@ -96,7 +97,7 @@ static forced_inline int ilt_lookup(insn_lookup_t *ilt,mips_insn_t insn)
}

/* Create an instruction lookup table */
insn_lookup_t *ilt_create(char *table_name,
insn_lookup_t *ilt_create(char *table_name,m_uint32_t crc32,
int nr_insn,ilt_get_insn_cbk_t get_insn,
ilt_check_cbk_t chk_lo,ilt_check_cbk_t chk_hi);

Expand Down
9 changes: 7 additions & 2 deletions stable/mips64_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "memory.h"
#include "insn_lookup.h"
#include "dynamips.h"
#include "crc.h"

/* Forward declaration of instruction array */
static struct mips64_insn_exec_tag mips64_exec_tags[];
Expand Down Expand Up @@ -55,11 +56,15 @@ static void destroy_ilt(void)
void mips64_exec_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;mips64_exec_tags[i].exec;i++)
for(i=0,count=0;mips64_exec_tags[i].exec;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_exec_tags[i].mask,sizeof(mips64_exec_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_exec_tags[i].value,sizeof(mips64_exec_tags[i].value));
count++;
}

ilt = ilt_create("mips64e",count,
ilt = ilt_create("mips64e",crc32,count,
(ilt_get_insn_cbk_t)mips64_exec_get_insn,
(ilt_check_cbk_t)mips64_exec_chk_lo,
(ilt_check_cbk_t)mips64_exec_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions stable/mips64_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "insn_lookup.h"
#include "memory.h"
#include "ptask.h"
#include "crc.h"

#include MIPS64_ARCH_INC_FILE

Expand Down Expand Up @@ -86,11 +87,15 @@ static void destroy_ilt(void)
void mips64_jit_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;mips64_insn_tags[i].emit;i++)
for(i=0,count=0;mips64_insn_tags[i].emit;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_insn_tags[i].mask,sizeof(mips64_insn_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_insn_tags[i].value,sizeof(mips64_insn_tags[i].value));
count++;
}

ilt = ilt_create("mips64j",count,
ilt = ilt_create("mips64j",crc32,count,
(ilt_get_insn_cbk_t)mips64_jit_get_insn,
(ilt_check_cbk_t)mips64_jit_chk_lo,
(ilt_check_cbk_t)mips64_jit_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions stable/ppc32_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "memory.h"
#include "insn_lookup.h"
#include "dynamips.h"
#include "crc.h"

/* Forward declaration of instruction array */
static struct ppc32_insn_exec_tag ppc32_exec_tags[];
Expand Down Expand Up @@ -54,11 +55,15 @@ static void destroy_ilt(void)
void ppc32_exec_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;ppc32_exec_tags[i].exec;i++)
for(i=0,count=0;ppc32_exec_tags[i].exec;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_exec_tags[i].mask,sizeof(ppc32_exec_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_exec_tags[i].value,sizeof(ppc32_exec_tags[i].value));
count++;
}

ilt = ilt_create("ppc32e",count,
ilt = ilt_create("ppc32e",crc32,count,
(ilt_get_insn_cbk_t)ppc32_exec_get_insn,
(ilt_check_cbk_t)ppc32_exec_chk_lo,
(ilt_check_cbk_t)ppc32_exec_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions stable/ppc32_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "insn_lookup.h"
#include "memory.h"
#include "ptask.h"
#include "crc.h"

#include PPC32_ARCH_INC_FILE

Expand Down Expand Up @@ -56,11 +57,15 @@ static void destroy_ilt(void)
void ppc32_jit_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;ppc32_insn_tags[i].emit;i++)
for(i=0,count=0;ppc32_insn_tags[i].emit;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_insn_tags[i].mask,sizeof(ppc32_insn_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_insn_tags[i].value,sizeof(ppc32_insn_tags[i].value));
count++;
}

ilt = ilt_create("ppc32j",count,
ilt = ilt_create("ppc32j",crc32,count,
(ilt_get_insn_cbk_t)ppc32_jit_get_insn,
(ilt_check_cbk_t)ppc32_jit_chk_lo,
(ilt_check_cbk_t)ppc32_jit_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions unstable/mips64_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "memory.h"
#include "insn_lookup.h"
#include "dynamips.h"
#include "crc.h"

/* Forward declaration of instruction array */
static struct mips64_insn_exec_tag mips64_exec_tags[];
Expand Down Expand Up @@ -55,11 +56,15 @@ static void destroy_ilt(void)
void mips64_exec_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;mips64_exec_tags[i].exec;i++)
for(i=0,count=0;mips64_exec_tags[i].exec;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_exec_tags[i].mask,sizeof(mips64_exec_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_exec_tags[i].value,sizeof(mips64_exec_tags[i].value));
count++;
}

ilt = ilt_create("mips64e",count,
ilt = ilt_create("mips64e",crc32,count,
(ilt_get_insn_cbk_t)mips64_exec_get_insn,
(ilt_check_cbk_t)mips64_exec_chk_lo,
(ilt_check_cbk_t)mips64_exec_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions unstable/mips64_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "insn_lookup.h"
#include "memory.h"
#include "ptask.h"
#include "crc.h"

#include MIPS64_ARCH_INC_FILE

Expand Down Expand Up @@ -89,11 +90,15 @@ static void destroy_ilt(void)
void mips64_jit_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;mips64_insn_tags[i].emit;i++)
for(i=0,count=0;mips64_insn_tags[i].emit;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_insn_tags[i].mask,sizeof(mips64_insn_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&mips64_insn_tags[i].value,sizeof(mips64_insn_tags[i].value));
count++;
}

ilt = ilt_create("mips64j",count,
ilt = ilt_create("mips64j",crc32,count,
(ilt_get_insn_cbk_t)mips64_jit_get_insn,
(ilt_check_cbk_t)mips64_jit_chk_lo,
(ilt_check_cbk_t)mips64_jit_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions unstable/ppc32_exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "memory.h"
#include "insn_lookup.h"
#include "dynamips.h"
#include "crc.h"

/* Forward declaration of instruction array */
static struct ppc32_insn_exec_tag ppc32_exec_tags[];
Expand Down Expand Up @@ -54,11 +55,15 @@ static void destroy_ilt(void)
void ppc32_exec_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;ppc32_exec_tags[i].exec;i++)
for(i=0,count=0;ppc32_exec_tags[i].exec;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_exec_tags[i].mask,sizeof(ppc32_exec_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_exec_tags[i].value,sizeof(ppc32_exec_tags[i].value));
count++;
}

ilt = ilt_create("ppc32e",count,
ilt = ilt_create("ppc32e",crc32,count,
(ilt_get_insn_cbk_t)ppc32_exec_get_insn,
(ilt_check_cbk_t)ppc32_exec_chk_lo,
(ilt_check_cbk_t)ppc32_exec_chk_hi);
Expand Down
9 changes: 7 additions & 2 deletions unstable/ppc32_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "insn_lookup.h"
#include "memory.h"
#include "ptask.h"
#include "crc.h"

#include PPC32_ARCH_INC_FILE

Expand Down Expand Up @@ -56,11 +57,15 @@ static void destroy_ilt(void)
void ppc32_jit_create_ilt(void)
{
int i,count;
m_uint32_t crc32 = 0;

for(i=0,count=0;ppc32_insn_tags[i].emit;i++)
for(i=0,count=0;ppc32_insn_tags[i].emit;i++) {
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_insn_tags[i].mask,sizeof(ppc32_insn_tags[i].mask));
crc32 = crc32_compute(~crc32,(m_uint8_t*)&ppc32_insn_tags[i].value,sizeof(ppc32_insn_tags[i].value));
count++;
}

ilt = ilt_create("ppc32j",count,
ilt = ilt_create("ppc32j",crc32,count,
(ilt_get_insn_cbk_t)ppc32_jit_get_insn,
(ilt_check_cbk_t)ppc32_jit_chk_lo,
(ilt_check_cbk_t)ppc32_jit_chk_hi);
Expand Down

0 comments on commit 2227de0

Please sign in to comment.