1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2024-09-27 04:54:37 +00:00

On the road to 1.0: optimize MUL/DIV by POW2

This commit is contained in:
dschmenk 2017-06-01 12:23:29 -07:00
parent b19956b3ba
commit 45500004dd

View File

@ -914,12 +914,13 @@ int crunch_seq(t_opseq *seq)
t_opseq *op = seq;
int crunched = 0;
int freeops = 0;
int shiftcnt;
while (op && (opnext = op->nextop))
{
switch (op->code)
{
case CONST_CODE:
//fprintf(stderr, "CONST -> $%04X", opnext->code);
if (op->val == 1)
{
if (opnext->code == BINARY_CODE(ADD_TOKEN))
@ -971,6 +972,28 @@ int crunch_seq(t_opseq *seq)
op->code = SAW_CODE;
freeops = 1;
break;
case BINARY_CODE(MUL_TOKEN):
for (shiftcnt = 0; shiftcnt < 16; shiftcnt++)
{
if (op->val == (1 << shiftcnt))
{
op->val = shiftcnt;
opnext->code = BINARY_CODE(SHL_TOKEN);
break;
}
}
break;
case BINARY_CODE(DIV_TOKEN):
for (shiftcnt = 0; shiftcnt < 16; shiftcnt++)
{
if (op->val == (1 << shiftcnt))
{
op->val = shiftcnt;
opnext->code = BINARY_CODE(SHR_TOKEN);
break;
}
}
break;
case CONST_CODE: // Collapse constant operation
if ((opnextnext = opnext->nextop))
switch (opnextnext->code)