Skip to content

Commit

Permalink
Use data_minus_addr to get a tiny tiny speedup
Browse files Browse the repository at this point in the history
so tiny, I can't measure it. but I can look at the disassembly and see
one less instruction
  • Loading branch information
Theodore Dubois committed Jun 22, 2017
1 parent c3d0189 commit c24ad25
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions emu/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ void *tlb_handle_miss(struct mem *mem, addr_t addr, int type) {
else
// 1 is not a valid page so this won't look like a hit
tlb->page_if_writable = TLB_PAGE_EMPTY;
tlb->data = pt->data;
mem->dirty_page = PAGE(addr);
return (char *) tlb->data + OFFSET(addr);
tlb->data_minus_addr = (uintptr_t) pt->data - TLB_PAGE(addr);
mem->dirty_page = TLB_PAGE(addr);
return (void *) (tlb->data_minus_addr + addr);
}

__attribute__((constructor))
Expand Down
10 changes: 5 additions & 5 deletions emu/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void pt_dump(struct mem *mem);
struct tlb_entry {
page_t page;
page_t page_if_writable;
void *data;
uintptr_t data_minus_addr;
};
#define TLB_BITS 10
#define TLB_SIZE (1 << TLB_BITS)
#define TLB_INDEX(addr) (((addr) & 0x003ff000) >> 12)
#define TLB_INDEX(addr) ((addr >> PAGE_BITS) & (TLB_SIZE - 1))
#define TLB_READ 0
#define TLB_WRITE 1
#define TLB_PAGE(addr) (addr & 0xfffff000)
Expand All @@ -76,7 +76,7 @@ void *tlb_handle_miss(struct mem *mem, addr_t addr, int type);
forceinline void *mem_read_ptr(struct mem *mem, addr_t addr) {
struct tlb_entry entry = mem->tlb[TLB_INDEX(addr)];
if (entry.page == TLB_PAGE(addr)) {
void *address = (char *) entry.data + OFFSET(addr);
void *address = (void *) (entry.data_minus_addr + addr);
postulate(address != NULL);
return address;
}
Expand All @@ -86,8 +86,8 @@ forceinline void *mem_read_ptr(struct mem *mem, addr_t addr) {
forceinline void *mem_write_ptr(struct mem *mem, addr_t addr) {
struct tlb_entry entry = mem->tlb[TLB_INDEX(addr)];
if (entry.page_if_writable == TLB_PAGE(addr)) {
mem->dirty_page = PAGE(addr);
void *address = (char *) entry.data + OFFSET(addr);
mem->dirty_page = TLB_PAGE(addr);
void *address = (void *) (entry.data_minus_addr + addr);
postulate(address != NULL);
return address;
}
Expand Down
2 changes: 2 additions & 0 deletions emu/modrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct regptr {
reg_id_t reg32_id;
reg_id_t reg64_id;
};
#if DEBUG_LOG
static const char *regptr_name(struct regptr regptr) {
static char buf[15];
sprintf(buf, "%s/%s/%s",
Expand All @@ -16,6 +17,7 @@ static const char *regptr_name(struct regptr regptr) {
reg32_name(regptr.reg32_id));
return buf;
}
#endif

struct modrm_info {
// MOD/RM BITS
Expand Down

0 comments on commit c24ad25

Please sign in to comment.