Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
replace slow linked list with fast hash
  • Loading branch information
WalterBright committed Feb 20, 2011
1 parent 597d233 commit b329817
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 35 deletions.
4 changes: 2 additions & 2 deletions src/backend/aa.c
Expand Up @@ -450,7 +450,7 @@ typedef int (*dg2_t)(void *, void *, void *);
int AArray::apply(void *parameter, dg2_t dg)
{ int result = 0;

//printf("_aaApply(aa = x%llx, keysize = %d, dg = x%llx)\n", aa.a, keysize, dg);
//printf("_aaApply(aa = %p, keysize = %d, dg = %p)\n", this, keyti->tsize(), dg);

if (nodes)
{
Expand All @@ -475,7 +475,7 @@ int AArray::apply_x(aaA* e, dg2_t dg, size_t keysize, void *parameter)

do
{
//printf("apply_x(e = %p, dg = x%llx)\n", e, dg);
//printf("apply_x(e = %p, dg = %p)\n", e, dg);
result = (*dg)(parameter, e + 1, (char *)(e + 1) + keysize);
if (result)
break;
Expand Down
83 changes: 59 additions & 24 deletions src/backend/cod3.c
Expand Up @@ -23,6 +23,8 @@
#include "global.h"
#include "type.h"
#include "parser.h"
#include "aa.h"
#include "tinfo.h"
#if SCPP
#include "cpp.h"
#include "exh.h"
Expand Down Expand Up @@ -65,7 +67,7 @@ static int AAoff; // offset of alloca temporary
*/

struct fixlist
{ symbol *Lsymbol; // symbol we don't know about
{ //symbol *Lsymbol; // symbol we don't know about
int Lseg; // where the fixup is going (CODE or DATA, never UDATA)
int Lflags; // CFxxxx
targ_size_t Loffset; // addr of reference to symbol
Expand All @@ -75,10 +77,12 @@ struct fixlist
#endif
fixlist *Lnext; // next in threaded list

static fixlist *start;
static AArray *start;
static int nodel; // don't delete from within searchfixlist
};

fixlist *fixlist::start = NULL;
AArray *fixlist::start = NULL;
int fixlist::nodel = 0;

/*************
* Size in bytes of each instruction.
Expand Down Expand Up @@ -4186,6 +4190,7 @@ unsigned codout(code *c)
c->Iop = op ^= 1; // toggle condition
c->IFL2 = FLconst;
c->IEVpointer2 = I16 ? 3 : 5; // skip over JMP block
c->Iflags &= ~CFjmp16;
}
}
}
Expand Down Expand Up @@ -4745,7 +4750,8 @@ STATIC void do8bit(enum FL fl,union evc *uev)
}
GEN(c);
}



/****************************
* Add to the fix list.
*/
Expand All @@ -4758,16 +4764,21 @@ void addtofixlist(symbol *s,targ_size_t soffset,int seg,targ_size_t val,int flag
//printf("addtofixlist(%p '%s')\n",s,s->Sident);
assert(flags);
ln = (fixlist *) mem_calloc(sizeof(fixlist));
ln->Lsymbol = s;
//ln->Lsymbol = s;
ln->Loffset = soffset;
ln->Lseg = seg;
ln->Lflags = flags;
ln->Lval = val;
#if TARGET_OSX
ln->Lfuncsym = funcsym_p;
#endif
ln->Lnext = fixlist::start;
fixlist::start = ln;

if (!fixlist::start)
fixlist::start = new AArray(&ti_pvoid, sizeof(fixlist *));
fixlist **pv = (fixlist **)fixlist::start->get(&s);
ln->Lnext = *pv;
*pv = ln;

#if TARGET_FLAT
numbytes = tysize[TYnptr];
if (I64 && !(flags & CFoffset64))
Expand Down Expand Up @@ -4796,13 +4807,16 @@ void addtofixlist(symbol *s,targ_size_t soffset,int seg,targ_size_t val,int flag
*/

void searchfixlist(symbol *s)
{ register fixlist **lp,*p;

//dbg_printf("searchfixlist(%s)\n",s->Sident);
for (lp = &fixlist::start; (p = *lp) != NULL;)
{
if (s == p->Lsymbol)
{ //dbg_printf("Found reference at x%lx\n",p->Loffset);
{
//printf("searchfixlist(%s)\n",s->Sident);
if (fixlist::start)
{
fixlist **lp = (fixlist **)fixlist::start->in(&s);
if (lp)
{ fixlist *p;
while ((p = *lp) != NULL)
{
//dbg_printf("Found reference at x%lx\n",p->Loffset);

// Determine if it is a self-relative fixup we can
// resolve directly.
Expand Down Expand Up @@ -4833,23 +4847,29 @@ void searchfixlist(symbol *s)
}
*lp = p->Lnext;
mem_free(p); /* remove from list */
}
if (!fixlist::nodel)
fixlist::start->del(&s);
}
else
lp = &(p->Lnext);
}
}
}

/****************************
* End of module. Output remaining fixlist elements as references
* to external symbols.
*/

void outfixlist()
STATIC int outfixlist_dg(void *parameter, void *pkey, void *pvalue)
{
//printf("outfixlist()\n");
for (fixlist *ln = fixlist::start; ln; ln = fixlist::start)
{
symbol *s = ln->Lsymbol;
//printf("outfixlist_dg(pkey = %p, pvalue = %p)\n", pkey, pvalue);
symbol *s = *(symbol **)pkey;

fixlist **plnext = (fixlist **)pvalue;

while (*plnext)
{
fixlist *ln = *plnext;

symbol_debug(s);
//printf("outfixlist '%s' offset %04x\n",s->Sident,ln->Loffset);

Expand Down Expand Up @@ -4902,14 +4922,29 @@ void outfixlist()
#else
reftoident(ln->Lseg,ln->Loffset,s,ln->Lval,ln->Lflags);
#endif
fixlist::start = ln->Lnext;
*plnext = ln->Lnext;
#if TERMCODE
mem_free(ln);
#endif
}
}
}
return 0;
}

void outfixlist()
{
//printf("outfixlist()\n");
if (fixlist::start)
{
fixlist::nodel++;
fixlist::start->apply(NULL, &outfixlist_dg);
fixlist::nodel--;
#if TERMCODE
delete fixlist::start;
fixlist::start = NULL;
#endif
}
}

/**********************************
*/
Expand Down
54 changes: 54 additions & 0 deletions src/backend/ti_pvoid.c
@@ -0,0 +1,54 @@

// Copyright (c) 2011-2011 by Digital Mars
// All Rights Reserved
// written by Walter Bright
// http://www.digitalmars.com
// License for redistribution is by either the Artistic License
// in artistic.txt, or the GNU General Public License in gpl.txt.
// See the included readme.txt for details.


#include <stdlib.h>

#include "tinfo.h"


// void*

TypeInfo_Pvoid ti_pvoid;

const char* TypeInfo_Pvoid::toString()
{
return "void*";
}

hash_t TypeInfo_Pvoid::getHash(void *p)
{ void* s = *(void **)p;
return (hash_t)s;
}

int TypeInfo_Pvoid::equals(void *p1, void *p2)
{
void* s1 = *(void**)p1;
void* s2 = *(void**)p2;

return s1 == s2;
}

int TypeInfo_Pvoid::compare(void *p1, void *p2)
{
void* s1 = *(void**)p1;
void* s2 = *(void**)p2;

return (s1 < s2) ? -1 : ((s1 == s2) ? 0 : 1);
}

size_t TypeInfo_Pvoid::tsize()
{
return sizeof(void*);
}

void TypeInfo_Pvoid::swap(void *p1, void *p2)
{
}

12 changes: 12 additions & 0 deletions src/backend/tinfo.h
Expand Up @@ -37,4 +37,16 @@ struct TypeInfo_Achar : TypeInfo

extern TypeInfo_Achar ti_achar;

struct TypeInfo_Pvoid : TypeInfo
{
const char* toString();
hash_t getHash(void *p);
int equals(void *p1, void *p2);
int compare(void *p1, void *p2);
size_t tsize();
void swap(void *p1, void *p2);
};

extern TypeInfo_Pvoid ti_pvoid;

#endif
6 changes: 5 additions & 1 deletion src/freebsd.mak
Expand Up @@ -42,7 +42,7 @@ DMD_OBJS = \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
imphint.o argtypes.o \
imphint.o argtypes.o ti_pvoid.o \
libelf.o elfobj.o

SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
Expand Down Expand Up @@ -78,6 +78,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
$C/ti_pvoid.c \
$C/machobj.c \
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
Expand Down Expand Up @@ -478,6 +479,9 @@ template.o: template.c
ti_achar.o: $C/tinfo.h $C/ti_achar.c
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c

ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c

tk.o: tk.c
$(CC) -c $(MFLAGS) tk.c

Expand Down
6 changes: 5 additions & 1 deletion src/linux.mak
Expand Up @@ -42,7 +42,7 @@ DMD_OBJS = \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
imphint.o argtypes.o \
imphint.o argtypes.o ti_pvoid.o \
libelf.o elfobj.o

SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
Expand Down Expand Up @@ -78,6 +78,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
$C/ti_pvoid.c \
$C/machobj.c \
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
Expand Down Expand Up @@ -478,6 +479,9 @@ template.o: template.c
ti_achar.o: $C/tinfo.h $C/ti_achar.c
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c

ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c

tk.o: tk.c
$(CC) -c $(MFLAGS) tk.c

Expand Down
14 changes: 10 additions & 4 deletions src/osx.mak
Expand Up @@ -3,15 +3,17 @@ C=backend
TK=tk
ROOT=root

MODEL=-m32

## See: http://developer.apple.com/documentation/developertools/conceptual/cross_development/Using/chapter_3_section_2.html#//apple_ref/doc/uid/20002000-1114311-BABGCAAB
ENVP= MACOSX_DEPLOYMENT_TARGET=10.3
SDK=/Developer/SDKs/MacOSX10.4u.sdk #doesn't work because can't find <stdarg.h>
SDK=/Developer/SDKs/MacOSX10.5.sdk
#SDK=/Developer/SDKs/MacOSX10.6.sdk
LDFLAGS= -isysroot ${SDK} -Wl,-syslibroot,${SDK}

CC=g++ -m32 -isysroot $(SDK)
#CC=g++ -m32
CC=g++ $(MODEL) -isysroot $(SDK)
#CC=g++ $(MODEL)

#OPT=-g -g3
#OPT=-O2
Expand Down Expand Up @@ -48,7 +50,7 @@ DMD_OBJS = \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
imphint.o argtypes.o \
imphint.o argtypes.o ti_pvoid.o \
libmach.o machobj.o

SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
Expand Down Expand Up @@ -84,6 +86,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
$C/ti_pvoid.c \
$C/machobj.c \
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
Expand Down Expand Up @@ -473,7 +476,7 @@ stringtable.o: $(ROOT)/stringtable.c
$(CC) -c $(GFLAGS) -I$(ROOT) $<

strtold.o: $C/strtold.c
gcc -m32 -c $C/strtold.c
gcc $(MODEL) -c $C/strtold.c

struct.o: struct.c
$(CC) -c $(CFLAGS) $<
Expand All @@ -484,6 +487,9 @@ template.o: template.c
ti_achar.o: $C/tinfo.h $C/ti_achar.c
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c

ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c

tk.o: tk.c
$(CC) -c $(MFLAGS) tk.c

Expand Down
6 changes: 5 additions & 1 deletion src/solaris.mak
Expand Up @@ -42,7 +42,7 @@ DMD_OBJS = \
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
builtin.o clone.o aliasthis.o \
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
imphint.o argtypes.o \
imphint.o argtypes.o ti_pvoid.o \
libelf.o elfobj.o

SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
Expand Down Expand Up @@ -78,6 +78,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
$C/ti_pvoid.c \
$C/machobj.c \
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
Expand Down Expand Up @@ -478,6 +479,9 @@ template.o: template.c
ti_achar.o: $C/tinfo.h $C/ti_achar.c
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c

ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c

tk.o: tk.c
$(CC) -c $(MFLAGS) tk.c

Expand Down

0 comments on commit b329817

Please sign in to comment.