some more tricks for better codegen

This commit is contained in:
Kyryl Melekhin
2021-08-06 09:56:11 +00:00
parent a9e6720dff
commit e71f2d2b46

54
pike.c
View File

@@ -453,6 +453,19 @@ if (--csub->ref == 0) { \
freesub = csub; \ freesub = csub; \
} \ } \
#define deccheck(nn) \
{ decref(sub) goto rec_check##nn; } \
#define fastrec(nn, list, listidx) \
if (*pc < WBEG) { \
list[listidx].sub = sub; \
list[listidx++].pc = pc; \
pc = pcs[i]; \
goto rec##nn; \
} \
subs[i++] = sub; \
goto next##nn; \
#define addthread(nn, list, listidx, _pc, _sub) \ #define addthread(nn, list, listidx, _pc, _sub) \
{ \ { \
int i = 0, *pc = _pc; \ int i = 0, *pc = _pc; \
@@ -462,16 +475,6 @@ if (--csub->ref == 0) { \
if (*pc < WBEG) { \ if (*pc < WBEG) { \
list[listidx].sub = sub; \ list[listidx].sub = sub; \
list[listidx++].pc = pc; \ list[listidx++].pc = pc; \
goto rec_check##nn; \
} \
switch(*pc) { \
case JMP: \
pc += 2 + pc[1]; \
goto rec##nn; \
case SPLIT: \
if(plist[pc - insts] == gen) { \
dec_check##nn: \
decref(sub) \
rec_check##nn: \ rec_check##nn: \
if (i) { \ if (i) { \
pc = pcs[--i]; \ pc = pcs[--i]; \
@@ -480,19 +483,28 @@ if (--csub->ref == 0) { \
} \ } \
continue; \ continue; \
} \ } \
next##nn: \
switch(*pc) { \
case JMP: \
pc += 2 + pc[1]; \
goto rec##nn; \
case SPLIT: \
if(plist[pc - insts] == gen) \
deccheck(nn) \
plist[pc - insts] = gen; \ plist[pc - insts] = gen; \
subs[i] = sub; \
sub->ref++; \ sub->ref++; \
pc += 2; \ pc += 2; \
pcs[i++] = pc + pc[-1]; \ pcs[i] = pc + pc[-1]; \
goto rec##nn; \ fastrec(nn, list, listidx) \
case RSPLIT: \ case RSPLIT: \
subs[i] = sub; \ if(plist[pc - insts] == gen) \
deccheck(nn) \
plist[pc - insts] = gen; \
sub->ref++; \ sub->ref++; \
pc += 2; \ pc += 2; \
pcs[i++] = pc; \ pcs[i] = pc; \
pc += pc[-1]; \ pc += pc[-1]; \
goto rec##nn; \ fastrec(nn, list, listidx) \
case SAVE: \ case SAVE: \
if (sub->ref > 1) { \ if (sub->ref > 1) { \
sub->ref--; \ sub->ref--; \
@@ -507,22 +519,22 @@ if (--csub->ref == 0) { \
goto rec##nn; \ goto rec##nn; \
case WBEG: \ case WBEG: \
if ((sp != s && isword(sp)) || !isword(_sp)) \ if ((sp != s && isword(sp)) || !isword(_sp)) \
goto dec_check##nn; \ deccheck(nn) \
pc++; goto rec##nn; \ pc++; goto rec##nn; \
case WEND: \ case WEND: \
if (isword(_sp)) \ if (isword(_sp)) \
goto dec_check##nn; \ deccheck(nn) \
pc++; goto rec##nn; \ pc++; goto rec##nn; \
case BOL: \ case BOL: \
if (_sp != s) { \ if (_sp != s) { \
if (!i && !listidx) \ if (!i && !listidx) \
_return(0) \ _return(0) \
goto dec_check##nn; \ deccheck(nn) \
} \ } \
pc++; goto rec##nn; \ pc++; goto rec##nn; \
case EOL: \ case EOL: \
if (*_sp) \ if (*_sp) \
goto dec_check##nn; \ deccheck(nn) \
pc++; goto rec##nn; \ pc++; goto rec##nn; \
} \ } \
} \ } \
@@ -547,7 +559,6 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
gen = prog->gen; gen = prog->gen;
goto jmp_start; goto jmp_start;
for(;; sp += l) { for(;; sp += l) {
nlistidx = 0;
gen++; uc_len(l, sp) uc_code(c, sp) gen++; uc_len(l, sp) uc_code(c, sp)
for(i = 0; i < clistidx; i++) { for(i = 0; i < clistidx; i++) {
npc = clist[i].pc; npc = clist[i].pc;
@@ -578,6 +589,7 @@ int re_pikevm(rcode *prog, const char *s, const char **subp, int nsubp)
clist = nlist; clist = nlist;
nlist = tmp; nlist = tmp;
clistidx = nlistidx; clistidx = nlistidx;
nlistidx = 0;
if (!matched) { if (!matched) {
jmp_start: jmp_start:
newsub() newsub()