mirror of
https://github.com/dschmenk/PLASMA.git
synced 2025-01-22 08:31:36 +00:00
Add BRGT/BRLT FOR/NEXT optimization
This commit is contained in:
parent
c07bc8172c
commit
b8714745dd
BIN
PLASMA-BLD2.PO
BIN
PLASMA-BLD2.PO
Binary file not shown.
BIN
PLASMA-DEM2.PO
BIN
PLASMA-DEM2.PO
Binary file not shown.
BIN
PLASMA-SOS2.PO
BIN
PLASMA-SOS2.PO
Binary file not shown.
BIN
PLASMA-SYS2.PO
BIN
PLASMA-SYS2.PO
Binary file not shown.
@ -1268,6 +1268,14 @@ int crunch_seq(t_opseq **seq, int pass)
|
||||
freeops = 1;
|
||||
}
|
||||
break;
|
||||
case BRGT_CODE:
|
||||
if (opprev && (opprev->code == CONST_CODE) && (op->val <= opprev->val))
|
||||
freeops = 1;
|
||||
break;
|
||||
case BRLT_CODE:
|
||||
if (opprev && (opprev->code == CONST_CODE) && (op->val >= opprev->val))
|
||||
freeops = 1;
|
||||
break;
|
||||
case BROR_CODE:
|
||||
if (!op->val)
|
||||
freeops = -2; // Remove zero constant
|
||||
@ -1355,7 +1363,7 @@ int crunch_seq(t_opseq **seq, int pass)
|
||||
case BINARY_CODE(LE_TOKEN):
|
||||
op->val = op->val <= opnext->val ? 1 : 0;
|
||||
freeops = 2;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
// End of collapse constant operation
|
||||
if ((pass > 0) && (freeops == 0) && (op->val != 0))
|
||||
@ -1976,6 +1984,12 @@ int emit_pending_seq()
|
||||
case BRTRUE_CODE:
|
||||
emit_brtru(op->tag);
|
||||
break;
|
||||
case BRGT_CODE:
|
||||
emit_brgt(op->tag);
|
||||
break;
|
||||
case BRLT_CODE:
|
||||
emit_brlt(op->tag);
|
||||
break;
|
||||
case CODETAG_CODE:
|
||||
printf("_B%03d%c\n", op->tag, LBL);
|
||||
break;
|
||||
|
@ -66,10 +66,12 @@ typedef struct _opseq {
|
||||
#define BRTRUE_CODE 0x0322
|
||||
#define BREQ_CODE 0x0323
|
||||
#define BRNE_CODE 0x0324
|
||||
#define BRAND_CODE 0x325
|
||||
#define BROR_CODE 0x326
|
||||
#define CODETAG_CODE 0x0327
|
||||
#define NOP_CODE 0x0328
|
||||
#define BRAND_CODE 0x0325
|
||||
#define BROR_CODE 0x0326
|
||||
#define BRLT_CODE 0x0327
|
||||
#define BRGT_CODE 0x0328
|
||||
#define CODETAG_CODE 0x0329
|
||||
#define NOP_CODE 0x032A
|
||||
#define ADDLB_CODE 0x0330
|
||||
#define ADDLW_CODE 0x0331
|
||||
#define ADDAB_CODE 0x0332
|
||||
@ -95,6 +97,8 @@ typedef struct _opseq {
|
||||
#define gen_drop(seq) gen_seq(seq,DROP_CODE,0,0,0,0)
|
||||
#define gen_brand(seq,tag) gen_seq(seq,BRAND_CODE,0,tag,0,0)
|
||||
#define gen_bror(seq,tag) gen_seq(seq,BROR_CODE,0,tag,0,0)
|
||||
#define gen_brgt(seq,tag) gen_seq(seq,BRGT_CODE,0,tag,0,0)
|
||||
#define gen_brlt(seq,tag) gen_seq(seq,BRLT_CODE,0,tag,0,0)
|
||||
#define gen_brfls(seq,tag) gen_seq(seq,BRFALSE_CODE,0,tag,0,0)
|
||||
#define gen_brtru(seq,tag) gen_seq(seq,BRTRUE_CODE,0,tag,0,0)
|
||||
#define gen_brnch(seq,tag) gen_seq(seq,BRNCH_CODE,0,tag,0,0)
|
||||
|
@ -113,6 +113,16 @@ def crunch_seq(seq, pass)
|
||||
freeops = 1
|
||||
fin
|
||||
break
|
||||
is BRGT_CODE
|
||||
if opprev and (opprev->opcode == CONST_CODE) and (op=>opval <= opprev=>opval)
|
||||
freeops = 1
|
||||
fin
|
||||
break
|
||||
is BRLT_CODE
|
||||
if opprev and (opprev->opcode == CONST_CODE) and (op=>opval >= opprev=>opval)
|
||||
freeops = 1
|
||||
fin
|
||||
break
|
||||
is BROR_CODE
|
||||
if not op=>opval
|
||||
freeops = -2 // Remove zero constant
|
||||
|
@ -87,6 +87,8 @@ const BRTRUE_CODE = $4E
|
||||
const BRNCH_CODE = $50
|
||||
const BRAND_CODE = $AC
|
||||
const BROR_CODE = $AE
|
||||
const BRGT_CODE = $A0
|
||||
const BRLT_CODE = $A2
|
||||
//
|
||||
// Code tag address group
|
||||
//
|
||||
|
@ -994,9 +994,8 @@ int parse_stmnt(void)
|
||||
{
|
||||
seq = NULL;
|
||||
}
|
||||
emit_seq(toseq);
|
||||
emit_seq(fromseq);
|
||||
step > 0 ? emit_brgt(break_tag) : emit_brlt(break_tag);
|
||||
toseq = cat_seq(toseq, fromseq);
|
||||
emit_seq(step > 0 ? gen_brgt(toseq, break_tag) : gen_brlt(toseq, break_tag));
|
||||
emit_codetag(tag_for);
|
||||
if (type & LOCAL_TYPE)
|
||||
type & BYTE_TYPE ? emit_dlb(addr) : emit_dlw(addr);
|
||||
|
@ -755,9 +755,7 @@ def parse_stmnt
|
||||
else
|
||||
seq = NULL
|
||||
fin
|
||||
emit_seq(toseq)
|
||||
emit_seq(fromseq)
|
||||
if stepdir > 0; emit_brgt(break_tag); else; emit_brlt(break_tag); fin
|
||||
emit_seq(gen_oprel(cat_seq(toseq, fromseq), stepdir > 0 ?? BRGT_CODE :: BRLT_CODE, break_tag))
|
||||
emit_tag(tag_for)
|
||||
if type & LOCAL_TYPE
|
||||
if type & BYTE_TYPE; emit_dlb(addr); else; emit_dlw(addr); fin
|
||||
|
Loading…
x
Reference in New Issue
Block a user