1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-10-06 01:55:47 +00:00

Snag a few more easy optimizations

This commit is contained in:
Dave Schmenk 2019-12-17 13:30:09 -08:00
parent ae5ea36e87
commit b81e911857
3 changed files with 63 additions and 13 deletions

View File

@ -204,5 +204,9 @@ puti(array:0); puts(" > "); puti(array:0); puts (" is ")
puts(array:0 > array:0 ?? "TRUE\n" :: "FALSE\n") puts(array:0 > array:0 ?? "TRUE\n" :: "FALSE\n")
puti(array:0); puts(" < "); puti(array:0); puts (" is ") puti(array:0); puts(" < "); puti(array:0); puts (" is ")
puts(array:0 < array:0 ?? "TRUE\n" :: "FALSE\n") puts(array:0 < array:0 ?? "TRUE\n" :: "FALSE\n")
ptr = 0 ptr = 5
puts("5*0="); puti(ptr*0); putln
puts("5*1="); puti(ptr*1); putln
puts("5*2="); puti(ptr*2); putln
puts("5/1="); puti(ptr/1); putln
done done

View File

@ -1230,6 +1230,17 @@ int crunch_seq(t_opseq **seq, int pass)
freeops = 1; freeops = 1;
break; break;
} }
if (opnext->code == BINARY_CODE(SHL_TOKEN))
{
op->code = DUP_CODE;
opnext->code == BINARY_CODE(ADD_TOKEN);
break;
}
if (opnext->code == BINARY_CODE(MUL_TOKEN) || opnext->code == BINARY_CODE(DIV_TOKEN))
{
freeops = -2;
break;
}
} }
switch (opnext->code) switch (opnext->code)
{ {
@ -1441,13 +1452,27 @@ int crunch_seq(t_opseq **seq, int pass)
} }
break; break;
case BINARY_CODE(MUL_TOKEN): case BINARY_CODE(MUL_TOKEN):
for (shiftcnt = 0; shiftcnt < 16; shiftcnt++) if (op->val == 0)
{ {
if (op->val == (1 << shiftcnt)) op->code = DROP_CODE;
opnext->code = CONST_CODE;
opnext->val = 0;
}
else if (op->val == 2)
{
op->code = DUP_CODE;
opnext->code = BINARY_CODE(ADD_TOKEN);
}
else
{
for (shiftcnt = 0; shiftcnt < 16; shiftcnt++)
{ {
op->val = shiftcnt; if (op->val == (1 << shiftcnt))
opnext->code = BINARY_CODE(SHL_TOKEN); {
break; op->val = shiftcnt;
opnext->code = BINARY_CODE(SHL_TOKEN);
break;
}
} }
} }
break; break;

View File

@ -79,6 +79,16 @@ def crunch_seq(seq, pass)
freeops = 1 freeops = 1
break break
fin fin
if nextop->opcode == SHL_CODE
op->opcode = DUP_CODE
nextop->opcode = ADD_CODE
op->opgroup = STACK_GROUP
break
fin
if nextop->opcode == MUL_CODE or nextop->opcode == DIV_CODE
freeops = -2
break
fin
fin fin
when nextop->opcode when nextop->opcode
is NEG_CODE is NEG_CODE
@ -258,13 +268,24 @@ def crunch_seq(seq, pass)
fin fin
break break
is MUL_CODE is MUL_CODE
for shiftcnt = 0 to 15 if op=>opval == 0
if op=>opval == 1 << shiftcnt op->opcode = DROP_CODE
op=>opval = shiftcnt nextop->opcode = CONST_CODE
nextop->opcode = SHL_CODE nextop->opval = 0
break nextop->opgroup = CONST_GROUP
fin elsif op=>opval == 2
next op->opcode = DUP_CODE
nextop->opcode = ADD_CODE
op->opgroup = STACK_GROUP
else
for shiftcnt = 2 to 15
if op=>opval == 1 << shiftcnt
op=>opval = shiftcnt
nextop->opcode = SHL_CODE
break
fin
next
fin
break break
is DIV_CODE is DIV_CODE
for shiftcnt = 0 to 15 for shiftcnt = 0 to 15