Skip to content

Commit b329817

Browse files
committed
replace slow linked list with fast hash
1 parent 597d233 commit b329817

File tree

10 files changed

+192
-35
lines changed

10 files changed

+192
-35
lines changed

src/backend/aa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ typedef int (*dg2_t)(void *, void *, void *);
450450
int AArray::apply(void *parameter, dg2_t dg)
451451
{ int result = 0;
452452

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

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

476476
do
477477
{
478-
//printf("apply_x(e = %p, dg = x%llx)\n", e, dg);
478+
//printf("apply_x(e = %p, dg = %p)\n", e, dg);
479479
result = (*dg)(parameter, e + 1, (char *)(e + 1) + keysize);
480480
if (result)
481481
break;

src/backend/cod3.c

Lines changed: 59 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include "global.h"
2424
#include "type.h"
2525
#include "parser.h"
26+
#include "aa.h"
27+
#include "tinfo.h"
2628
#if SCPP
2729
#include "cpp.h"
2830
#include "exh.h"
@@ -65,7 +67,7 @@ static int AAoff; // offset of alloca temporary
6567
*/
6668

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

78-
static fixlist *start;
80+
static AArray *start;
81+
static int nodel; // don't delete from within searchfixlist
7982
};
8083

81-
fixlist *fixlist::start = NULL;
84+
AArray *fixlist::start = NULL;
85+
int fixlist::nodel = 0;
8286

8387
/*************
8488
* Size in bytes of each instruction.
@@ -4186,6 +4190,7 @@ unsigned codout(code *c)
41864190
c->Iop = op ^= 1; // toggle condition
41874191
c->IFL2 = FLconst;
41884192
c->IEVpointer2 = I16 ? 3 : 5; // skip over JMP block
4193+
c->Iflags &= ~CFjmp16;
41894194
}
41904195
}
41914196
}
@@ -4745,7 +4750,8 @@ STATIC void do8bit(enum FL fl,union evc *uev)
47454750
}
47464751
GEN(c);
47474752
}
4748-
4753+
4754+
47494755
/****************************
47504756
* Add to the fix list.
47514757
*/
@@ -4758,16 +4764,21 @@ void addtofixlist(symbol *s,targ_size_t soffset,int seg,targ_size_t val,int flag
47584764
//printf("addtofixlist(%p '%s')\n",s,s->Sident);
47594765
assert(flags);
47604766
ln = (fixlist *) mem_calloc(sizeof(fixlist));
4761-
ln->Lsymbol = s;
4767+
//ln->Lsymbol = s;
47624768
ln->Loffset = soffset;
47634769
ln->Lseg = seg;
47644770
ln->Lflags = flags;
47654771
ln->Lval = val;
47664772
#if TARGET_OSX
47674773
ln->Lfuncsym = funcsym_p;
47684774
#endif
4769-
ln->Lnext = fixlist::start;
4770-
fixlist::start = ln;
4775+
4776+
if (!fixlist::start)
4777+
fixlist::start = new AArray(&ti_pvoid, sizeof(fixlist *));
4778+
fixlist **pv = (fixlist **)fixlist::start->get(&s);
4779+
ln->Lnext = *pv;
4780+
*pv = ln;
4781+
47714782
#if TARGET_FLAT
47724783
numbytes = tysize[TYnptr];
47734784
if (I64 && !(flags & CFoffset64))
@@ -4796,13 +4807,16 @@ void addtofixlist(symbol *s,targ_size_t soffset,int seg,targ_size_t val,int flag
47964807
*/
47974808

47984809
void searchfixlist(symbol *s)
4799-
{ register fixlist **lp,*p;
4800-
4801-
//dbg_printf("searchfixlist(%s)\n",s->Sident);
4802-
for (lp = &fixlist::start; (p = *lp) != NULL;)
4803-
{
4804-
if (s == p->Lsymbol)
4805-
{ //dbg_printf("Found reference at x%lx\n",p->Loffset);
4810+
{
4811+
//printf("searchfixlist(%s)\n",s->Sident);
4812+
if (fixlist::start)
4813+
{
4814+
fixlist **lp = (fixlist **)fixlist::start->in(&s);
4815+
if (lp)
4816+
{ fixlist *p;
4817+
while ((p = *lp) != NULL)
4818+
{
4819+
//dbg_printf("Found reference at x%lx\n",p->Loffset);
48064820

48074821
// Determine if it is a self-relative fixup we can
48084822
// resolve directly.
@@ -4833,23 +4847,29 @@ void searchfixlist(symbol *s)
48334847
}
48344848
*lp = p->Lnext;
48354849
mem_free(p); /* remove from list */
4850+
}
4851+
if (!fixlist::nodel)
4852+
fixlist::start->del(&s);
48364853
}
4837-
else
4838-
lp = &(p->Lnext);
4839-
}
4854+
}
48404855
}
48414856

48424857
/****************************
48434858
* End of module. Output remaining fixlist elements as references
48444859
* to external symbols.
48454860
*/
48464861

4847-
void outfixlist()
4862+
STATIC int outfixlist_dg(void *parameter, void *pkey, void *pvalue)
48484863
{
4849-
//printf("outfixlist()\n");
4850-
for (fixlist *ln = fixlist::start; ln; ln = fixlist::start)
4851-
{
4852-
symbol *s = ln->Lsymbol;
4864+
//printf("outfixlist_dg(pkey = %p, pvalue = %p)\n", pkey, pvalue);
4865+
symbol *s = *(symbol **)pkey;
4866+
4867+
fixlist **plnext = (fixlist **)pvalue;
4868+
4869+
while (*plnext)
4870+
{
4871+
fixlist *ln = *plnext;
4872+
48534873
symbol_debug(s);
48544874
//printf("outfixlist '%s' offset %04x\n",s->Sident,ln->Loffset);
48554875

@@ -4902,14 +4922,29 @@ void outfixlist()
49024922
#else
49034923
reftoident(ln->Lseg,ln->Loffset,s,ln->Lval,ln->Lflags);
49044924
#endif
4905-
fixlist::start = ln->Lnext;
4925+
*plnext = ln->Lnext;
49064926
#if TERMCODE
49074927
mem_free(ln);
49084928
#endif
49094929
}
4910-
}
4930+
}
4931+
return 0;
49114932
}
49124933

4934+
void outfixlist()
4935+
{
4936+
//printf("outfixlist()\n");
4937+
if (fixlist::start)
4938+
{
4939+
fixlist::nodel++;
4940+
fixlist::start->apply(NULL, &outfixlist_dg);
4941+
fixlist::nodel--;
4942+
#if TERMCODE
4943+
delete fixlist::start;
4944+
fixlist::start = NULL;
4945+
#endif
4946+
}
4947+
}
49134948

49144949
/**********************************
49154950
*/

src/backend/ti_pvoid.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
// Copyright (c) 2011-2011 by Digital Mars
3+
// All Rights Reserved
4+
// written by Walter Bright
5+
// http://www.digitalmars.com
6+
// License for redistribution is by either the Artistic License
7+
// in artistic.txt, or the GNU General Public License in gpl.txt.
8+
// See the included readme.txt for details.
9+
10+
11+
#include <stdlib.h>
12+
13+
#include "tinfo.h"
14+
15+
16+
// void*
17+
18+
TypeInfo_Pvoid ti_pvoid;
19+
20+
const char* TypeInfo_Pvoid::toString()
21+
{
22+
return "void*";
23+
}
24+
25+
hash_t TypeInfo_Pvoid::getHash(void *p)
26+
{ void* s = *(void **)p;
27+
return (hash_t)s;
28+
}
29+
30+
int TypeInfo_Pvoid::equals(void *p1, void *p2)
31+
{
32+
void* s1 = *(void**)p1;
33+
void* s2 = *(void**)p2;
34+
35+
return s1 == s2;
36+
}
37+
38+
int TypeInfo_Pvoid::compare(void *p1, void *p2)
39+
{
40+
void* s1 = *(void**)p1;
41+
void* s2 = *(void**)p2;
42+
43+
return (s1 < s2) ? -1 : ((s1 == s2) ? 0 : 1);
44+
}
45+
46+
size_t TypeInfo_Pvoid::tsize()
47+
{
48+
return sizeof(void*);
49+
}
50+
51+
void TypeInfo_Pvoid::swap(void *p1, void *p2)
52+
{
53+
}
54+

src/backend/tinfo.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,16 @@ struct TypeInfo_Achar : TypeInfo
3737

3838
extern TypeInfo_Achar ti_achar;
3939

40+
struct TypeInfo_Pvoid : TypeInfo
41+
{
42+
const char* toString();
43+
hash_t getHash(void *p);
44+
int equals(void *p1, void *p2);
45+
int compare(void *p1, void *p2);
46+
size_t tsize();
47+
void swap(void *p1, void *p2);
48+
};
49+
50+
extern TypeInfo_Pvoid ti_pvoid;
51+
4052
#endif

src/freebsd.mak

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DMD_OBJS = \
4242
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
4343
builtin.o clone.o aliasthis.o \
4444
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
45-
imphint.o argtypes.o \
45+
imphint.o argtypes.o ti_pvoid.o \
4646
libelf.o elfobj.o
4747

4848
SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
@@ -78,6 +78,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
7878
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
7979
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
8080
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
81+
$C/ti_pvoid.c \
8182
$C/machobj.c \
8283
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
8384
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
@@ -478,6 +479,9 @@ template.o: template.c
478479
ti_achar.o: $C/tinfo.h $C/ti_achar.c
479480
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c
480481

482+
ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
483+
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c
484+
481485
tk.o: tk.c
482486
$(CC) -c $(MFLAGS) tk.c
483487

src/linux.mak

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DMD_OBJS = \
4242
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
4343
builtin.o clone.o aliasthis.o \
4444
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
45-
imphint.o argtypes.o \
45+
imphint.o argtypes.o ti_pvoid.o \
4646
libelf.o elfobj.o
4747

4848
SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
@@ -78,6 +78,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
7878
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
7979
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
8080
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
81+
$C/ti_pvoid.c \
8182
$C/machobj.c \
8283
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
8384
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
@@ -478,6 +479,9 @@ template.o: template.c
478479
ti_achar.o: $C/tinfo.h $C/ti_achar.c
479480
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c
480481

482+
ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
483+
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c
484+
481485
tk.o: tk.c
482486
$(CC) -c $(MFLAGS) tk.c
483487

src/osx.mak

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ C=backend
33
TK=tk
44
ROOT=root
55

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

13-
CC=g++ -m32 -isysroot $(SDK)
14-
#CC=g++ -m32
15+
CC=g++ $(MODEL) -isysroot $(SDK)
16+
#CC=g++ $(MODEL)
1517

1618
#OPT=-g -g3
1719
#OPT=-O2
@@ -48,7 +50,7 @@ DMD_OBJS = \
4850
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
4951
builtin.o clone.o aliasthis.o \
5052
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
51-
imphint.o argtypes.o \
53+
imphint.o argtypes.o ti_pvoid.o \
5254
libmach.o machobj.o
5355

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

475478
strtold.o: $C/strtold.c
476-
gcc -m32 -c $C/strtold.c
479+
gcc $(MODEL) -c $C/strtold.c
477480

478481
struct.o: struct.c
479482
$(CC) -c $(CFLAGS) $<
@@ -484,6 +487,9 @@ template.o: template.c
484487
ti_achar.o: $C/tinfo.h $C/ti_achar.c
485488
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c
486489

490+
ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
491+
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c
492+
487493
tk.o: tk.c
488494
$(CC) -c $(MFLAGS) tk.c
489495

src/solaris.mak

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ DMD_OBJS = \
4242
hdrgen.o delegatize.o aa.o ti_achar.o toir.o interpret.o traits.o \
4343
builtin.o clone.o aliasthis.o \
4444
man.o arrayop.o port.o response.o async.o json.o speller.o aav.o unittests.o \
45-
imphint.o argtypes.o \
45+
imphint.o argtypes.o ti_pvoid.o \
4646
libelf.o elfobj.o
4747

4848
SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
@@ -78,6 +78,7 @@ SRC = win32.mak linux.mak osx.mak freebsd.mak solaris.mak \
7878
$C/cdeflnx.h $C/outbuf.h $C/token.h $C/tassert.h \
7979
$C/elfobj.c $C/cv4.h $C/dwarf2.h $C/cpp.h $C/exh.h $C/go.h \
8080
$C/dwarf.c $C/dwarf.h $C/aa.h $C/aa.c $C/tinfo.h $C/ti_achar.c \
81+
$C/ti_pvoid.c \
8182
$C/machobj.c \
8283
$(TK)/filespec.h $(TK)/mem.h $(TK)/list.h $(TK)/vec.h \
8384
$(TK)/filespec.c $(TK)/mem.c $(TK)/vec.c $(TK)/list.c \
@@ -478,6 +479,9 @@ template.o: template.c
478479
ti_achar.o: $C/tinfo.h $C/ti_achar.c
479480
$(CC) -c $(MFLAGS) -I. $C/ti_achar.c
480481

482+
ti_pvoid.o: $C/tinfo.h $C/ti_pvoid.c
483+
$(CC) -c $(MFLAGS) -I. $C/ti_pvoid.c
484+
481485
tk.o: tk.c
482486
$(CC) -c $(MFLAGS) tk.c
483487

0 commit comments

Comments
 (0)