mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-22 19:22:05 +00:00
Improve rgbasm performance
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "asm/types.h"
|
#include "asm/types.h"
|
||||||
|
|
||||||
#define HASHSIZE 73
|
#define HASHSIZE (1 << 16)
|
||||||
#define MAXSYMLEN 256
|
#define MAXSYMLEN 256
|
||||||
|
|
||||||
struct sSymbol {
|
struct sSymbol {
|
||||||
@@ -35,6 +35,7 @@ struct sSymbol {
|
|||||||
#define SYMF_CONST 0x200 /* symbol has a constant value, will
|
#define SYMF_CONST 0x200 /* symbol has a constant value, will
|
||||||
* not be changed during linking */
|
* not be changed during linking */
|
||||||
|
|
||||||
|
ULONG calchash(char *s);
|
||||||
void sym_PrepPass1(void);
|
void sym_PrepPass1(void);
|
||||||
void sym_PrepPass2(void);
|
void sym_PrepPass2(void);
|
||||||
void sym_AddLocalReloc(char *tzSym);
|
void sym_AddLocalReloc(char *tzSym);
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ struct PatchSymbol {
|
|||||||
ULONG ID;
|
ULONG ID;
|
||||||
struct sSymbol *pSymbol;
|
struct sSymbol *pSymbol;
|
||||||
struct PatchSymbol *pNext;
|
struct PatchSymbol *pNext;
|
||||||
|
struct PatchSymbol *pBucketNext; // next symbol in hash table bucket
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SectionStackEntry {
|
struct SectionStackEntry {
|
||||||
@@ -56,8 +57,10 @@ struct SectionStackEntry {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
struct PatchSymbol *tHashedPatchSymbols[HASHSIZE];
|
||||||
struct Section *pSectionList = NULL, *pCurrentSection = NULL;
|
struct Section *pSectionList = NULL, *pCurrentSection = NULL;
|
||||||
struct PatchSymbol *pPatchSymbols = NULL;
|
struct PatchSymbol *pPatchSymbols = NULL;
|
||||||
|
struct PatchSymbol **ppPatchSymbolsTail = &pPatchSymbols;
|
||||||
char tzObjectname[_MAX_PATH];
|
char tzObjectname[_MAX_PATH];
|
||||||
struct SectionStackEntry *pSectionStack = NULL;
|
struct SectionStackEntry *pSectionStack = NULL;
|
||||||
|
|
||||||
@@ -327,30 +330,32 @@ ULONG
|
|||||||
addsymbol(struct sSymbol * pSym)
|
addsymbol(struct sSymbol * pSym)
|
||||||
{
|
{
|
||||||
struct PatchSymbol *pPSym, **ppPSym;
|
struct PatchSymbol *pPSym, **ppPSym;
|
||||||
ULONG ID = 0;
|
static ULONG nextID = 0;
|
||||||
|
ULONG hash;
|
||||||
|
|
||||||
pPSym = pPatchSymbols;
|
hash = calchash(pSym->tzName);
|
||||||
ppPSym = &(pPatchSymbols);
|
ppPSym = &(tHashedPatchSymbols[hash]);
|
||||||
|
|
||||||
while (pPSym) {
|
while ((*ppPSym) != NULL) {
|
||||||
if (pSym == pPSym->pSymbol)
|
if (pSym == (*ppPSym)->pSymbol)
|
||||||
return (pPSym->ID);
|
return (*ppPSym)->ID;
|
||||||
ppPSym = &(pPSym->pNext);
|
ppPSym = &((*ppPSym)->pBucketNext);
|
||||||
pPSym = pPSym->pNext;
|
|
||||||
ID += 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((*ppPSym = pPSym =
|
if ((*ppPSym = pPSym =
|
||||||
(struct PatchSymbol *) malloc(sizeof(struct PatchSymbol))) !=
|
(struct PatchSymbol *) malloc(sizeof(struct PatchSymbol))) !=
|
||||||
NULL) {
|
NULL) {
|
||||||
pPSym->pNext = NULL;
|
pPSym->pNext = NULL;
|
||||||
|
pPSym->pBucketNext = NULL;
|
||||||
pPSym->pSymbol = pSym;
|
pPSym->pSymbol = pSym;
|
||||||
pPSym->ID = ID;
|
pPSym->ID = nextID++;
|
||||||
return (ID);
|
|
||||||
} else
|
} else
|
||||||
fatalerror("No memory for patchsymbol");
|
fatalerror("No memory for patchsymbol");
|
||||||
|
|
||||||
return ((ULONG) - 1);
|
*ppPatchSymbolsTail = pPSym;
|
||||||
|
ppPatchSymbolsTail = &(pPSym->pNext);
|
||||||
|
|
||||||
|
return pPSym->ID;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* RGBAsm - OUTPUT.C - Outputs an objectfile
|
* RGBAsm - OUTPUT.C - Outputs an objectfile
|
||||||
@@ -385,24 +390,18 @@ addexports(void)
|
|||||||
struct Patch *
|
struct Patch *
|
||||||
allocpatch(void)
|
allocpatch(void)
|
||||||
{
|
{
|
||||||
struct Patch *pPatch, **ppPatch;
|
struct Patch *pPatch;
|
||||||
|
|
||||||
pPatch = pCurrentSection->pPatches;
|
if ((pPatch =
|
||||||
ppPatch = &(pCurrentSection->pPatches);
|
|
||||||
|
|
||||||
while (pPatch) {
|
|
||||||
ppPatch = &(pPatch->pNext);
|
|
||||||
pPatch = pPatch->pNext;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((*ppPatch = pPatch =
|
|
||||||
(struct Patch *) malloc(sizeof(struct Patch))) != NULL) {
|
(struct Patch *) malloc(sizeof(struct Patch))) != NULL) {
|
||||||
pPatch->pNext = NULL;
|
pPatch->pNext = pCurrentSection->pPatches;
|
||||||
pPatch->nRPNSize = 0;
|
pPatch->nRPNSize = 0;
|
||||||
pPatch->pRPN = NULL;
|
pPatch->pRPN = NULL;
|
||||||
} else
|
} else
|
||||||
fatalerror("No memory for patch");
|
fatalerror("No memory for patch");
|
||||||
|
|
||||||
|
pCurrentSection->pPatches = pPatch;
|
||||||
|
|
||||||
return (pPatch);
|
return (pPatch);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -75,10 +75,10 @@ getvaluefield(struct sSymbol * sym)
|
|||||||
ULONG
|
ULONG
|
||||||
calchash(char *s)
|
calchash(char *s)
|
||||||
{
|
{
|
||||||
ULONG hash = 0;
|
ULONG hash = 5381;
|
||||||
|
|
||||||
while (*s != 0)
|
while (*s != 0)
|
||||||
hash += (*s++);
|
hash = (hash * 33) ^ (*s++);
|
||||||
|
|
||||||
return (hash % HASHSIZE);
|
return (hash % HASHSIZE);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user