From da859b710a17ec33bc7255adfae4a3ebed343e61 Mon Sep 17 00:00:00 2001 From: John Brandwood Date: Fri, 13 Sep 2024 12:21:48 -0400 Subject: [PATCH 1/5] Rewrite HuCC's optimization of pre and post increment/decrement. Add a table of flags for each i-code to make checking their effects easier in the future. Start changing the i-code and macro naming scheme to allow for more clarity in their usage, and to open up more namespace to create new and very situation-specific optimizations. --- include/hucc/hucc-codegen.asm | 652 +++++++++++++++++++++++++--------- src/hucc/code.c | 245 +++++++++++-- src/hucc/defs.h | 70 +++- src/hucc/function.c | 26 +- src/hucc/optimize.c | 582 ++++++++++++++++++++++-------- src/hucc/optimize.h | 6 + 6 files changed, 1205 insertions(+), 376 deletions(-) diff --git a/include/hucc/hucc-codegen.asm b/include/hucc/hucc-codegen.asm index 0f391d3d..d57364e0 100644 --- a/include/hucc/hucc-codegen.asm +++ b/include/hucc/hucc-codegen.asm @@ -17,6 +17,42 @@ ; ; *************************************************************************** ; *************************************************************************** +; +; NAMING SCHEME FOR HuCC MACROS ... +; +; __function.parameters +; +; {parameters} is a list of alphanumeric specifiers, starting with {size} and +; followed by {where}, followed by {index} if an array, then optional {value} +; and finally ending with optional {suffix} +; +; {size} +; w : 16-bit signed int (default "int" in HuCC) +; u : 16-bit unsigned int +; b : 8-bit signed char +; c : 8-bit unsigned char (default "char" in HuCC) +; +; {where} or {index} +; i : immediate value, i.e. a decimal number +; r : HuCC primary register, made up of the Y:A cpu registers +; t : top of arithmetic stack +; m : memory, i.e. C global, static, and "-fno-recursive" variables +; s : stack, i.e. C function parameters and locals (not "-fno-recursive") +; a : array, i.e. C global, static, "-fno-recursive" arrays <= 256 bytes +; x : array index already in the X register +; y : array index already in the Y register +; +; {value} OPTIONAL +; i : immediate value, i.e. a decimal number +; z : zero value +; +; {suffix} OPTIONAL +; q : quick, used for optimized math on only 8-bit values, because all math +; is normally promoted to "int" size in C; and when optimized stores do +; not need to preserve the primary register contents +; +; *************************************************************************** +; *************************************************************************** @@ -26,6 +62,10 @@ ; *************************************************************************** ; *************************************************************************** +; ************** +; this only exists to mark the end of a C statement when the primary register +; contents are no longer needed + __fence .macro .endm @@ -961,6 +1001,314 @@ __lduba_s .macro ; __STACK +; *************************************************************************** +; *************************************************************************** +; i-codes for pre- and post- increment and decrement +; *************************************************************************** +; *************************************************************************** + +; ************** + +__incld.wm .macro + inc.l \1 + bne !+ + inc.h \1 +!: lda.l \1 + ldy.h \1 + .endm + +; ************** + +__incld.bm .macro + inc \1 + lda \1 + cly + bpl !+ + dey +!: + .endm + +; ************** + +__incld.cm .macro + inc \1 + lda \1 + cly + .endm + +; ************** + +__decld.wm .macro + lda.l \1 + bne !+ + dec.h \1 +!: dec a + sta.l \1 + ldy.h \1 + .endm + +; ************** + +__decld.bm .macro + dec \1 + lda \1 + cly + bpl !+ + dey +!: + .endm + +; ************** + +__decld.cm .macro + dec \1 + lda \1 + cly + .endm + +; ************** + +__ldinc.wm .macro + lda.l \1 + ldy.h \1 + inc.l \1 + bne !+ + inc.h \1 +!: + .endm + +; ************** + +__ldinc.bm .macro + lda \1 + cly + bpl !+ + dey +!: inc \1 + .endm + +; ************** + +__ldinc.cm .macro + lda \1 + cly + inc \1 + .endm + +; ************** + +__lddec.wm .macro + ldy.h \1 + lda.l \1 + bne !+ + dec.h \1 +!: dec.l \1 + .endm + +; ************** + +__lddec.bm .macro + lda \1 + cly + bpl !+ + dey +!: dec \1 + .endm + +; ************** + +__lddec.cm .macro + lda \1 + cly + dec \1 + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__inc.wmq .macro + inc.l \1 + bne !+ + inc.h \1 +!: + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__inc.cmq .macro + inc \1 + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__dec.wmq .macro + lda.l \1 + bne !+ + dec.h \1 +!: dec.l \1 + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__dec.cmq .macro + dec \1 + .endm + +; ************** + +__incld.ws .macro + inc.l <__stack + \1, x + bne !+ + inc.h <__stack + \1, x +!: lda.l <__stack + \1, x + ldy.h <__stack + \1, x + .endm + +; ************** + +__incld.bs .macro + inc <__stack + \1, x + lda <__stack + \1, x + cly + bpl !+ + dey +!: + .endm + +; ************** + +__incld.cs .macro + inc <__stack + \1, x + lda <__stack + \1, x + cly + .endm + +; ************** + +__decld.ws .macro + lda.l <__stack + \1, x + bne !+ + dec.h <__stack + \1, x +!: dec a + sta.l <__stack + \1, x + ldy.h <__stack + \1, x + .endm + +; ************** + +__decld.bs .macro + dec <__stack + \1, x + lda <__stack + \1, x + cly + bpl !+ + dey +!: + .endm + +; ************** + +__decld.cs .macro + dec <__stack + \1, x + lda <__stack + \1, x + cly + .endm + +; ************** + +__ldinc.ws .macro + lda.l <__stack + \1, x + ldy.h <__stack + \1, x + inc.l <__stack + \1, x + bne !+ + inc.h <__stack + \1, x +!: + .endm + +; ************** + +__ldinc.bs .macro + lda <__stack + \1, x + cly + bpl !+ + dey +!: inc <__stack + \1, x + .endm + +; ************** + +__ldinc.cs .macro + lda <__stack + \1, x + cly + inc <__stack + \1, x + .endm + +; ************** + +__lddec.ws .macro + ldy.h <__stack + \1, x + lda.l <__stack + \1, x + bne !+ + dec.h <__stack + \1, x +!: dec.l <__stack + \1, x + .endm + +; ************** + +__lddec.bs .macro + lda <__stack + \1, x + cly + bpl !+ + dey +!: dec <__stack + \1, x + .endm + +; ************** + +__lddec.cs .macro + lda <__stack + \1, x + cly + dec <__stack + \1, x + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__inc.wsq .macro + inc.l <__stack + \1, x + bne !+ + inc.h <__stack + \1, x +!: + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__inc.csq .macro + inc <__stack + \1, x + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__dec.wsq .macro + lda.l <__stack + \1, x + bne !+ + dec.h <__stack + \1, x +!: dec.l <__stack + \1, x + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__dec.csq .macro + dec <__stack + \1, x + .endm + + + ; *************************************************************************** ; *************************************************************************** ; i-codes for saving the primary register @@ -1214,81 +1562,6 @@ __negw .macro ; ************** -__incw .macro - inc.l \1 - bne !+ - inc.h \1 -!: - .endm - -; ************** - -__incb .macro - inc \1 - .endm - -; ; ************** NEW and UNIMPLEMENTED! -; -; __decw_ .macro -; lda.l \1 -; bne !+ -; dec.h \1 -; !: dec.l \1 -; .endm -; -; ; ************** NEW and UNIMPLEMENTED! -; -; __decwa_ .macro -; cmp #0 -; bne !+ -; dey -; !: dec a -; .endm -; -; __decwa2_ .macro -; sec -; sbc #2 -; say -; sbc #0 -; say -; .endm -; -; __decwm_ .macro -; lda.l \1 -; bne !+ -; dec.h \1 -; !: dec.l \1 -; .endm -; -; __decwm2_ .macro -; lda.l \1 -; bne !+ -; dec.h \1 -; !: dec.l \1 -; bne !+ -; dec.h \1 -; !: dec.l \1 -; .endm -; -; __decws_ .macro -; lda.l <__stack, x -; bne !+ -; dec.h <__stack, x -; !: dec.l <__stack, x -; .endm -; -; __decws2_ .macro -; lda.l <__stack, x -; bne !+ -; dec.h <__stack, x -; !: dec.l <__stack, x -; bne !+ -; dec.h <__stack, x -; !: dec.l <__stack, x -; .endm - -; ************** - __addws .macro ; __STACK clc adc.l <__stack, x @@ -1317,19 +1590,6 @@ __addwi .macro .endif .endm -; ; ************** -; ; pceas workaround; the regular __addwi doesn't work if the argument is -; ; symbolic because the code size changes as it is resolved. -; ; ************** -; -; __addwi_sym .macro -; clc -; adc.l #\1 -; say -; adc.h #\1 -; say -; .endm - ; ************** __addw .macro @@ -1835,29 +2095,6 @@ __mulwi .macro -; *************************************************************************** -; *************************************************************************** -; optimized i-codes for local variables on the C stack -; *************************************************************************** -; *************************************************************************** - -; ************** - -__incw_s .macro ; __STACK - inc.l <__stack + \1, x - bne !+ - inc.h <__stack + \1, x -!: - .endm - -; ************** - -__incb_s .macro ; __STACK - inc <__stack + \1, x - .endm - - - ; *************************************************************************** ; *************************************************************************** ; i-codes for 32-bit longs @@ -2490,89 +2727,90 @@ do_switchb: sty.h <__ptr ; Save hi-byte of the table address. ; ************** -__ldincw .macro - lda.l \1 - ldy.h \1 - inc.l \1 - bne - inc.h \1 -!: +__lddec.war .macro + phx + asl a + tax + ldy.h \1, x + lda.l \1, x + bne !+ + dec.h \1, x +!: dec.l \1, x + plx .endm ; ************** -__ldincb .macro - lda \1 +__lddec.uar .macro + tay + lda.l \1, y + dec a + sta.l \1, y + inc a cly - bpl !+ - dey -!: inc \1 .endm ; ************** -__ldincub .macro - lda \1 - cly - inc \1 +__dec.warq .macro + asl a + sax + ldy.l \1, x + bne !+ + dec.h \1, x +!: dec.l \1, x + tax .endm ; ************** -__lddecw .macro - ldy.h \1 - lda.l \1 - bne !+ - dec.h \1 -!: dec.l \1 +__dec.uarq .macro + sax + dec.l \1, x + tax .endm ; ************** -__lddecb .macro - lda \1 - cly - bpl !+ - dey -!: dec \1 +__st.wat .macro + stx <__sp + plx + sta.l \1, x + say + sta.h \1, x + say + ldx <__sp .endm ; ************** -__lddecub .macro - lda \1 - cly - dec \1 +__st.bat .macro + sty <__temp + ply + sta.l \1, y + ldy <__temp .endm ; ************** -__lddecwa_a .macro - phx - asl a - tax - ldy.h \1, x - lda.l \1, x - bne !+ - dec.h \1, x -!: dec.l \1, x - plx +__st.watq .macro + sty <__temp + ply + sta.l \1, y + lda <__temp + sta.h \1, y .endm ; ************** -__lddecuba_a .macro - tay - lda.l \1, y - dec a +__st.batq .macro + ply sta.l \1, y - inc a - cly .endm ; ************** -__stwa .macro +__st.wam .macro phy pha lda \2 @@ -2586,7 +2824,7 @@ __stwa .macro ; ************** -__stba .macro +__st.bam .macro phy ldy \2 sta \1, y @@ -2595,17 +2833,93 @@ __stba .macro ; ************** -__stpwaq .macro - sty <__temp - ply - sta.l \1, y - lda <__temp +__st.wamq .macro + pha + lda \2 + asl a + say sta.h \1, y + pla + sta.l \1, y .endm ; ************** -__stpbaq .macro - ply - sta.l \1, y +__st.bamq .macro + ldy \2 + sta \1, y + .endm + +; ************** + +__add.wam .macro + stx <__sp + tax + lda \2 + asl a + sax + clc + adc.l \1, x + say + adc.h \1, x + say + ldx <__sp + .endm + +; ************** + +__add.bam .macro + stx <__sp + ldx \2 + bit.l \1, x + bpl !+ + dey +!: clc + adc.l \1, x + bcc !+ + iny +!: ldx <__sp + .endm + +; ************** + +__add.uam .macro + stx <__sp + ldx \2 + clc + adc.l \1, x + bcc !+ + iny +!: ldx <__sp + .endm + +; ************** + +__add.uamq .macro + ldy \2 + clc + adc.l \1, y + .endm + +; ************** + +__sub.bam .macro + stx <__sp + ldx \2 + bit.l \1, x + bpl !+ + iny +!: sec + sbc.l \1, x + bcs !+ + dey +!: ldx <__sp + .endm + +; ************** + +__sub.bamq .macro + ldy \2 +!: sec + sbc.l \1, y .endm diff --git a/src/hucc/code.c b/src/hucc/code.c index 32c4a04e..10ff70f5 100644 --- a/src/hucc/code.c +++ b/src/hucc/code.c @@ -246,7 +246,7 @@ void dump_ins (INS *tmp) */ void gen_code (INS *tmp) { - int code; + enum ICODE code; int type; intptr_t data; int imm_type; @@ -282,6 +282,11 @@ void gen_code (INS *tmp) case T_SYMBOL: outsymbol((SYMBOL *)data); break; + case T_STRING: + outconst(litlab); + outbyte('+'); + outdec((int)data); + break; } outstr(", "); outstr(tmp->arg[0]); @@ -776,6 +781,216 @@ void gen_code (INS *tmp) // nl(); // break; + /* i-codes for pre- and post- increment and decrement */ + + case X_INCLD_WM: + ot("__incld.wm\t"); + out_type(type, data); + nl(); + break; + + case X_INCLD_BM: + ot("__incld.bm\t"); + out_type(type, data); + nl(); + break; + + case X_INCLD_CM: + ot("__incld.cm\t"); + out_type(type, data); + nl(); + break; + + case X_DECLD_WM: + ot("__decld.wm\t"); + out_type(type, data); + nl(); + break; + + case X_DECLD_BM: + ot("__decld.bm\t"); + out_type(type, data); + nl(); + break; + + case X_DECLD_CM: + ot("__decld.cm\t"); + out_type(type, data); + nl(); + break; + + case X_LDINC_WM: + ot("__ldinc.wm\t"); + out_type(type, data); + nl(); + break; + + case X_LDINC_BM: + ot("__ldinc.bm\t"); + out_type(type, data); + nl(); + break; + + case X_LDINC_CM: + ot("__ldinc.cm\t"); + out_type(type, data); + nl(); + break; + + case X_LDDEC_WM: + ot("__lddec.wm\t"); + out_type(type, data); + nl(); + break; + + case X_LDDEC_BM: + ot("__lddec.bm\t"); + out_type(type, data); + nl(); + break; + + case X_LDDEC_CM: + ot("__lddec.cm\t"); + out_type(type, data); + nl(); + break; + + case X_INC_WMQ: + ot("__inc.wmq\t"); + out_type(type, data); + nl(); + break; + + case X_INC_CMQ: + ot("__inc.cmq\t"); + out_type(type, data); + nl(); + break; + + case X_DEC_WMQ: + ot("__dec.wmq\t"); + out_type(type, data); + nl(); + break; + + case X_DEC_CMQ: + ot("__dec.cmq\t"); + out_type(type, data); + nl(); + break; + + case X_INCLD_WS: + ot("__incld.ws\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_INCLD_BS: + ot("__incld.bs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_INCLD_CS: + ot("__incld.cs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_DECLD_WS: + ot("__decld.ws\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_DECLD_BS: + ot("__decld.bs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_DECLD_CS: + ot("__decld.cs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_LDINC_WS: + ot("__ldinc.ws\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_LDINC_BS: + ot("__ldinc.bs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_LDINC_CS: + ot("__ldinc.cs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_LDDEC_WS: + ot("__lddec.ws\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_LDDEC_BS: + ot("__lddec.bs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_LDDEC_CS: + ot("__lddec.cs\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_INC_WSQ: + ot("__inc.wsq\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_INC_CSQ: + ot("__inc.csq\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_DEC_WSQ: + ot("__dec.wsq\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + + case X_DEC_CSQ: + ot("__dec.csq\t"); + outdec((int)data); + outlocal(tmp->sym); + nl(); + break; + /* i-codes for saving the primary register */ case I_STWZ: @@ -942,18 +1157,6 @@ void gen_code (INS *tmp) ol("__negw"); break; - case I_INCW: - ot("__incw\t\t"); - out_addr(type, data); - nl(); - break; - - case I_INCB: - ot("__incb\t\t"); - out_addr(type, data); - nl(); - break; - case I_ADDWS: ol("__addws"); break; @@ -1126,22 +1329,6 @@ void gen_code (INS *tmp) nl(); break; - /* optimized i-codes for local variables on the C stack */ - - case X_INCW_S: - ot("__incw_s\t"); - outdec((int)data); - outlocal(tmp->sym); - nl(); - break; - - case X_INCB_S: - ot("__incb_s\t"); - outdec((int)data); - outlocal(tmp->sym); - nl(); - break; - default: gen_asm(tmp); break; diff --git a/src/hucc/defs.h b/src/hucc/defs.h index b333758d..20bd7ba0 100644 --- a/src/hucc/defs.h +++ b/src/hucc/defs.h @@ -32,7 +32,12 @@ #define T_PAL 11 #define T_LITERAL 12 -/* basic pseudo instructions */ + +/* i-code pseudo instructions */ +/* + * N.B. this i-code enum list MUST be kept updated and in the same order + * as the table of i-code flag information in optimize.c + */ enum ICODE { /* i-code that retires the primary register contents */ @@ -109,15 +114,19 @@ enum ICODE { I_LDWI, I_LEA_S, + I_LDW, I_LDB, I_LDUB, + I_LDWP, I_LDBP, I_LDUBP, + X_LDWA_A, X_LDBA_A, X_LDUBA_A, + X_LDW_S, X_LDB_S, X_LDUB_S, @@ -126,6 +135,52 @@ enum ICODE { X_LDPBA_A, X_LDPUBA_A, + /* i-codes for pre- and post- increment and decrement */ + + X_INCLD_WM, + X_INCLD_BM, + X_INCLD_CM, + + X_DECLD_WM, + X_DECLD_BM, + X_DECLD_CM, + + X_LDINC_WM, + X_LDINC_BM, + X_LDINC_CM, + + X_LDDEC_WM, + X_LDDEC_BM, + X_LDDEC_CM, + + X_INC_WMQ, + X_INC_CMQ, + + X_DEC_WMQ, + X_DEC_CMQ, + + X_INCLD_WS, + X_INCLD_BS, + X_INCLD_CS, + + X_DECLD_WS, + X_DECLD_BS, + X_DECLD_CS, + + X_LDINC_WS, + X_LDINC_BS, + X_LDINC_CS, + + X_LDDEC_WS, + X_LDDEC_BS, + X_LDDEC_CS, + + X_INC_WSQ, + X_INC_CSQ, + + X_DEC_WSQ, + X_DEC_CSQ, + /* i-codes for saving the primary register */ I_STWZ, @@ -160,9 +215,6 @@ enum ICODE { I_COMW, I_NEGW, - I_INCW, - I_INCB, - I_ADDWS, I_ADDWI, I_ADDW, @@ -205,11 +257,6 @@ enum ICODE { I_MULWI, - /* optimized i-codes for local variables on the C stack */ - - X_INCW_S, - X_INCB_S, - /* i-codes for 32-bit longs */ X_LDD_I, @@ -311,7 +358,6 @@ struct tag_symbol { #define PUBLIC 1 #define AUTO 2 #define EXTERN 3 - #define STATIC 4 #define LSTATIC 5 #define DEFAUTO 6 @@ -404,12 +450,12 @@ struct macro { /* pseudo instruction structure */ typedef struct { - int code; + enum ICODE code; int type; intptr_t data; int imm_type; intptr_t imm_data; - char *arg[3]; + const char *arg[3]; SYMBOL *sym; } INS; diff --git a/src/hucc/function.c b/src/hucc/function.c index aa15407d..50ad7b5a 100644 --- a/src/hucc/function.c +++ b/src/hucc/function.c @@ -857,23 +857,8 @@ void arg_flush (int arg, int adj) } } else { - switch (ins->code) { - case I_LEA_S: - case X_LDW_S: - case X_LDB_S: - case X_LDUB_S: - case X_STWI_S: - case X_STBI_S: - case X_STB_S: - case X_STW_S: - case X_INCW_S: - case X_ADDW_S: - case X_ADDUB_S: - case X_LDD_S_W: - case X_LDD_S_B: + if (icode_flags[ins->code] & IS_SPREL) ins->data -= adj; - break; - } } /* flush */ @@ -881,6 +866,10 @@ void arg_flush (int arg, int adj) } } +/* + * convert a function argument into a farptr + * + */ void arg_to_fptr (struct fastcall *fast, int i, int arg, int adj) { INS *ins, tmp; @@ -944,6 +933,8 @@ void arg_to_fptr (struct fastcall *fast, int i, int arg, int adj) case I_LDWP: err = 1; break; + default: + break; } } @@ -992,6 +983,9 @@ void arg_to_fptr (struct fastcall *fast, int i, int arg, int adj) } } +/* + * + */ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) { INS *ins, *ptr, tmp; diff --git a/src/hucc/optimize.c b/src/hucc/optimize.c index 2376a509..c156755f 100644 --- a/src/hucc/optimize.c +++ b/src/hucc/optimize.c @@ -24,6 +24,7 @@ #include "sym.h" #include "code.h" #include "function.h" +#include "optimize.h" #include "io.h" #include "error.h" @@ -38,6 +39,241 @@ #pragma GCC diagnostic ignored "-Wstringop-overread" #endif +/* flag information for each of the i-code instructions */ +/* + * N.B. this table MUST be kept updated and in the same order as the i-code + * enum list in defs.h + */ +unsigned char icode_flags[] = { + 0, + + /* i-code that retires the primary register contents */ + + /* I_FENCE */ 0, + + /* i-codes for handling farptr */ + + /* I_FARPTR */ 0, + /* I_FARPTR_I */ 0, + /* I_FARPTR_GET */ 0, + /* I_FGETW */ 0, + /* I_FGETB */ 0, + /* I_FGETUB */ 0, + + /* i-codes for interrupts */ + + /* I_SEI */ 0, + /* I_CLI */ 0, + + /* i-codes for calling functions */ + + /* I_MACRO */ 0, + /* I_CALL */ 0, + /* I_CALLP */ 0, + /* I_JSR */ 0, + + /* i-codes for C functions and the C parameter stack */ + + /* I_ENTER */ 0, + /* I_LEAVE */ 0, + /* I_GETACC */ 0, + /* I_SAVESP */ 0, + /* I_LOADSP */ 0, + /* I_MODSP */ 0, + /* I_PUSHW */ 0, + /* I_POPW */ 0, + /* I_SPUSHW */ 0, + /* I_SPUSHB */ 0, + /* I_SPOPW */ 0, + /* I_SPOPB */ 0, + + /* i-codes for handling boolean tests and branching */ + + /* I_SWITCHW */ 0, + /* I_SWITCHB */ 0, + /* I_CASE */ 0, + /* I_ENDCASE */ 0, + /* I_LABEL */ 0, + /* I_ALIAS */ 0, + /* I_BRA */ 0, + /* I_DEF */ 0, + /* I_CMPW */ 0, + /* I_CMPB */ 0, + /* X_CMPWI_EQ */ 0, + /* X_CMPWI_NE */ 0, + /* I_NOTW */ 0, + /* I_TSTW */ 0, + /* I_BFALSE */ 0, + /* I_BTRUE */ 0, + /* X_TZB */ 0, + /* X_TZBP */ 0, + /* X_TZB_S */ IS_SPREL, + /* X_TZW */ 0, + /* X_TZWP */ 0, + /* X_TZW_S */ IS_SPREL, + /* X_TNZB */ 0, + /* X_TNZBP */ 0, + /* X_TNZB_S */ IS_SPREL, + /* X_TNZW */ 0, + /* X_TNZWP */ 0, + /* X_TNZW_S */ IS_SPREL, + + /* i-codes for loading the primary register */ + + /* I_LDWI */ 0, + /* I_LEA_S */ IS_SPREL, + + /* I_LDW */ 0, + /* I_LDB */ 0, + /* I_LDUB */ 0, + + /* I_LDWP */ 0, + /* I_LDBP */ 0, + /* I_LDUBP */ 0, + + /* X_LDWA_A */ 0, + /* X_LDBA_A */ 0, + /* X_LDUBA_A */ 0, + + /* X_LDW_S */ IS_SPREL, + /* X_LDB_S */ IS_SPREL, + /* X_LDUB_S */ IS_SPREL, + + /* X_LDPWA_A */ 0, + /* X_LDPBA_A */ 0, + /* X_LDPUBA_A */ 0, + + /* i-codes for pre- and post- increment and decrement */ + + /* X_INCLD_WM */ 0, + /* X_INCLD_BM */ 0, + /* X_INCLD_CM */ 0, + + /* X_DECLD_WM */ 0, + /* X_DECLD_BM */ 0, + /* X_DECLD_CM */ 0, + + /* X_LDINC_WM */ 0, + /* X_LDINC_BM */ 0, + /* X_LDINC_CM */ 0, + + /* X_LDDEC_WM */ 0, + /* X_LDDEC_BM */ 0, + /* X_LDDEC_CM */ 0, + + /* X_INC_WMQ */ 0, + /* X_INC_CMQ */ 0, + + /* X_DEC_WMQ */ 0, + /* X_DEC_CMQ */ 0, + + /* X_INCLD_WS */ IS_SPREL, + /* X_INCLD_BS */ IS_SPREL, + /* X_INCLD_CS */ IS_SPREL, + + /* X_DECLD_WS */ IS_SPREL, + /* X_DECLD_BS */ IS_SPREL, + /* X_DECLD_CS */ IS_SPREL, + + /* X_LDINC_WS */ IS_SPREL, + /* X_LDINC_BS */ IS_SPREL, + /* X_LDINC_CS */ IS_SPREL, + + /* X_LDDEC_WS */ IS_SPREL, + /* X_LDDEC_BS */ IS_SPREL, + /* X_LDDEC_CS */ IS_SPREL, + + /* X_INC_WSQ */ IS_SPREL, + /* X_INC_CSQ */ IS_SPREL, + + /* X_DEC_WSQ */ IS_SPREL, + /* X_DEC_CSQ */ IS_SPREL, + + /* i-codes for saving the primary register */ + + /* I_STWZ */ 0, + /* I_STBZ */ 0, + /* I_STWI */ 0, + /* I_STBI */ 0, + /* I_STWIP */ 0, + /* I_STBIP */ 0, + /* I_STW */ 0, + /* I_STB */ 0, + /* I_STWP */ 0, + /* I_STBP */ 0, + /* I_STWPS */ 0, + /* I_STBPS */ 0, + /* X_STWI_S */ IS_SPREL, + /* X_STBI_S */ IS_SPREL, + /* X_STW_S */ IS_SPREL, + /* X_STB_S */ IS_SPREL, + + /* X_INDEXW */ 0, + /* X_INDEXB */ 0, + /* X_STWAS */ 0, + /* X_STBAS */ 0, + + /* i-codes for extending the primary register */ + + /* I_EXTW */ 0, + /* I_EXTUW */ 0, + + /* i-codes for math with the primary register */ + + /* I_COMW */ 0, + /* I_NEGW */ 0, + + /* I_ADDWS */ 0, + /* I_ADDWI */ 0, + /* I_ADDW */ 0, + /* I_ADDUB */ 0, + /* X_ADDW_S */ IS_SPREL, + /* X_ADDUB_S */ IS_SPREL, + + /* I_ADDBI_P */ 0, + + /* I_SUBWS */ 0, + /* I_SUBWI */ 0, + /* I_SUBW */ 0, + /* I_SUBUB */ 0, + + /* I_ISUBWI */ 0, + + /* I_ANDWS */ 0, + /* I_ANDWI */ 0, + /* I_ANDW */ 0, + /* I_ANDUB */ 0, + + /* I_EORWS */ 0, + /* I_EORWI */ 0, + /* I_EORW */ 0, + /* I_EORUB */ 0, + + /* I_ORWS */ 0, + /* I_ORWI */ 0, + /* I_ORW */ 0, + /* I_ORUB */ 0, + + /* I_ASLWS */ 0, + /* I_ASLWI */ 0, + /* I_ASLW */ 0, + + /* I_ASRWI */ 0, + /* I_ASRW */ 0, + + /* I_LSRWI */ 0, + + /* I_MULWI */ 0, + + /* i-codes for 32-bit longs */ + + /* X_LDD_I */ 0, + /* X_LDD_W */ 0, + /* X_LDD_B */ 0, + /* X_LDD_S_W */ IS_SPREL, + /* X_LDD_S_B */ IS_SPREL +}; + /* defines */ #define Q_SIZE 16 @@ -70,47 +306,9 @@ int cmp_operands (INS *p1, INS *p2) return (1); } - -static int is_load (INS *i) +inline bool is_sprel (INS *i) { - return (i->code == I_LDWI || - i->code == I_LDW || - i->code == I_LDB || - i->code == I_LDUB || - i->code == I_LDWP || - i->code == I_LDBP || - i->code == I_LDUBP || -// i->code == X_LDWA_A || -// i->code == X_LDBA_A || -// i->code == X_LDUBA_A || - i->code == X_LDW_S || - i->code == X_LDB_S || - i->code == X_LDUB_S || - i->code == X_LDD_I || - i->code == X_LDD_S_W || - i->code == X_LDD_S_B); -} - -static int is_sprel (INS *i) -{ - return (i->code == I_LEA_S || - i->code == X_LDW_S || - i->code == X_LDB_S || - i->code == X_LDUB_S || - i->code == X_STWI_S || - i->code == X_STBI_S || - i->code == X_STW_S || - i->code == X_STB_S || - i->code == X_INCW_S || - i->code == X_INCB_S || - i->code == X_ADDW_S || - i->code == X_ADDUB_S || - i->code == X_TZW_S || - i->code == X_TZB_S || - i->code == X_TNZW_S || - i->code == X_TNZB_S || - i->code == X_LDD_S_W || - i->code == X_LDD_S_B); + return (icode_flags[i->code] & IS_SPREL); } inline bool is_small_array (SYMBOL *sym) @@ -195,14 +393,87 @@ void push_ins (INS *ins) /* * __getacc --> * __fence + * + * __addwi / __subwi --> + * __fence */ if ((q_nb >= 2) && - (p[1]->code == I_GETACC) + (p[1]->code == I_ADDWI || + p[1]->code == I_SUBWI || + p[1]->code == I_GETACC) ) { nb = 2; } + /* + * __ldinc_wm / __incld_wm --> __inc_wm + * __fence + * + * __lddec_wm / __decld_wm --> __dec_wm + * __fence + * + * unused pre-increment or post-increment value + * unused pre-decrement or post-decrement value + */ + else if + ((q_nb >= 2) && + (p[1]->code == X_INCLD_WM || + p[1]->code == X_INCLD_BM || + p[1]->code == X_INCLD_CM || + p[1]->code == X_LDINC_WM || + p[1]->code == X_LDINC_BM || + p[1]->code == X_LDINC_CM || + p[1]->code == X_DECLD_WM || + p[1]->code == X_DECLD_BM || + p[1]->code == X_DECLD_CM || + p[1]->code == X_LDDEC_WM || + p[1]->code == X_LDDEC_BM || + p[1]->code == X_LDDEC_CM || + p[1]->code == X_INCLD_WS || + p[1]->code == X_INCLD_BS || + p[1]->code == X_INCLD_CS || + p[1]->code == X_LDINC_WS || + p[1]->code == X_LDINC_BS || + p[1]->code == X_LDINC_CS || + p[1]->code == X_DECLD_WS || + p[1]->code == X_DECLD_BS || + p[1]->code == X_DECLD_CS || + p[1]->code == X_LDDEC_WS || + p[1]->code == X_LDDEC_BS || + p[1]->code == X_LDDEC_CS) + ) { + /* replace code */ + switch (p[1]->code) { + case X_INCLD_WM: + case X_LDINC_WM: p[1]->code = X_INC_WMQ; break; + case X_INCLD_BM: + case X_INCLD_CM: + case X_LDINC_BM: + case X_LDINC_CM: p[1]->code = X_INC_CMQ; break; + case X_DECLD_WM: + case X_LDDEC_WM: p[1]->code = X_DEC_WMQ; break; + case X_DECLD_BM: + case X_DECLD_CM: + case X_LDDEC_BM: + case X_LDDEC_CM: p[1]->code = X_DEC_CMQ; break; + case X_INCLD_WS: + case X_LDINC_WS: p[1]->code = X_INC_WSQ; break; + case X_INCLD_BS: + case X_INCLD_CS: + case X_LDINC_BS: + case X_LDINC_CS: p[1]->code = X_INC_CSQ; break; + case X_DECLD_WS: + case X_LDDEC_WS: p[1]->code = X_DEC_WSQ; break; + case X_DECLD_BS: + case X_DECLD_CS: + case X_LDDEC_BS: + case X_LDDEC_CS: p[1]->code = X_DEC_CSQ; break; + default: abort(); + } + nb = 1; + } + /* flush queue */ if (nb) { q_wr -= nb; @@ -385,54 +656,6 @@ void push_ins (INS *ins) nb = 3; } - /* - * __ldw_s i --> __ldw/b/ub_s i - * __addwi 1 __incw/b_s i - * __stw_s i - * __subwi 1 - */ - else if - ((p[0]->code == I_SUBWI) && - (p[1]->code == X_STW_S) && - (p[2]->code == I_ADDWI) && - (p[3]->code == X_LDW_S) && - - (p[0]->data == 1) && - (p[2]->data == 1) && - (p[1]->data == p[3]->data) && - (p[1]->data < 255) - ) { - /* replace code */ - p[2]->code = X_INCW_S; - p[2]->data = p[3]->data; - p[2]->sym = p[3]->sym; - nb = 2; - } - - /* - * __ldb/ub_s i --> __ldb/ub_s i - * __addwi 1 __incw/b_s i - * __stb_s i - * __subwi 1 - */ - else if - ((p[0]->code == I_SUBWI) && - (p[1]->code == X_STB_S) && - (p[2]->code == I_ADDWI) && - (p[3]->code == X_LDB_S || - p[3]->code == X_LDUB_S) && - (p[0]->data == 1) && - (p[2]->data == 1) && - (p[1]->data == p[3]->data) && - (p[1]->data < 255) - ) { - /* replace code */ - p[2]->code = X_INCB_S; - p[2]->data = p[3]->data; - p[2]->sym = p[3]->sym; - nb = 2; - } - /* * __ldwi i --> __ldwi i * j * __pushw @@ -834,73 +1057,74 @@ void push_ins (INS *ins) } /* - * __ldw/b/ub n --> __incw/b n - * __addwi 1 __ldw/b/ub n - * __stw/b/ub n + * __ld{w/b/c} n --> __incld_{w/b/c}m n + * __addwi 1 + * __st{w/c} n * - * is this a pre-increment? + * __ld{w/b/c} n --> __decld_{w/b/c}m n + * __subwi 1 + * __st{w/c} n + * + * pre-increment, post-increment, + * pre-decrement, post-decrement! */ else if - ((p[0]->code == I_STW || - p[0]->code == I_STB) && - (p[1]->code == I_ADDWI) && + ((p[1]->code == I_ADDWI || + p[1]->code == I_SUBWI) && (p[1]->type == T_VALUE) && (p[1]->data == 1) && - + (p[0]->code == I_STW || + p[0]->code == I_STB) && (p[2]->code == I_LDW || p[2]->code == I_LDB || p[2]->code == I_LDUB) && - (cmp_operands(p[0], p[2]) == 1) + (p[0]->type == p[2]->type) && + (p[0]->data == p[2]->data) +// (cmp_operands(p[0], p[2]) == 1) ) { /* replace code */ - p[1]->code = p[2]->code; - p[1]->type = p[2]->type; - p[1]->data = p[2]->data; - p[2]->code = (p[0]->code == I_STW) ? I_INCW : I_INCB; - nb = 1; + switch (p[2]->code) { + case I_LDW: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_WM : X_DECLD_WM; break; + case I_LDB: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_BM : X_DECLD_BM; break; + case I_LDUB: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_CM : X_DECLD_CM; break; + default: break; + } + nb = 2; } /* - * __incw n --> __ldw n - * __ldw n __incw n + * __ld{w/b/c}_s n --> __incld_{w/b/c}s n + * __addwi 1 + * __st{w/c}_s n + * + * __ld{w/b/c}_s n --> __decld_{w/b/c}s n * __subwi 1 + * __st{w/c}_s n + * + * C pre-increment, post-increment, + * C pre-decrement, post-decrement! */ else if - (((p[0]->code == I_SUBWI) && - (p[0]->type == T_VALUE) && - (p[0]->data == 1)) && - - (p[1]->code == I_LDW) && - (p[2]->code == I_INCW) && - (cmp_operands(p[1], p[2]) == 1) + ((p[1]->code == I_ADDWI || + p[1]->code == I_SUBWI) && + (p[1]->type == T_VALUE) && + (p[1]->data == 1) && + (p[0]->code == X_STW_S || + p[0]->code == X_STB_S) && + (p[2]->code == X_LDW_S || + p[2]->code == X_LDB_S || + p[2]->code == X_LDUB_S) && + (p[0]->type == p[2]->type) && + (p[0]->data == p[2]->data) ) { /* replace code */ - p[2]->code = p[1]->code; - p[2]->type = p[1]->type; - p[2]->data = p[1]->data; - p[1]->code = I_INCW; - nb = 1; - } - - /* - * __incb n --> __ldb/ub n - * __ldb/ub n __incb n - * __subwi 1 - */ - else if - (((p[0]->code == I_SUBWI) && - (p[0]->type == T_VALUE) && - (p[0]->data == 1)) && - - (p[1]->code == I_LDB || p[1]->code == I_LDUB) && - (p[2]->code == I_INCB) && - (cmp_operands(p[1], p[2]) == 1)) { - /* replace code */ - p[2]->code = p[1]->code; - p[2]->type = p[1]->type; - p[2]->data = p[1]->data; - p[1]->code = I_INCB; - nb = 1; + switch (p[2]->code) { + case X_LDW_S: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_WS : X_DECLD_WS; break; + case X_LDB_S: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_BS : X_DECLD_BS; break; + case X_LDUB_S: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_CS : X_DECLD_CS; break; + default: break; + } + nb = 2; } /* @@ -1492,28 +1716,77 @@ void push_ins (INS *ins) } /* - * subwi/addwi i --> is_load() - * is_load() + * __decld_{w/b/c}m n --> __lddec_{w/b/c}m n + * __addwi 1 * - * This is a frequent case in which the result - * of a post-increment or decrement is not used. + * __decld_{w/b/c}s n --> __lddec_{w/b/c}s n + * __addwi 1 + * + * C post-decrement! */ else if - ((p[1]->code == I_SUBWI || - p[1]->code == I_ADDWI) && - (p[1]->type == T_VALUE) && - (is_load(p[0])) && - (p[0]->type != X_LDWA_A) && - (p[0]->type != X_LDBA_A) && - (p[0]->type != X_LDUBA_A) + ((p[0]->code == I_ADDWI) && + (p[0]->type == T_VALUE) && + (p[0]->data == 1) && + (p[1]->code == X_DECLD_WM || + p[1]->code == X_DECLD_BM || + p[1]->code == X_DECLD_CM || + p[1]->code == X_DECLD_WS || + p[1]->code == X_DECLD_BS || + p[1]->code == X_DECLD_CS) ) { - *p[1] = *p[0]; + /* replace code */ + switch (p[1]->code) { + case X_DECLD_WM: p[1]->code = X_LDDEC_WM; break; + case X_DECLD_BM: p[1]->code = X_LDDEC_BM; break; + case X_DECLD_CM: p[1]->code = X_LDDEC_CM; break; + case X_DECLD_WS: p[1]->code = X_LDDEC_WS; break; + case X_DECLD_BS: p[1]->code = X_LDDEC_BS; break; + case X_DECLD_CS: p[1]->code = X_LDDEC_CS; break; + default: break; + } + nb = 1; + } + + /* + * __incld_{w/b/c}m n --> __ldinc_{w/b/c}m n + * __subwi 1 + * + * __incld_{w/b/c}s n --> __ldinc_{w/b/c}s n + * __subwi 1 + * + * C post-increment! + */ + else if + ((p[0]->code == I_SUBWI) && + (p[0]->type == T_VALUE) && + (p[0]->data == 1) && + (p[1]->code == X_INCLD_WM || + p[1]->code == X_INCLD_BM || + p[1]->code == X_INCLD_CM || + p[1]->code == X_INCLD_WS || + p[1]->code == X_INCLD_BS || + p[1]->code == X_INCLD_CS) + ) { + /* replace code */ + switch (p[1]->code) { + case X_INCLD_WM: p[1]->code = X_LDINC_WM; break; + case X_INCLD_BM: p[1]->code = X_LDINC_BM; break; + case X_INCLD_CM: p[1]->code = X_LDINC_CM; break; + case X_INCLD_WS: p[1]->code = X_LDINC_WS; break; + case X_INCLD_BS: p[1]->code = X_LDINC_BS; break; + case X_INCLD_CS: p[1]->code = X_LDINC_CS; break; + default: break; + } nb = 1; } +#if 0 /* * __stwi 0 --> __stwz * is_load() + * + * BETTER HANDLED WITH I_FENCE! */ else if ((p[1]->code == I_STWI) && @@ -1527,6 +1800,8 @@ void push_ins (INS *ins) /* * __stbi 0 --> __stwz * is_load() + * + * BETTER HANDLED WITH I_FENCE! */ else if ((p[1]->code == I_STBI) && @@ -1536,6 +1811,7 @@ void push_ins (INS *ins) ) { p[1]->code = I_STBZ; } +#endif /* flush queue */ if (nb) { @@ -1664,6 +1940,8 @@ void push_ins (INS *ins) case I_PUSHW: offset -= 2; break; + default: + break; } /* check offset */ @@ -1901,6 +2179,7 @@ void push_ins (INS *ins) nb = 1; } +#if 0 /* * __pushw --> __stw __ptr * @@ -1908,6 +2187,8 @@ void push_ins (INS *ins) * * This cannot be done earlier because it screws up * the reordering optimization above. + * + * THIS IS VERY RARE, REMOVE IT FOR NOW AND RETHINK IT */ else if ((p[0]->code == I_STBPS || @@ -1927,6 +2208,7 @@ void push_ins (INS *ins) p[0]->code = I_STWP; q_ins[q_wr].type = T_PTR; } +#endif /* flush queue */ if (nb) { diff --git a/src/hucc/optimize.h b/src/hucc/optimize.h index ca6a1943..1d293afa 100644 --- a/src/hucc/optimize.h +++ b/src/hucc/optimize.h @@ -6,6 +6,12 @@ #ifndef _OPTIMIZE_H #define _OPTIMIZE_H +/* bit-flag definitions for the i-code instructions */ +#define IS_SPREL 1 + +/* flag information for each of the i-code instructions */ +extern unsigned char icode_flags[]; + void push_ins (INS *ins); void flush_ins (void); void flush_ins_label (int nextlabel); From 53b94141c9c9c61458e6472b9052b15d8f9bbeb9 Mon Sep 17 00:00:00 2001 From: John Brandwood Date: Sat, 14 Sep 2024 11:12:33 -0400 Subject: [PATCH 2/5] Add HuCC optimizations for "array[index]" pre and post increment/decrement. Also make a small size improvement in writes to "array[index]". --- include/hucc/hucc-codegen.asm | 443 +++++++++++++++++----------------- src/hucc/code.c | 136 +++++++++-- src/hucc/defs.h | 42 +++- src/hucc/optimize.c | 168 ++++++++++--- 4 files changed, 509 insertions(+), 280 deletions(-) diff --git a/include/hucc/hucc-codegen.asm b/include/hucc/hucc-codegen.asm index d57364e0..c81663eb 100644 --- a/include/hucc/hucc-codegen.asm +++ b/include/hucc/hucc-codegen.asm @@ -849,7 +849,7 @@ __ldubp .macro ; ************** -__ldwa_a .macro +__ld.war .macro asl a tay lda.h \1, y @@ -860,7 +860,7 @@ __ldwa_a .macro ; ************** -__ldba_a .macro +__ld.bar .macro tay lda \1, y cly @@ -871,7 +871,7 @@ __ldba_a .macro ; ************** -__lduba_a .macro +__ld.car .macro tay lda \1, y cly @@ -879,7 +879,7 @@ __lduba_a .macro ; ************** -__ldwa_m .macro +__ld.wam .macro lda \2 asl a tay @@ -891,7 +891,7 @@ __ldwa_m .macro ; ************** -__ldba_m .macro +__ld.bam .macro ldy \2 lda \1, y cly @@ -902,7 +902,7 @@ __ldba_m .macro ; ************** -__lduba_m .macro +__ld.cam .macro ldy \2 lda \1, y cly @@ -910,8 +910,10 @@ __lduba_m .macro ; ************** ; special load for when array writes are optimized +; the cpu stack is balanced with an __st.wat -__ldpwa_a .macro +__ldp.war .macro + phx asl a tay phy @@ -923,8 +925,10 @@ __ldpwa_a .macro ; ************** ; special load for when array writes are optimized +; the cpu stack is balanced with an __st.cat -__ldpba_a .macro +__ldp.bar .macro + phx tay phy lda \1, y @@ -936,8 +940,10 @@ __ldpba_a .macro ; ************** ; special load for when array writes are optimized +; the cpu stack is balanced with an __st.cat -__ldpuba_a .macro +__ldp.car .macro + phx tay phy lda \1, y @@ -1307,6 +1313,202 @@ __dec.csq .macro dec <__stack + \1, x .endm +; ************** + +__incld.war .macro + phx + asl a + tax + inc.l \1, x + bne !+ + inc.h \1, x +!: lda.l \1, x + ldy.h \1, x + plx + .endm + +; ************** + +__incld.bar .macro + tay + lda \1, y + inc a + sta \1, y + cly + bpl !+ + dey +!: + .endm + +; ************** + +__incld.car .macro + tay + lda \1, y + inc a + sta \1, y + cly + .endm + +; ************** + +__decld.war .macro + phx + asl a + tax + lda.l \1, x + bne !+ + dec.h \1, x +!: dec a + sta.l \1, x + ldy.h \1, x + plx + .endm + +; ************** + +__decld.bar .macro + tay + lda \1, y + dec a + sta \1, y + cly + bpl !+ + dey +!: + .endm + +; ************** + +__decld.car .macro + tay + lda \1, y + dec a + sta \1, y + cly + .endm + +; ************** + +__ldinc.war .macro + phx + asl a + tax + lda.l \1, x + ldy.h \1, x + inc.l \1, x + bne !+ + inc.h \1, x +!: plx + .endm + +; ************** + +__ldinc.bar .macro + tay + lda.l \1, y + inc a + sta.l \1, y + dec a + cly + bpl !+ + dey +!: + .endm + +; ************** + +__ldinc.car .macro + tay + lda.l \1, y + inc a + sta.l \1, y + dec a + cly + .endm + +; ************** + +__lddec.war .macro + phx + asl a + tax + ldy.h \1, x + lda.l \1, x + bne !+ + dec.h \1, x +!: dec.l \1, x + plx + .endm + +; ************** + +__lddec.bar .macro + tay + lda.l \1, y + dec a + sta.l \1, y + inc a + cly + bpl !+ + dey +!: + .endm + +; ************** + +__lddec.car .macro + tay + lda.l \1, y + dec a + sta.l \1, y + inc a + cly + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__inc.warq .macro + asl a + sax + inc.l \1, x + bne !+ + inc.h \1, x +!: tax + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__inc.carq .macro + sax + inc \1, x + tax + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__dec.warq .macro + asl a + sax + ldy.l \1, x + bne !+ + dec.h \1, x +!: dec.l \1, x + tax + .endm + +; ************** +; optimized macro used when the value isn't needed in the primary register + +__dec.carq .macro + sax + dec \1, x + tax + .endm + ; *************************************************************************** @@ -1421,37 +1623,45 @@ __stbps .macro ; __STACK .endm ; ************** +; special store for when array writes are optimized +; the cpu stack is balanced with an __st.wat -__indexw .macro +__index.wr .macro + phx asl a pha .endm ; ************** +; special store for when array writes are optimized +; the cpu stack is balanced with an __st.cat -__indexb .macro +__index.cr .macro + phx pha .endm ; ************** +; special store for when array writes are optimized +; this balances the cpu stack after an __index.wr or __ldp.war -__stwas .macro - stx <__sp +__st.wat .macro plx sta.l \1, x say sta.h \1, x say - ldx <__sp + plx .endm ; ************** +; special store for when array writes are optimized +; this balances the cpu stack after an __index.cr or __ldp.car -__stbas .macro - stx <__sp +__st.cat .macro plx sta.l \1, x - ldx <__sp + plx .endm ; ************** @@ -2724,202 +2934,3 @@ do_switchb: sty.h <__ptr ; Save hi-byte of the table address. ; POTENTIAL OPTIMIZATIONS, NOT YET ADDED ; *************************************************************************** ; *************************************************************************** - -; ************** - -__lddec.war .macro - phx - asl a - tax - ldy.h \1, x - lda.l \1, x - bne !+ - dec.h \1, x -!: dec.l \1, x - plx - .endm - -; ************** - -__lddec.uar .macro - tay - lda.l \1, y - dec a - sta.l \1, y - inc a - cly - .endm - -; ************** - -__dec.warq .macro - asl a - sax - ldy.l \1, x - bne !+ - dec.h \1, x -!: dec.l \1, x - tax - .endm - -; ************** - -__dec.uarq .macro - sax - dec.l \1, x - tax - .endm - -; ************** - -__st.wat .macro - stx <__sp - plx - sta.l \1, x - say - sta.h \1, x - say - ldx <__sp - .endm - -; ************** - -__st.bat .macro - sty <__temp - ply - sta.l \1, y - ldy <__temp - .endm - -; ************** - -__st.watq .macro - sty <__temp - ply - sta.l \1, y - lda <__temp - sta.h \1, y - .endm - -; ************** - -__st.batq .macro - ply - sta.l \1, y - .endm - -; ************** - -__st.wam .macro - phy - pha - lda \2 - asl a - say - sta.h \1, y - pla - sta.l \1, y - ply - .endm - -; ************** - -__st.bam .macro - phy - ldy \2 - sta \1, y - ply - .endm - -; ************** - -__st.wamq .macro - pha - lda \2 - asl a - say - sta.h \1, y - pla - sta.l \1, y - .endm - -; ************** - -__st.bamq .macro - ldy \2 - sta \1, y - .endm - -; ************** - -__add.wam .macro - stx <__sp - tax - lda \2 - asl a - sax - clc - adc.l \1, x - say - adc.h \1, x - say - ldx <__sp - .endm - -; ************** - -__add.bam .macro - stx <__sp - ldx \2 - bit.l \1, x - bpl !+ - dey -!: clc - adc.l \1, x - bcc !+ - iny -!: ldx <__sp - .endm - -; ************** - -__add.uam .macro - stx <__sp - ldx \2 - clc - adc.l \1, x - bcc !+ - iny -!: ldx <__sp - .endm - -; ************** - -__add.uamq .macro - ldy \2 - clc - adc.l \1, y - .endm - -; ************** - -__sub.bam .macro - stx <__sp - ldx \2 - bit.l \1, x - bpl !+ - iny -!: sec - sbc.l \1, x - bcs !+ - dey -!: ldx <__sp - .endm - -; ************** - -__sub.bamq .macro - ldy \2 -!: sec - sbc.l \1, y - .endm diff --git a/src/hucc/code.c b/src/hucc/code.c index 10ff70f5..c204450b 100644 --- a/src/hucc/code.c +++ b/src/hucc/code.c @@ -697,20 +697,20 @@ void gen_code (INS *tmp) nl(); break; - case X_LDWA_A: - ot("__ldwa_a\t"); + case X_LD_WAR: + ot("__ld.war\t"); out_type(type, data); nl(); break; - case X_LDBA_A: - ot("__ldba_a\t"); + case X_LD_BAR: + ot("__ld.bar\t"); out_type(type, data); nl(); break; - case X_LDUBA_A: - ot("__lduba_a\t"); + case X_LD_CAR: + ot("__ld.car\t"); out_type(type, data); nl(); break; @@ -736,20 +736,20 @@ void gen_code (INS *tmp) nl(); break; - case X_LDPWA_A: - ot("__ldpwa_a\t"); + case X_LDP_WAR: + ot("__ldp.war\t"); out_type(type, data); nl(); break; - case X_LDPBA_A: - ot("__ldpba_a\t"); + case X_LDP_BAR: + ot("__ldp.bar\t"); out_type(type, data); nl(); break; - case X_LDPUBA_A: - ot("__ldpuba_a\t"); + case X_LDP_CAR: + ot("__ldp.car\t"); out_type(type, data); nl(); break; @@ -991,6 +991,102 @@ void gen_code (INS *tmp) nl(); break; + case X_INCLD_WAR: + ot("__incld.war\t"); + out_type(type, data); + nl(); + break; + + case X_INCLD_BAR: + ot("__incld.bar\t"); + out_type(type, data); + nl(); + break; + + case X_INCLD_CAR: + ot("__incld.car\t"); + out_type(type, data); + nl(); + break; + + case X_DECLD_WAR: + ot("__decld.war\t"); + out_type(type, data); + nl(); + break; + + case X_DECLD_BAR: + ot("__decld.bar\t"); + out_type(type, data); + nl(); + break; + + case X_DECLD_CAR: + ot("__decld.car\t"); + out_type(type, data); + nl(); + break; + + case X_LDINC_WAR: + ot("__ldinc.war\t"); + out_type(type, data); + nl(); + break; + + case X_LDINC_BAR: + ot("__ldinc.bar\t"); + out_type(type, data); + nl(); + break; + + case X_LDINC_CAR: + ot("__ldinc.car\t"); + out_type(type, data); + nl(); + break; + + case X_LDDEC_WAR: + ot("__lddec.war\t"); + out_type(type, data); + nl(); + break; + + case X_LDDEC_BAR: + ot("__lddec.bar\t"); + out_type(type, data); + nl(); + break; + + case X_LDDEC_CAR: + ot("__lddec.car\t"); + out_type(type, data); + nl(); + break; + + case X_INC_WARQ: + ot("__inc.warq\t"); + out_type(type, data); + nl(); + break; + + case X_INC_CARQ: + ot("__inc.carq\t"); + out_type(type, data); + nl(); + break; + + case X_DEC_WARQ: + ot("__dec.warq\t"); + out_type(type, data); + nl(); + break; + + case X_DEC_CARQ: + ot("__dec.carq\t"); + out_type(type, data); + nl(); + break; + /* i-codes for saving the primary register */ case I_STWZ: @@ -1097,26 +1193,26 @@ void gen_code (INS *tmp) nl(); break; - case X_INDEXW: - ot("__indexw\t"); + case X_INDEX_WR: + ot("__index.wr\t"); out_type(type, data); nl(); break; - case X_INDEXB: - ot("__indexb\t"); + case X_INDEX_CR: + ot("__index.cr\t"); out_type(type, data); nl(); break; - case X_STWAS: - ot("__stwas\t\t"); + case X_ST_WAT: + ot("__st.wat\t"); out_type(type, data); nl(); break; - case X_STBAS: - ot("__stbas\t\t"); + case X_ST_CAT: + ot("__st.cat\t"); out_type(type, data); nl(); break; diff --git a/src/hucc/defs.h b/src/hucc/defs.h index 20bd7ba0..fb30e15c 100644 --- a/src/hucc/defs.h +++ b/src/hucc/defs.h @@ -123,17 +123,17 @@ enum ICODE { I_LDBP, I_LDUBP, - X_LDWA_A, - X_LDBA_A, - X_LDUBA_A, + X_LD_WAR, + X_LD_BAR, + X_LD_CAR, X_LDW_S, X_LDB_S, X_LDUB_S, - X_LDPWA_A, - X_LDPBA_A, - X_LDPUBA_A, + X_LDP_WAR, + X_LDP_BAR, + X_LDP_CAR, /* i-codes for pre- and post- increment and decrement */ @@ -181,6 +181,28 @@ enum ICODE { X_DEC_WSQ, X_DEC_CSQ, + X_INCLD_WAR, + X_INCLD_BAR, + X_INCLD_CAR, + + X_DECLD_WAR, + X_DECLD_BAR, + X_DECLD_CAR, + + X_LDINC_WAR, + X_LDINC_BAR, + X_LDINC_CAR, + + X_LDDEC_WAR, + X_LDDEC_BAR, + X_LDDEC_CAR, + + X_INC_WARQ, + X_INC_CARQ, + + X_DEC_WARQ, + X_DEC_CARQ, + /* i-codes for saving the primary register */ I_STWZ, @@ -200,10 +222,10 @@ enum ICODE { X_STW_S, X_STB_S, - X_INDEXW, - X_INDEXB, - X_STWAS, - X_STBAS, + X_INDEX_WR, + X_INDEX_CR, + X_ST_WAT, + X_ST_CAT, /* i-codes for extending the primary register */ diff --git a/src/hucc/optimize.c b/src/hucc/optimize.c index c156755f..267e7329 100644 --- a/src/hucc/optimize.c +++ b/src/hucc/optimize.c @@ -131,17 +131,17 @@ unsigned char icode_flags[] = { /* I_LDBP */ 0, /* I_LDUBP */ 0, - /* X_LDWA_A */ 0, - /* X_LDBA_A */ 0, - /* X_LDUBA_A */ 0, + /* X_LD_WAR */ 0, + /* X_LD_BAR */ 0, + /* X_LD_CAR */ 0, /* X_LDW_S */ IS_SPREL, /* X_LDB_S */ IS_SPREL, /* X_LDUB_S */ IS_SPREL, - /* X_LDPWA_A */ 0, - /* X_LDPBA_A */ 0, - /* X_LDPUBA_A */ 0, + /* X_LDP_WAR */ 0, + /* X_LDP_BAR */ 0, + /* X_LDP_CAR */ 0, /* i-codes for pre- and post- increment and decrement */ @@ -189,6 +189,28 @@ unsigned char icode_flags[] = { /* X_DEC_WSQ */ IS_SPREL, /* X_DEC_CSQ */ IS_SPREL, + /* X_INCLD_WAR */ 0, + /* X_INCLD_BAR */ 0, + /* X_INCLD_CAR */ 0, + + /* X_DECLD_WAR */ 0, + /* X_DECLD_BAR */ 0, + /* X_DECLD_CAR */ 0, + + /* X_LDINC_WAR */ 0, + /* X_LDINC_BAR */ 0, + /* X_LDINC_CAR */ 0, + + /* X_LDDEC_WAR */ 0, + /* X_LDDEC_BAR */ 0, + /* X_LDDEC_CAR */ 0, + + /* X_INC_WARQ */ 0, + /* X_INC_CARQ */ 0, + + /* X_DEC_WARQ */ 0, + /* X_DEC_CARQ */ 0, + /* i-codes for saving the primary register */ /* I_STWZ */ 0, @@ -208,10 +230,10 @@ unsigned char icode_flags[] = { /* X_STW_S */ IS_SPREL, /* X_STB_S */ IS_SPREL, - /* X_INDEXW */ 0, - /* X_INDEXB */ 0, - /* X_STWAS */ 0, - /* X_STBAS */ 0, + /* X_INDEX_WR */ 0, + /* X_INDEX_CR */ 0, + /* X_ST_WAT */ 0, + /* X_ST_CAT */ 0, /* i-codes for extending the primary register */ @@ -441,7 +463,19 @@ void push_ins (INS *ins) p[1]->code == X_DECLD_CS || p[1]->code == X_LDDEC_WS || p[1]->code == X_LDDEC_BS || - p[1]->code == X_LDDEC_CS) + p[1]->code == X_LDDEC_CS || + p[1]->code == X_INCLD_WAR || + p[1]->code == X_INCLD_BAR || + p[1]->code == X_INCLD_CAR || + p[1]->code == X_LDINC_WAR || + p[1]->code == X_LDINC_BAR || + p[1]->code == X_LDINC_CAR || + p[1]->code == X_DECLD_WAR || + p[1]->code == X_DECLD_BAR || + p[1]->code == X_DECLD_CAR || + p[1]->code == X_LDDEC_WAR || + p[1]->code == X_LDDEC_BAR || + p[1]->code == X_LDDEC_CAR) ) { /* replace code */ switch (p[1]->code) { @@ -469,6 +503,18 @@ void push_ins (INS *ins) case X_DECLD_CS: case X_LDDEC_BS: case X_LDDEC_CS: p[1]->code = X_DEC_CSQ; break; + case X_INCLD_WAR: + case X_LDINC_WAR: p[1]->code = X_INC_WARQ; break; + case X_INCLD_BAR: + case X_INCLD_CAR: + case X_LDINC_BAR: + case X_LDINC_CAR: p[1]->code = X_INC_CARQ; break; + case X_DECLD_WAR: + case X_LDDEC_WAR: p[1]->code = X_DEC_WARQ; break; + case X_DECLD_BAR: + case X_DECLD_CAR: + case X_LDDEC_BAR: + case X_LDDEC_CAR: p[1]->code = X_DEC_CARQ; break; default: abort(); } nb = 1; @@ -746,7 +792,7 @@ void push_ins (INS *ins) (p[3]->code == I_ASLW) ) { /* replace code */ - p[3]->code = X_LDWA_A; + p[3]->code = X_LD_WAR; p[3]->type = T_SYMBOL; p[3]->data = p[2]->data; nb = 3; @@ -1127,6 +1173,42 @@ void push_ins (INS *ins) nb = 2; } + /* + * __ldp_{w/b/c}ar n --> __incld_{w/b/c}ar n + * __addwi 1 + * __st{w/c} n + * + * __ldp_{w/b/c}ar n --> __decld_{w/b/c}ar n + * __subwi 1 + * __st{w/c} n + * + * pre-increment, post-increment, + * pre-decrement, post-decrement! + */ + else if + ((p[1]->code == I_ADDWI || + p[1]->code == I_SUBWI) && + (p[1]->type == T_VALUE) && + (p[1]->data == 1) && + (p[0]->code == X_ST_WAT || + p[0]->code == X_ST_CAT) && + (p[2]->code == X_LDP_WAR || + p[2]->code == X_LDP_BAR || + p[2]->code == X_LDP_CAR) && + (p[0]->type == p[2]->type) && + (p[0]->data == p[2]->data) +// (cmp_operands(p[0], p[2]) == 1) + ) { + /* replace code */ + switch (p[2]->code) { + case X_LDP_WAR: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_WAR : X_DECLD_WAR; break; + case X_LDP_BAR: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_BAR : X_DECLD_BAR; break; + case X_LDP_CAR: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_CAR : X_DECLD_CAR; break; + default: break; + } + nb = 2; + } + /* * __ldw/b/ub --> __tzw/b/ub * __tstw __btrue (or __bfalse) @@ -1208,14 +1290,14 @@ void push_ins (INS *ins) (is_small_array((SYMBOL *)p[2]->data)) ) { /* replace code */ - p[2]->code = (p[0]->code == I_LDBP) ? X_LDBA_A : X_LDUBA_A; + p[2]->code = (p[0]->code == I_LDBP) ? X_LD_BAR : X_LD_CAR; nb = 2; } #endif #if OPT_ARRAY_WR /* - * __indexw or __indexb array --> __pldwa/__pldba/__plduba array + * __index.wr or __index.cr --> __ldp.{w/b/c}ar array * __stw _ptr * __ldwp/__ldbp/__ldubp _ptr * @@ -1233,14 +1315,14 @@ void push_ins (INS *ins) (p[0]->type == T_PTR) && (p[1]->code == I_STW) && (p[1]->type == T_PTR) && - (p[2]->code == X_INDEXW || - p[2]->code == X_INDEXB) + (p[2]->code == X_INDEX_WR || + p[2]->code == X_INDEX_CR) ) { /* replace code */ if (p[0]->code == I_LDWP) - p[2]->code = X_LDPWA_A; + p[2]->code = X_LDP_WAR; else - p[2]->code = (p[0]->code == I_LDBP) ? X_LDPBA_A : X_LDPUBA_A; + p[2]->code = (p[0]->code == I_LDBP) ? X_LDP_BAR : X_LDP_CAR; nb = 2; } #endif @@ -1315,8 +1397,8 @@ void push_ins (INS *ins) p[1]->code == I_LDUB || p[1]->code == I_LDBP || p[1]->code == I_LDUBP || - p[1]->code == X_LDBA_A || - p[1]->code == X_LDUBA_A || + p[1]->code == X_LD_BAR || + p[1]->code == X_LD_CAR || p[1]->code == X_LDB_S || p[1]->code == X_LDUB_S) ) { @@ -1722,6 +1804,9 @@ void push_ins (INS *ins) * __decld_{w/b/c}s n --> __lddec_{w/b/c}s n * __addwi 1 * + * __decld_{w/b/c}ar n --> __lddec_{w/b/c}ar n + * __addwi 1 + * * C post-decrement! */ else if @@ -1733,7 +1818,10 @@ void push_ins (INS *ins) p[1]->code == X_DECLD_CM || p[1]->code == X_DECLD_WS || p[1]->code == X_DECLD_BS || - p[1]->code == X_DECLD_CS) + p[1]->code == X_DECLD_CS || + p[1]->code == X_DECLD_WAR || + p[1]->code == X_DECLD_BAR || + p[1]->code == X_DECLD_CAR) ) { /* replace code */ switch (p[1]->code) { @@ -1743,6 +1831,9 @@ void push_ins (INS *ins) case X_DECLD_WS: p[1]->code = X_LDDEC_WS; break; case X_DECLD_BS: p[1]->code = X_LDDEC_BS; break; case X_DECLD_CS: p[1]->code = X_LDDEC_CS; break; + case X_DECLD_WAR: p[1]->code = X_LDDEC_WAR; break; + case X_DECLD_BAR: p[1]->code = X_LDDEC_BAR; break; + case X_DECLD_CAR: p[1]->code = X_LDDEC_CAR; break; default: break; } nb = 1; @@ -1755,6 +1846,9 @@ void push_ins (INS *ins) * __incld_{w/b/c}s n --> __ldinc_{w/b/c}s n * __subwi 1 * + * __incld_{w/b/c}ar n --> __ldinc_{w/b/c}ar n + * __subwi 1 + * * C post-increment! */ else if @@ -1766,7 +1860,10 @@ void push_ins (INS *ins) p[1]->code == X_INCLD_CM || p[1]->code == X_INCLD_WS || p[1]->code == X_INCLD_BS || - p[1]->code == X_INCLD_CS) + p[1]->code == X_INCLD_CS || + p[1]->code == X_INCLD_WAR || + p[1]->code == X_INCLD_BAR || + p[1]->code == X_INCLD_CAR) ) { /* replace code */ switch (p[1]->code) { @@ -1776,6 +1873,9 @@ void push_ins (INS *ins) case X_INCLD_WS: p[1]->code = X_LDINC_WS; break; case X_INCLD_BS: p[1]->code = X_LDINC_BS; break; case X_INCLD_CS: p[1]->code = X_LDINC_CS; break; + case X_INCLD_WAR: p[1]->code = X_LDINC_WAR; break; + case X_INCLD_BAR: p[1]->code = X_LDINC_BAR; break; + case X_INCLD_CAR: p[1]->code = X_LDINC_CAR; break; default: break; } nb = 1; @@ -1853,30 +1953,30 @@ void push_ins (INS *ins) * * this covers storing to global and static arrays with "=" ... * - * __aslw --> __index2 + * __aslw --> __index.wr * __addwi array ... - * __pushw __stwa_a array + * __pushw __st.wat array * ... * __stwps * - * __addwi array --> __index1 + * __addwi array --> __index.cr * __pushw ... - * ... __stba_a array + * ... __st.cat array * __stbps * * this covers storing to global and static arrays with "+=", "-=", etc ... * - * __aslw --> __ldpwa_a array + * __aslw --> __ldp.war array * __addwi array ... - * __pushw __stwa_a array + * __pushw __st.wat array * __stw _ptr * __ldwp _ptr * ... * __stwps * - * __addwi array --> __ldpuba_a array + * __addwi array --> __ldp.car array * __pushw ... - * __stw _ptr __stba_a array + * __stw _ptr __st.cat array * __ldubp _ptr * ... * __stbps @@ -2032,8 +2132,8 @@ void push_ins (INS *ins) #if OPT_ARRAY_WR } else { - int push = X_INDEXB; - int code = X_STBAS; + int push = X_INDEX_CR; + int code = X_ST_CAT; /* make sure that I_ADDWI is really a short array */ if (q_ins[prev].type != T_SYMBOL || @@ -2052,8 +2152,8 @@ void push_ins (INS *ins) if (copy == q_nb || q_ins[aslw].code != I_ASLW) break; drop = 2; - push = X_INDEXW; - code = X_STWAS; + push = X_INDEX_WR; + code = X_ST_WAT; } /* push the index from the preceding I_ADDWI */ From d0bbc7bd4d34e6763e15e61b848d59e122038814 Mon Sep 17 00:00:00 2001 From: John Brandwood Date: Sun, 15 Sep 2024 18:22:08 -0400 Subject: [PATCH 3/5] Rename all HuCC i-codes and macros to follow the new naming scheme. --- include/hucc/hucc-codegen.asm | 346 ++++---- src/hucc/code.c | 440 ++++----- src/hucc/defs.h | 216 ++--- src/hucc/expr.c | 6 +- src/hucc/function.c | 70 +- src/hucc/gen.c | 122 +-- src/hucc/optimize.c | 1570 +++++++++++++++++---------------- src/hucc/pseudo.c | 2 +- src/hucc/sym.c | 16 +- 9 files changed, 1425 insertions(+), 1363 deletions(-) diff --git a/include/hucc/hucc-codegen.asm b/include/hucc/hucc-codegen.asm index c81663eb..62e71e26 100644 --- a/include/hucc/hucc-codegen.asm +++ b/include/hucc/hucc-codegen.asm @@ -28,14 +28,15 @@ ; ; {size} ; w : 16-bit signed int (default "int" in HuCC) -; u : 16-bit unsigned int +; c : 16-bit unsigned int (a "cardinal" in Pascal terms) ; b : 8-bit signed char -; c : 8-bit unsigned char (default "char" in HuCC) +; u : 8-bit unsigned char (default "char" in HuCC) ; ; {where} or {index} -; i : immediate value, i.e. a decimal number ; r : HuCC primary register, made up of the Y:A cpu registers ; t : top of arithmetic stack +; p : indirect pointer, usually [__ptr] +; i : immediate value, i.e. a decimal number ; m : memory, i.e. C global, static, and "-fno-recursive" variables ; s : stack, i.e. C function parameters and locals (not "-fno-recursive") ; a : array, i.e. C global, static, "-fno-recursive" arrays <= 256 bytes @@ -420,7 +421,7 @@ __modsp_sym .macro ; ************** ; main C data-stack for arguments/locals/expressions -__pushw .macro ; __STACK +__push.wr .macro ; __STACK dex dex .if HUCC_DEBUG_SP @@ -433,7 +434,7 @@ __pushw .macro ; __STACK ; ************** ; main C data-stack for arguments/locals/expressions -__popw .macro ; __STACK +__pop.wr .macro ; __STACK lda.l <__stack, x ldy.h <__stack, x inx @@ -442,7 +443,8 @@ __popw .macro ; __STACK ; ************** ; hardware-stack used for *temporary* storage of spilled arguments -__spushw .macro + +__spush.wr .macro phy pha .endm @@ -450,7 +452,7 @@ __spushw .macro ; ************** ; hardware-stack used for *temporary* storage of spilled arguments -__spopw .macro +__spop.wr .macro pla ply .endm @@ -458,14 +460,14 @@ __spopw .macro ; ************** ; hardware-stack used for *temporary* storage of spilled arguments -__spushb .macro +__spush.ur .macro pha .endm ; ************** ; hardware-stack used for *temporary* storage of spilled arguments -__spopb .macro +__spop.ur .macro pla .endm @@ -480,7 +482,7 @@ __spopb .macro ; ************** ; Y:A is the value to check for. -__switchw .macro +__switch.wr .macro sty.h __temp ldy.l #\1 sty.l __ptr @@ -491,7 +493,7 @@ __switchw .macro ; ************** ; Y:A is the value to check for. -__switchb .macro +__switch.ur .macro ldy.l #\1 sty.l __ptr ldy.h #\1 @@ -518,18 +520,18 @@ __bra .macro .endm ; ************** -; boolean test, always followed by a __tstw or __notw +; boolean test, always followed by a __tst.wr or __not.wr ; this MUST set the Z flag for the susequent branches! -__cmpw .macro +__cmp.wt .macro jsr \1 .endm ; ************** -; boolean test, always followed by a __tstw or __notw +; boolean test, always followed by a __tst.wr or __not.wr ; this MUST set the Z flag for the susequent branches! -__cmpb .macro +__cmp.ut .macro jsr \1 .endm @@ -537,7 +539,7 @@ __cmpb .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__cmpwi_eq .macro +__tst.wi .macro eor.l #\1 bne !false+ cpy.h #\1 @@ -551,7 +553,7 @@ __cmpwi_eq .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__cmpwi_ne .macro +__not.wi .macro eor.l #\1 bne !true+ cpy.h #\1 @@ -564,7 +566,7 @@ __cmpwi_ne .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__cmpbi_eq .macro +__tst.ui .macro eor.l #\1 beq !true+ !false: lda #-1 @@ -576,7 +578,7 @@ __cmpbi_eq .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__cmpbi_ne .macro +__not.ui .macro eor.l #\1 beq !false+ lda #1 @@ -584,10 +586,10 @@ __cmpbi_ne .macro .endm ; ************** -; boolean test, optimized into __notw if used before a __tstw +; boolean test, optimized into __not.wr if used before a __tst.wr ; this MUST set the Z flag for the susequent branches! -__notw .macro +__not.wr .macro sty <__temp ora <__temp beq !+ @@ -600,7 +602,7 @@ __notw .macro ; boolean test, always output immediately before a __bfalse or __btrue ; this MUST set the Z flag for the susequent branches! -__tstw .macro +__tst.wr .macro sty <__temp ora <__temp beq !+ @@ -609,14 +611,14 @@ __tstw .macro .endm ; ************** -; always preceeded by a __tstw before peephole optimization +; always preceeded by a __tst.wr before peephole optimization __bfalse .macro beq \1 .endm ; ************** -; always preceeded by a __tstw before peephole optimization +; always preceeded by a __tst.wr before peephole optimization __btrue .macro bne \1 @@ -626,7 +628,7 @@ __btrue .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tzb .macro +__not.um .macro lda \1 beq !+ lda #-1 @@ -638,7 +640,7 @@ __tzb .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tzbp .macro +__not.up .macro lda [\1] beq !+ lda #-1 @@ -650,7 +652,7 @@ __tzbp .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tzb_s .macro ; __STACK +__not.us .macro ; __STACK lda.l <__stack + \1, x beq !+ lda #-1 @@ -662,7 +664,7 @@ __tzb_s .macro ; __STACK ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tzw .macro +__not.wm .macro lda.l \1 ora.h \1 beq !+ @@ -675,7 +677,7 @@ __tzw .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tzwp .macro +__not.wp .macro ldy #1 lda [\1], y ora [\1] @@ -689,7 +691,7 @@ __tzwp .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tzw_s .macro ; __STACK +__not.ws .macro ; __STACK lda.l <__stack + \1, x ora.h <__stack + \1, x beq !+ @@ -702,7 +704,7 @@ __tzw_s .macro ; __STACK ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tnzb .macro +__tst.um .macro lda \1 beq !+ lda #1 @@ -713,7 +715,7 @@ __tnzb .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tnzbp .macro +__tst.up .macro lda [\1] beq !+ lda #1 @@ -724,7 +726,7 @@ __tnzbp .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tnzb_s .macro ; __STACK +__tst.us .macro ; __STACK lda.l <__stack + \1, x beq !+ lda #1 @@ -735,7 +737,7 @@ __tnzb_s .macro ; __STACK ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tnzw .macro +__tst.wm .macro lda.l \1 ora.h \1 beq !+ @@ -747,7 +749,7 @@ __tnzw .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tnzwp .macro +__tst.wp .macro ldy #1 lda [\1], y ora [\1] @@ -760,7 +762,7 @@ __tnzwp .macro ; optimized boolean test ; this MUST set the Z flag for the susequent branches! -__tnzw_s .macro ; __STACK +__tst.ws .macro ; __STACK lda.l <__stack + \1, x ora.h <__stack + \1, x beq !+ @@ -778,7 +780,7 @@ __tnzw_s .macro ; __STACK ; ************** -__ldwi .macro +__ld.wi .macro .if ((\?1 == ARG_ABS) && (\1 >= 0) && (\1 < 256)) lda.l #\1 cly @@ -790,7 +792,7 @@ __ldwi .macro ; ************** -__lea_s .macro ; __STACK +__lea.s .macro ; __STACK txa clc adc.l #__stack + (\1) @@ -799,14 +801,14 @@ __lea_s .macro ; __STACK ; ************** -__ldw .macro +__ld.wm .macro lda.l \1 ldy.h \1 .endm ; ************** -__ldb .macro +__ld.bm .macro lda \1 cly bpl !+ @@ -816,14 +818,14 @@ __ldb .macro ; ************** -__ldub .macro +__ld.um .macro lda \1 cly .endm ; ************** -__ldwp .macro +__ld.wp .macro ldy #1 lda [\1], y tay @@ -832,7 +834,7 @@ __ldwp .macro ; ************** -__ldbp .macro +__ld.bp .macro lda [\1] cly bpl !+ @@ -842,7 +844,7 @@ __ldbp .macro ; ************** -__ldubp .macro +__ld.up .macro lda [\1] cly .endm @@ -871,7 +873,7 @@ __ld.bar .macro ; ************** -__ld.car .macro +__ld.uar .macro tay lda \1, y cly @@ -902,7 +904,7 @@ __ld.bam .macro ; ************** -__ld.cam .macro +__ld.uam .macro ldy \2 lda \1, y cly @@ -925,7 +927,7 @@ __ldp.war .macro ; ************** ; special load for when array writes are optimized -; the cpu stack is balanced with an __st.cat +; the cpu stack is balanced with an __st.uat __ldp.bar .macro phx @@ -940,9 +942,9 @@ __ldp.bar .macro ; ************** ; special load for when array writes are optimized -; the cpu stack is balanced with an __st.cat +; the cpu stack is balanced with an __st.uat -__ldp.car .macro +__ldp.uar .macro phx tay phy @@ -952,14 +954,14 @@ __ldp.car .macro ; ************** -__ldw_s .macro ; __STACK +__ld.ws .macro ; __STACK lda.l <__stack + \1, x ldy.h <__stack + \1, x .endm ; ************** -__ldb_s .macro ; __STACK +__ld.bs .macro ; __STACK lda.l <__stack + \1, x cly bpl !+ ; signed @@ -969,7 +971,7 @@ __ldb_s .macro ; __STACK ; ************** -__ldub_s .macro ; __STACK +__ld.us .macro ; __STACK lda <__stack + \1, x cly .endm @@ -1036,7 +1038,7 @@ __incld.bm .macro ; ************** -__incld.cm .macro +__incld.um .macro inc \1 lda \1 cly @@ -1066,7 +1068,7 @@ __decld.bm .macro ; ************** -__decld.cm .macro +__decld.um .macro dec \1 lda \1 cly @@ -1095,7 +1097,7 @@ __ldinc.bm .macro ; ************** -__ldinc.cm .macro +__ldinc.um .macro lda \1 cly inc \1 @@ -1123,7 +1125,7 @@ __lddec.bm .macro ; ************** -__lddec.cm .macro +__lddec.um .macro lda \1 cly dec \1 @@ -1142,7 +1144,7 @@ __inc.wmq .macro ; ************** ; optimized macro used when the value isn't needed in the primary register -__inc.cmq .macro +__inc.umq .macro inc \1 .endm @@ -1159,7 +1161,7 @@ __dec.wmq .macro ; ************** ; optimized macro used when the value isn't needed in the primary register -__dec.cmq .macro +__dec.umq .macro dec \1 .endm @@ -1186,7 +1188,7 @@ __incld.bs .macro ; ************** -__incld.cs .macro +__incld.us .macro inc <__stack + \1, x lda <__stack + \1, x cly @@ -1216,7 +1218,7 @@ __decld.bs .macro ; ************** -__decld.cs .macro +__decld.us .macro dec <__stack + \1, x lda <__stack + \1, x cly @@ -1245,7 +1247,7 @@ __ldinc.bs .macro ; ************** -__ldinc.cs .macro +__ldinc.us .macro lda <__stack + \1, x cly inc <__stack + \1, x @@ -1273,7 +1275,7 @@ __lddec.bs .macro ; ************** -__lddec.cs .macro +__lddec.us .macro lda <__stack + \1, x cly dec <__stack + \1, x @@ -1292,7 +1294,7 @@ __inc.wsq .macro ; ************** ; optimized macro used when the value isn't needed in the primary register -__inc.csq .macro +__inc.usq .macro inc <__stack + \1, x .endm @@ -1309,7 +1311,7 @@ __dec.wsq .macro ; ************** ; optimized macro used when the value isn't needed in the primary register -__dec.csq .macro +__dec.usq .macro dec <__stack + \1, x .endm @@ -1342,7 +1344,7 @@ __incld.bar .macro ; ************** -__incld.car .macro +__incld.uar .macro tay lda \1, y inc a @@ -1380,7 +1382,7 @@ __decld.bar .macro ; ************** -__decld.car .macro +__decld.uar .macro tay lda \1, y dec a @@ -1418,7 +1420,7 @@ __ldinc.bar .macro ; ************** -__ldinc.car .macro +__ldinc.uar .macro tay lda.l \1, y inc a @@ -1457,7 +1459,7 @@ __lddec.bar .macro ; ************** -__lddec.car .macro +__lddec.uar .macro tay lda.l \1, y dec a @@ -1481,7 +1483,7 @@ __inc.warq .macro ; ************** ; optimized macro used when the value isn't needed in the primary register -__inc.carq .macro +__inc.uarq .macro sax inc \1, x tax @@ -1503,7 +1505,7 @@ __dec.warq .macro ; ************** ; optimized macro used when the value isn't needed in the primary register -__dec.carq .macro +__dec.uarq .macro sax dec \1, x tax @@ -1519,20 +1521,20 @@ __dec.carq .macro ; ************** -__stwz .macro +__st.wmz .macro stz.l \1 stz.h \1 .endm ; ************** -__stbz .macro +__st.umz .macro stz \1 .endm ; ************** -__stwi .macro +__st.wmi .macro lda.l #\2 sta.l \1 ldy.h #\2 @@ -1541,14 +1543,14 @@ __stwi .macro ; ************** -__stbi .macro +__st.umi .macro lda.l #\2 sta \1 .endm ; ************** -__stwip .macro +__st.wpi .macro sta.l <__ptr sty.h <__ptr lda.h #\1 @@ -1561,7 +1563,7 @@ __stwip .macro ; ************** -__stbip .macro +__st.upi .macro sta.l <__ptr sty.h <__ptr lda.l #\1 @@ -1571,20 +1573,20 @@ __stbip .macro ; ************** -__stw .macro +__st.wm .macro sta.l \1 sty.h \1 .endm ; ************** -__stb .macro +__st.um .macro sta \1 .endm ; ************** -__stwp .macro +__st.wp .macro sta [\1] pha tya @@ -1596,13 +1598,13 @@ __stwp .macro ; ************** -__stbp .macro +__st.up .macro sta [\1] .endm ; ************** -__stwps .macro ; __STACK +__st.wpt .macro ; __STACK sta [__stack, x] inc.l <__stack, x bne !+ @@ -1616,7 +1618,7 @@ __stwps .macro ; __STACK ; ************** -__stbps .macro ; __STACK +__st.upt .macro ; __STACK sta [__stack, x] inx inx @@ -1634,9 +1636,9 @@ __index.wr .macro ; ************** ; special store for when array writes are optimized -; the cpu stack is balanced with an __st.cat +; the cpu stack is balanced with an __st.uat -__index.cr .macro +__index.ur .macro phx pha .endm @@ -1656,9 +1658,9 @@ __st.wat .macro ; ************** ; special store for when array writes are optimized -; this balances the cpu stack after an __index.cr or __ldp.car +; this balances the cpu stack after an __index.ur or __ldp.uar -__st.cat .macro +__st.uat .macro plx sta.l \1, x plx @@ -1666,7 +1668,7 @@ __st.cat .macro ; ************** -__stwi_s .macro ; __STACK +__st.wsi .macro ; __STACK lda.l #\1 sta.l <__stack + \2, x ldy.h #\1 @@ -1675,7 +1677,7 @@ __stwi_s .macro ; __STACK ; ************** -__stbi_s .macro ; __STACK +__st.usi .macro ; __STACK lda.l #\1 sta.l <__stack + \2, x cly @@ -1683,20 +1685,20 @@ __stbi_s .macro ; __STACK ; ************** -__stw_s .macro ; __STACK +__st.ws .macro ; __STACK sta.l <__stack + \1, x sty.h <__stack + \1, x .endm ; ************** -__stb_s .macro ; __STACK +__st.us .macro ; __STACK sta.l <__stack + \1, x .endm ; ************** -__stwa_s .macro ; __STACK +__st.was .macro ; __STACK phy pha lda <__stack + \2, x @@ -1710,7 +1712,7 @@ __stwa_s .macro ; __STACK ; ************** -__stba_s .macro ; __STACK +__st.uas .macro ; __STACK phy ldy <__stack + \2, x sta \1, y @@ -1727,7 +1729,7 @@ __stba_s .macro ; __STACK ; ************** -__extw .macro +__ext.br .macro tay cly bpl !+ @@ -1737,7 +1739,7 @@ __extw .macro ; ************** -__extuw .macro +__ext.ur .macro cly .endm @@ -1751,7 +1753,7 @@ __extuw .macro ; ************** -__comw .macro +__com.wr .macro eor #$FF say eor #$FF @@ -1760,7 +1762,7 @@ __comw .macro ; ************** -__negw .macro +__neg.wr .macro sec eor #$FF adc #0 @@ -1772,7 +1774,7 @@ __negw .macro ; ************** -__addws .macro ; __STACK +__add.wt .macro ; __STACK clc adc.l <__stack, x say @@ -1784,7 +1786,7 @@ __addws .macro ; __STACK ; ************** -__addwi .macro +__add.wi .macro .if ((\?1 == ARG_ABS) && (\1 >= 0) && (\1 < 256)) clc adc.l #\1 @@ -1802,7 +1804,7 @@ __addwi .macro ; ************** -__addw .macro +__add.wm .macro clc adc.l \1 say @@ -1812,7 +1814,7 @@ __addw .macro ; ************** -__addub .macro +__add.um .macro clc adc \1 bcc !+ @@ -1822,7 +1824,7 @@ __addub .macro ; ************** -__addw_s .macro ; __STACK +__add.ws .macro ; __STACK clc adc.l <__stack + \1, x say @@ -1832,7 +1834,7 @@ __addw_s .macro ; __STACK ; ************** -__addub_s .macro ; __STACK +__add.us .macro ; __STACK clc adc <__stack + \1, x bcc !+ @@ -1854,7 +1856,7 @@ __addbi_p .macro ; ************** -__subws .macro ; __STACK +__sub.wt .macro ; __STACK sec eor #$FF adc.l <__stack, x @@ -1868,7 +1870,7 @@ __subws .macro ; __STACK ; ************** -__subwi .macro +__sub.wi .macro .if ((\?1 == ARG_ABS) && (\1 >= 0) && (\1 < 256)) sec sbc.l #\1 @@ -1886,7 +1888,7 @@ __subwi .macro ; ************** -__subw .macro +__sub.wm .macro sec sbc.l \1 say @@ -1896,7 +1898,7 @@ __subw .macro ; ************** -__subub .macro +__sub.um .macro sec sbc \1 bcs !+ @@ -1906,7 +1908,7 @@ __subub .macro ; ************** -__isubwi .macro ; __STACK +__isub.wi .macro ; __STACK sec eor #$FF adc.l #\1 @@ -1918,7 +1920,7 @@ __isubwi .macro ; __STACK ; ************** -__andws .macro ; __STACK +__and.wt .macro ; __STACK and.l <__stack, x say and.h <__stack, x @@ -1929,7 +1931,7 @@ __andws .macro ; __STACK ; ************** -__andwi .macro +__and.wi .macro .if (\?1 != ARG_ABS) and.l #\1 say @@ -1957,7 +1959,7 @@ __andwi .macro ; ************** -__andw .macro +__and.wm .macro and.l \1 say and.h \1 @@ -1966,14 +1968,14 @@ __andw .macro ; ************** -__andub .macro +__and.um .macro and \1 cly .endm ; ************** -__eorws .macro ; __STACK +__eor.wt .macro ; __STACK eor.l <__stack, x say eor.h <__stack, x @@ -1984,7 +1986,7 @@ __eorws .macro ; __STACK ; ************** -__eorwi .macro +__eor.wi .macro .if ((\1 >= 0) && (\1 < 256)) eor #\1 .else @@ -2003,7 +2005,7 @@ __eorwi .macro ; ************** -__eorw .macro +__eor.wm .macro eor.l \1 say eor.h \1 @@ -2012,13 +2014,13 @@ __eorw .macro ; ************** -__eorub .macro +__eor.um .macro eor \1 .endm ; ************** -__orws .macro ; __STACK +__or.wt .macro ; __STACK ora.l <__stack, x say ora.h <__stack, x @@ -2029,7 +2031,7 @@ __orws .macro ; __STACK ; ************** -__orwi .macro +__or.wi .macro .if ((\1 >= 0) && (\1 < 256)) ora #\1 .else @@ -2048,7 +2050,7 @@ __orwi .macro ; ************** -__orw .macro +__or.wm .macro ora.l \1 say ora.h \1 @@ -2057,21 +2059,21 @@ __orw .macro ; ************** -__orub .macro +__or.um .macro ora \1 .endm ; ************** ; N.B. Used when calculating a pointer into a word array. -__aslws .macro +__asl.wt .macro asl.l <__stack, x rol.h <__stack, x .endm ; ************** -__aslwi .macro +__asl.wi .macro .if (\1 = 1) asl a say @@ -2110,7 +2112,7 @@ __aslwi .macro ; ************** -__aslw .macro +__asl.wr .macro asl a say rol a @@ -2119,7 +2121,7 @@ __aslw .macro ; ************** -__asrwi .macro +__asr.wi .macro .if (\1 = 1) cpy #$80 say @@ -2168,7 +2170,7 @@ __asrwi .macro ; ************** -__asrw .macro +__asr.wr .macro cpy #$80 say ror a @@ -2178,7 +2180,7 @@ __asrw .macro ; ************** -__lsrwi .macro +__lsr.wi .macro .if (\1 = 1) say lsr a @@ -2232,66 +2234,66 @@ __lsrwi .macro ; ************** -__mulwi .macro +__mul.wi .macro .if (\1 = 2) - __aslw + __asl.wr .else .if (\1 = 3) - sta.l <__temp - sty.h <__temp - __aslw - __addw <__temp + sta.l <__temp + sty.h <__temp + __asl.wr + __add.wm <__temp .else .if (\1 = 4) - __aslw - __aslw + __asl.wr + __asl.wr .else .if (\1 = 5) - sta.l <__temp - sty.h <__temp - __aslw - __aslw - __addw <__temp + sta.l <__temp + sty.h <__temp + __asl.wr + __asl.wr + __add.wm <__temp .else .if (\1 = 6) - __aslw - sta.l <__temp - sty.h <__temp - __aslw - __addw <__temp + __asl.wr + sta.l <__temp + sty.h <__temp + __asl.wr + __add.wm <__temp .else .if (\1 = 7) - sta.l <__temp - sty.h <__temp - __aslw - __aslw - __aslw - __subw <__temp + sta.l <__temp + sty.h <__temp + __asl.wr + __asl.wr + __asl.wr + __sub.wm <__temp .else .if (\1 = 8) - __aslw - __aslw - __aslw + __asl.wr + __asl.wr + __asl.wr .else .if (\1 = 9) - sta.l <__temp - sty.h <__temp - __aslw - __aslw - __aslw - __addw <__temp + sta.l <__temp + sty.h <__temp + __asl.wr + __asl.wr + __asl.wr + __add.wm <__temp .else .if (\1 = 10) - __aslw - sta.l <__temp - sty.h <__temp - __aslw - __aslw - __addw <__temp + __asl.wr + sta.l <__temp + sty.h <__temp + __asl.wr + __asl.wr + __add.wm <__temp .else - __pushw - __ldwi \1 - jsr umul + __push.wr + __ld.wi \1 + jsr umul .endif .endif .endif @@ -2806,7 +2808,7 @@ asrw_positive: sta <__temp umul: smul: sta.l sym); nl(); break; - case I_LDW: - ot("__ldw\t\t"); + case I_LD_WM: + ot("__ld.wm\t\t"); out_addr(type, data); nl(); break; - case I_LDB: - ot("__ldb\t\t"); + case I_LD_BM: + ot("__ld.bm\t\t"); out_type(type, data); nl(); break; - case I_LDUB: - ot("__ldub\t\t"); + case I_LD_UM: + ot("__ld.um\t\t"); out_type(type, data); nl(); break; - case I_LDWP: - ot("__ldwp\t\t"); + case I_LD_WP: + ot("__ld.wp\t\t"); out_addr(type, data); nl(); break; - case I_LDBP: - ot("__ldbp\t\t"); + case I_LD_BP: + ot("__ld.bp\t\t"); out_addr(type, data); nl(); break; - case I_LDUBP: - ot("__ldubp\t\t"); + case I_LD_UP: + ot("__ld.up\t\t"); out_addr(type, data); nl(); break; @@ -709,28 +709,28 @@ void gen_code (INS *tmp) nl(); break; - case X_LD_CAR: - ot("__ld.car\t"); + case X_LD_UAR: + ot("__ld.uar\t"); out_type(type, data); nl(); break; - case X_LDW_S: - ot("__ldw_s\t\t"); + case X_LD_WS: + ot("__ld.ws\t\t"); outdec((int)data); outlocal(tmp->sym); nl(); break; - case X_LDB_S: - ot("__ldb_s\t\t"); + case X_LD_BS: + ot("__ld.bs\t\t"); outdec((int)data); outlocal(tmp->sym); nl(); break; - case X_LDUB_S: - ot("__ldub_s\t"); + case X_LD_US: + ot("__ld.us\t\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -748,14 +748,14 @@ void gen_code (INS *tmp) nl(); break; - case X_LDP_CAR: - ot("__ldp.car\t"); + case X_LDP_UAR: + ot("__ldp.uar\t"); out_type(type, data); nl(); break; // case X_LDWA_S: -// ot("__ldwa_s\t"); +// ot("__ld.was\t"); // outsymbol((SYMBOL *)imm_data); // outstr(", "); // outdec((int)data); @@ -764,7 +764,7 @@ void gen_code (INS *tmp) // break; // // case X_LDBA_S: -// ot("__ldba_s\t"); +// ot("__ld.bas\t"); // outsymbol((SYMBOL *)imm_data); // outstr(", "); // outdec((int)data); @@ -773,7 +773,7 @@ void gen_code (INS *tmp) // break; // // case X_LDUBA_S: -// ot("__lduba_s\t"); +// ot("__ld.uas\t"); // outsymbol((SYMBOL *)imm_data); // outstr(", "); // outdec((int)data); @@ -795,8 +795,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INCLD_CM: - ot("__incld.cm\t"); + case X_INCLD_UM: + ot("__incld.um\t"); out_type(type, data); nl(); break; @@ -813,8 +813,8 @@ void gen_code (INS *tmp) nl(); break; - case X_DECLD_CM: - ot("__decld.cm\t"); + case X_DECLD_UM: + ot("__decld.um\t"); out_type(type, data); nl(); break; @@ -831,8 +831,8 @@ void gen_code (INS *tmp) nl(); break; - case X_LDINC_CM: - ot("__ldinc.cm\t"); + case X_LDINC_UM: + ot("__ldinc.um\t"); out_type(type, data); nl(); break; @@ -849,8 +849,8 @@ void gen_code (INS *tmp) nl(); break; - case X_LDDEC_CM: - ot("__lddec.cm\t"); + case X_LDDEC_UM: + ot("__lddec.um\t"); out_type(type, data); nl(); break; @@ -861,8 +861,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INC_CMQ: - ot("__inc.cmq\t"); + case X_INC_UMQ: + ot("__inc.umq\t"); out_type(type, data); nl(); break; @@ -873,8 +873,8 @@ void gen_code (INS *tmp) nl(); break; - case X_DEC_CMQ: - ot("__dec.cmq\t"); + case X_DEC_UMQ: + ot("__dec.umq\t"); out_type(type, data); nl(); break; @@ -893,8 +893,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INCLD_CS: - ot("__incld.cs\t"); + case X_INCLD_US: + ot("__incld.us\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -914,8 +914,8 @@ void gen_code (INS *tmp) nl(); break; - case X_DECLD_CS: - ot("__decld.cs\t"); + case X_DECLD_US: + ot("__decld.us\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -935,8 +935,8 @@ void gen_code (INS *tmp) nl(); break; - case X_LDINC_CS: - ot("__ldinc.cs\t"); + case X_LDINC_US: + ot("__ldinc.us\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -956,8 +956,8 @@ void gen_code (INS *tmp) nl(); break; - case X_LDDEC_CS: - ot("__lddec.cs\t"); + case X_LDDEC_US: + ot("__lddec.us\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -970,8 +970,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INC_CSQ: - ot("__inc.csq\t"); + case X_INC_USQ: + ot("__inc.usq\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -984,8 +984,8 @@ void gen_code (INS *tmp) nl(); break; - case X_DEC_CSQ: - ot("__dec.csq\t"); + case X_DEC_USQ: + ot("__dec.usq\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -1003,8 +1003,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INCLD_CAR: - ot("__incld.car\t"); + case X_INCLD_UAR: + ot("__incld.uar\t"); out_type(type, data); nl(); break; @@ -1021,8 +1021,8 @@ void gen_code (INS *tmp) nl(); break; - case X_DECLD_CAR: - ot("__decld.car\t"); + case X_DECLD_UAR: + ot("__decld.uar\t"); out_type(type, data); nl(); break; @@ -1039,8 +1039,8 @@ void gen_code (INS *tmp) nl(); break; - case X_LDINC_CAR: - ot("__ldinc.car\t"); + case X_LDINC_UAR: + ot("__ldinc.uar\t"); out_type(type, data); nl(); break; @@ -1057,8 +1057,8 @@ void gen_code (INS *tmp) nl(); break; - case X_LDDEC_CAR: - ot("__lddec.car\t"); + case X_LDDEC_UAR: + ot("__lddec.uar\t"); out_type(type, data); nl(); break; @@ -1069,8 +1069,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INC_CARQ: - ot("__inc.carq\t"); + case X_INC_UARQ: + ot("__inc.uarq\t"); out_type(type, data); nl(); break; @@ -1081,88 +1081,88 @@ void gen_code (INS *tmp) nl(); break; - case X_DEC_CARQ: - ot("__dec.carq\t"); + case X_DEC_UARQ: + ot("__dec.uarq\t"); out_type(type, data); nl(); break; /* i-codes for saving the primary register */ - case I_STWZ: - ot("__stwz\t\t"); + case I_ST_WMZ: + ot("__st.wmz\t"); out_type(type, data); nl(); break; - case I_STBZ: - ot("__stbz\t\t"); + case I_ST_UMZ: + ot("__st.umz\t"); out_type(type, data); nl(); break; - case I_STWI: - ot("__stwi\t\t"); + case I_ST_WMI: + ot("__st.wmi\t"); out_type(type, data); outstr(", "); out_type(imm_type, imm_data); nl(); break; - case I_STBI: - ot("__stbi\t\t"); + case I_ST_UMI: + ot("__st.umi\t"); out_type(type, data); outstr(", "); out_type(imm_type, imm_data); nl(); break; - case I_STWIP: - ot("__stwip\t\t"); + case I_ST_WPI: + ot("__st.wpi\t\t"); outdec((int)data); nl(); break; - case I_STBIP: - ot("__stbip\t\t"); + case I_ST_UPI: + ot("__st.upi\t\t"); outdec((int)data); nl(); break; - case I_STW: - ot("__stw\t\t"); + case I_ST_WM: + ot("__st.wm\t\t"); out_addr(type, data); nl(); break; - case I_STB: - ot("__stb\t\t"); + case I_ST_UM: + ot("__st.um\t\t"); out_addr(type, data); nl(); break; - case I_STWP: - ot("__stwp\t\t"); + case I_ST_WP: + ot("__st.wp\t\t"); out_addr(type, data); nl(); break; - case I_STBP: - ot("__stbp\t\t"); + case I_ST_UP: + ot("__st.up\t\t"); out_addr(type, data); nl(); break; - case I_STWPS: - ol("__stwps"); + case I_ST_WPT: + ol("__st.wpt"); break; - case I_STBPS: - ol("__stbps"); + case I_ST_UPT: + ol("__st.upt"); break; - case X_STWI_S: - ot("__stwi_s\t"); + case X_ST_WSI: + ot("__st.wsi\t"); outdec((int)imm_data); outstr(", "); outdec((int)data); @@ -1170,8 +1170,8 @@ void gen_code (INS *tmp) nl(); break; - case X_STBI_S: - ot("__stbi_s\t"); + case X_ST_USI: + ot("__st.usi\t"); outdec((int)imm_data); outstr(", "); outdec((int)data); @@ -1179,15 +1179,15 @@ void gen_code (INS *tmp) nl(); break; - case X_STW_S: - ot("__stw_s\t\t"); + case X_ST_WS: + ot("__st.ws\t\t"); outdec((int)data); outlocal(tmp->sym); nl(); break; - case X_STB_S: - ot("__stb_s\t\t"); + case X_ST_US: + ot("__st.us\t\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -1199,8 +1199,8 @@ void gen_code (INS *tmp) nl(); break; - case X_INDEX_CR: - ot("__index.cr\t"); + case X_INDEX_UR: + ot("__index.ur\t"); out_type(type, data); nl(); break; @@ -1211,8 +1211,8 @@ void gen_code (INS *tmp) nl(); break; - case X_ST_CAT: - ot("__st.cat\t"); + case X_ST_UAT: + ot("__st.uat\t"); out_type(type, data); nl(); break; @@ -1235,55 +1235,55 @@ void gen_code (INS *tmp) /* i-codes for extending a byte to a word */ - case I_EXTW: - ol("__extw"); + case I_EXT_BR: + ol("__ext.br"); break; - case I_EXTUW: - ol("__extuw"); + case I_EXT_UR: + ol("__ext.ur"); break; /* i-codes for math with the primary register */ - case I_COMW: - ol("__comw"); + case I_COM_WR: + ol("__com.wr"); break; - case I_NEGW: - ol("__negw"); + case I_NEG_WR: + ol("__neg.wr"); break; - case I_ADDWS: - ol("__addws"); + case I_ADD_WT: + ol("__add.wt"); break; - case I_ADDWI: - ot("__addwi\t\t"); + case I_ADD_WI: + ot("__add.wi\t"); out_type(type, data); nl(); break; - case I_ADDW: - ot("__addw\t\t"); + case I_ADD_WM: + ot("__add.wm\t"); out_addr(type, data); nl(); break; - case I_ADDUB: - ot("__addub\t\t"); + case I_ADD_UM: + ot("__add.um\t"); out_addr(type, data); nl(); break; - case X_ADDW_S: - ot("__addw_s\t"); + case X_ADD_WS: + ot("__add.ws\t"); outdec((int)data); outlocal(tmp->sym); nl(); break; - case X_ADDUB_S: - ot("__addub_s\t"); + case X_ADD_US: + ot("__add.us\t"); outdec((int)data); outlocal(tmp->sym); nl(); @@ -1295,132 +1295,132 @@ void gen_code (INS *tmp) nl(); break; - case I_SUBWS: - ol("__subws"); + case I_SUB_WT: + ol("__sub.wt"); break; - case I_SUBWI: - ot("__subwi\t\t"); + case I_SUB_WI: + ot("__sub.wi\t"); out_type(type, data); nl(); break; - case I_SUBW: - ot("__subw\t\t"); + case I_SUB_WM: + ot("__sub.wm\t"); out_addr(type, data); nl(); break; - case I_SUBUB: - ot("__subub\t\t"); + case I_SUB_UM: + ot("__sub.um\t"); out_addr(type, data); nl(); break; - case I_ISUBWI: - ot("__isubwi\t"); + case I_ISUB_WI: + ot("__isub.wi\t"); out_type(type, data); nl(); break; - case I_ANDWS: - ol("__andws"); + case I_AND_WT: + ol("__and.wt"); break; - case I_ANDWI: - ot("__andwi\t\t"); + case I_AND_WI: + ot("__and.wi\t"); out_type(type, data); nl(); break; - case I_ANDW: - ot("__andw\t\t"); + case I_AND_WM: + ot("__and.wm\t"); out_addr(type, data); nl(); break; - case I_ANDUB: - ot("__andub\t\t"); + case I_AND_UM: + ot("__and.um\t"); out_addr(type, data); nl(); break; - case I_EORWS: - ol("__eorws"); + case I_EOR_WT: + ol("__eor.wt"); break; - case I_EORWI: - ot("__eorwi\t\t"); + case I_EOR_WI: + ot("__eor.wi\t"); out_type(type, data); nl(); break; - case I_EORW: - ot("__eorw\t\t"); + case I_EOR_WM: + ot("__eor.wm\t"); out_addr(type, data); nl(); break; - case I_EORUB: - ot("__eorub\t\t"); + case I_EOR_UM: + ot("__eor.um\t"); out_addr(type, data); nl(); break; - case I_ORWS: - ol("__orws"); + case I_OR_WT: + ol("__or.wt"); break; - case I_ORWI: - ot("__orwi\t\t"); + case I_OR_WI: + ot("__or.wi\t\t"); out_type(type, data); nl(); break; - case I_ORW: - ot("__orw\t\t"); + case I_OR_WM: + ot("__or.wm\t"); out_addr(type, data); nl(); break; - case I_ORUB: - ot("__orub\t\t"); + case I_OR_UM: + ot("__or.um\t"); out_addr(type, data); nl(); break; - case I_ASLWS: - ol("__aslws"); + case I_ASL_WT: + ol("__asl.wt"); break; - case I_ASLWI: - ot("__aslwi\t\t"); + case I_ASL_WI: + ot("__asl.wi\t"); out_type(type, data); nl(); break; - case I_ASLW: - ol("__aslw"); + case I_ASL_WR: + ol("__asl.wr"); break; - case I_ASRWI: - ot("__asrwi\t\t"); + case I_ASR_WI: + ot("__asr.wi\t"); out_type(type, data); nl(); break; - case I_ASRW: - ol("__asrw"); + case I_ASR_WR: + ol("__asr.wr"); break; - case I_LSRWI: - ot("__lsrwi\t\t"); + case I_LSR_WI: + ot("__lsr.wi\t"); out_type(type, data); nl(); break; - case I_MULWI: - ot("__mulwi\t\t"); + case I_MUL_WI: + ot("__mul.wi\t"); outdec((int)data); nl(); break; diff --git a/src/hucc/defs.h b/src/hucc/defs.h index fb30e15c..93e4b92e 100644 --- a/src/hucc/defs.h +++ b/src/hucc/defs.h @@ -72,212 +72,212 @@ enum ICODE { I_SAVESP, I_LOADSP, I_MODSP, - I_PUSHW, - I_POPW, - I_SPUSHW, /* push and pop on the hw-stack */ - I_SPUSHB, /* to temporarily save data */ - I_SPOPW, - I_SPOPB, + I_PUSH_WR, + I_POP_WR, + I_SPUSH_WR, /* push and pop on the hw-stack */ + I_SPUSH_UR, /* to temporarily save data */ + I_SPOP_WR, + I_SPOP_UR, /* i-codes for handling boolean tests and branching */ - I_SWITCHW, - I_SWITCHB, + I_SWITCH_WR, + I_SWITCH_UR, I_CASE, I_ENDCASE, I_LABEL, I_ALIAS, I_BRA, I_DEF, - I_CMPW, - I_CMPB, - X_CMPWI_EQ, - X_CMPWI_NE, - I_NOTW, - I_TSTW, + I_CMP_WT, + I_CMP_UT, + X_TST_WI, + X_NOT_WI, + I_NOT_WR, + I_TST_WR, I_BFALSE, I_BTRUE, - X_TZB, - X_TZBP, - X_TZB_S, - X_TZW, - X_TZWP, - X_TZW_S, - X_TNZB, - X_TNZBP, - X_TNZB_S, - X_TNZW, - X_TNZWP, - X_TNZW_S, + X_NOT_UM, + X_NOT_UP, + X_NOT_US, + X_NOT_WM, + X_NOT_WP, + X_NOT_WS, + X_TST_UM, + X_TST_UP, + X_TST_US, + X_TST_WM, + X_TST_WP, + X_TST_WS, /* i-codes for loading the primary register */ - I_LDWI, + I_LD_WI, I_LEA_S, - I_LDW, - I_LDB, - I_LDUB, + I_LD_WM, + I_LD_BM, + I_LD_UM, - I_LDWP, - I_LDBP, - I_LDUBP, + I_LD_WP, + I_LD_BP, + I_LD_UP, X_LD_WAR, X_LD_BAR, - X_LD_CAR, + X_LD_UAR, - X_LDW_S, - X_LDB_S, - X_LDUB_S, + X_LD_WS, + X_LD_BS, + X_LD_US, X_LDP_WAR, X_LDP_BAR, - X_LDP_CAR, + X_LDP_UAR, /* i-codes for pre- and post- increment and decrement */ X_INCLD_WM, X_INCLD_BM, - X_INCLD_CM, + X_INCLD_UM, X_DECLD_WM, X_DECLD_BM, - X_DECLD_CM, + X_DECLD_UM, X_LDINC_WM, X_LDINC_BM, - X_LDINC_CM, + X_LDINC_UM, X_LDDEC_WM, X_LDDEC_BM, - X_LDDEC_CM, + X_LDDEC_UM, X_INC_WMQ, - X_INC_CMQ, + X_INC_UMQ, X_DEC_WMQ, - X_DEC_CMQ, + X_DEC_UMQ, X_INCLD_WS, X_INCLD_BS, - X_INCLD_CS, + X_INCLD_US, X_DECLD_WS, X_DECLD_BS, - X_DECLD_CS, + X_DECLD_US, X_LDINC_WS, X_LDINC_BS, - X_LDINC_CS, + X_LDINC_US, X_LDDEC_WS, X_LDDEC_BS, - X_LDDEC_CS, + X_LDDEC_US, X_INC_WSQ, - X_INC_CSQ, + X_INC_USQ, X_DEC_WSQ, - X_DEC_CSQ, + X_DEC_USQ, X_INCLD_WAR, X_INCLD_BAR, - X_INCLD_CAR, + X_INCLD_UAR, X_DECLD_WAR, X_DECLD_BAR, - X_DECLD_CAR, + X_DECLD_UAR, X_LDINC_WAR, X_LDINC_BAR, - X_LDINC_CAR, + X_LDINC_UAR, X_LDDEC_WAR, X_LDDEC_BAR, - X_LDDEC_CAR, + X_LDDEC_UAR, X_INC_WARQ, - X_INC_CARQ, + X_INC_UARQ, X_DEC_WARQ, - X_DEC_CARQ, + X_DEC_UARQ, /* i-codes for saving the primary register */ - I_STWZ, - I_STBZ, - I_STWI, - I_STBI, - I_STWIP, - I_STBIP, - I_STW, - I_STB, - I_STWP, - I_STBP, - I_STWPS, - I_STBPS, - X_STWI_S, - X_STBI_S, - X_STW_S, - X_STB_S, + I_ST_WMZ, + I_ST_UMZ, + I_ST_WMI, + I_ST_UMI, + I_ST_WPI, + I_ST_UPI, + I_ST_WM, + I_ST_UM, + I_ST_WP, + I_ST_UP, + I_ST_WPT, + I_ST_UPT, + X_ST_WSI, + X_ST_USI, + X_ST_WS, + X_ST_US, X_INDEX_WR, - X_INDEX_CR, + X_INDEX_UR, X_ST_WAT, - X_ST_CAT, + X_ST_UAT, /* i-codes for extending the primary register */ - I_EXTW, - I_EXTUW, + I_EXT_BR, + I_EXT_UR, /* i-codes for math with the primary register */ - I_COMW, - I_NEGW, + I_COM_WR, + I_NEG_WR, - I_ADDWS, - I_ADDWI, - I_ADDW, - I_ADDUB, - X_ADDW_S, - X_ADDUB_S, + I_ADD_WT, + I_ADD_WI, + I_ADD_WM, + I_ADD_UM, + X_ADD_WS, + X_ADD_US, I_ADDBI_P, - I_SUBWS, - I_SUBWI, - I_SUBW, - I_SUBUB, + I_SUB_WT, + I_SUB_WI, + I_SUB_WM, + I_SUB_UM, - I_ISUBWI, + I_ISUB_WI, - I_ANDWS, - I_ANDWI, - I_ANDW, - I_ANDUB, + I_AND_WT, + I_AND_WI, + I_AND_WM, + I_AND_UM, - I_EORWS, - I_EORWI, - I_EORW, - I_EORUB, + I_EOR_WT, + I_EOR_WI, + I_EOR_WM, + I_EOR_UM, - I_ORWS, - I_ORWI, - I_ORW, - I_ORUB, + I_OR_WT, + I_OR_WI, + I_OR_WM, + I_OR_UM, - I_ASLWS, - I_ASLWI, - I_ASLW, + I_ASL_WT, + I_ASL_WI, + I_ASL_WR, - I_ASRWI, - I_ASRW, + I_ASR_WI, + I_ASR_WR, - I_LSRWI, + I_LSR_WI, - I_MULWI, + I_MUL_WI, /* i-codes for 32-bit longs */ diff --git a/src/hucc/expr.c b/src/hucc/expr.c index 451b584b..9954bbeb 100644 --- a/src/hucc/expr.c +++ b/src/hucc/expr.c @@ -758,7 +758,7 @@ int heir11 (LVALUE *lval, int comma) if (!deferred && !ptr->far) gadd(NULL, NULL); if (deferred) { - out_ins(I_ADDWI, T_SYMBOL, (intptr_t)ptr); + out_ins(I_ADD_WI, T_SYMBOL, (intptr_t)ptr); deferred = false; } lval->symbol = 0; @@ -837,7 +837,7 @@ int heir11 (LVALUE *lval, int comma) } if (k && direct == 0) rvalue(lval); - out_ins(I_ADDWI, T_VALUE, ptr->offset); // move pointer from struct begin to struct member + out_ins(I_ADD_WI, T_VALUE, ptr->offset); // move pointer from struct begin to struct member lval->symbol = ptr; lval->indirect = ptr->type; // lval->indirect = lval->val_type = ptr->type lval->ptr_type = 0; @@ -889,7 +889,7 @@ void store (LVALUE *lval) if (lval->symbol) putmem(lval->symbol); else - out_ins(I_STW, T_VALUE, lval->value); + out_ins(I_ST_WM, T_VALUE, lval->value); } } } diff --git a/src/hucc/function.c b/src/hucc/function.c index 50ad7b5a..f1f44e9f 100644 --- a/src/hucc/function.c +++ b/src/hucc/function.c @@ -522,13 +522,13 @@ int getarg (int t, int syntax, int otag, int is_fastcall) #define SPILLB(a) { \ spilled_args[sparg_idx] = (a); \ spilled_arg_sizes[sparg_idx++] = 1; \ - out_ins(I_SPUSHB, 0, 0); \ + out_ins(I_SPUSH_UR, 0, 0); \ } #define SPILLW(a) { \ spilled_args[sparg_idx] = (a); \ spilled_arg_sizes[sparg_idx++] = 2; \ - out_ins(I_SPUSHW, 0, 0); \ + out_ins(I_SPUSH_WR, 0, 0); \ } void callfunction (char *ptr) @@ -577,7 +577,7 @@ void callfunction (char *ptr) if (ptr == NULL) { /* save indirect call function-ptr on the hardware-stack */ - out_ins(I_SPUSHW, 0, 0); + out_ins(I_SPUSH_WR, 0, 0); } else { /* fastcall check, but don't know how many parameters */ if ((is_fc = fastcall_look(ptr, -1, NULL)) == 0) { @@ -658,20 +658,20 @@ void callfunction (char *ptr) if (i < max_fc_arg) SPILLB(fast->argname[j]) else - out_ins(I_STB, T_LITERAL, (intptr_t)fast->argname[j]); + out_ins(I_ST_UM, T_LITERAL, (intptr_t)fast->argname[j]); break; case TYPE_WORD: if (i < max_fc_arg) SPILLW(fast->argname[j]) else - out_ins(I_STW, T_LITERAL, (intptr_t)fast->argname[j]); + out_ins(I_ST_WM, T_LITERAL, (intptr_t)fast->argname[j]); break; case TYPE_FARPTR: arg_to_fptr(fast, j, arg_idx + i, adj); if (i < max_fc_arg) { - out_ins(I_LDUB, T_LITERAL, (intptr_t)fast->argname[j]); + out_ins(I_LD_UM, T_LITERAL, (intptr_t)fast->argname[j]); SPILLB(fast->argname[j]) - out_ins(I_LDW, T_LITERAL, (intptr_t)fast->argname[j + 1]); + out_ins(I_LD_WM, T_LITERAL, (intptr_t)fast->argname[j + 1]); SPILLW(fast->argname[j + 1]) } j += 1; @@ -679,11 +679,11 @@ void callfunction (char *ptr) case TYPE_DWORD: arg_to_dword(fast, j, arg_idx + i, adj); if (i < max_fc_arg) { - out_ins(I_LDW, T_LITERAL, (intptr_t)fast->argname[j]); + out_ins(I_LD_WM, T_LITERAL, (intptr_t)fast->argname[j]); SPILLW(fast->argname[j]) - out_ins(I_LDW, T_LITERAL, (intptr_t)fast->argname[j + 1]); + out_ins(I_LD_WM, T_LITERAL, (intptr_t)fast->argname[j + 1]); SPILLW(fast->argname[j + 1]) - out_ins(I_LDW, T_LITERAL, (intptr_t)fast->argname[j + 2]); + out_ins(I_LD_WM, T_LITERAL, (intptr_t)fast->argname[j + 2]); SPILLW(fast->argname[j + 2]) } j += 2; @@ -725,27 +725,27 @@ void callfunction (char *ptr) /* Reloading corrupts acc, so we need to save it if it is used by the callee. */ if (uses_acc) - out_ins(I_STW, T_LITERAL, (intptr_t)"__temp"); + out_ins(I_ST_WM, T_LITERAL, (intptr_t)"__temp"); for (i = sparg_idx - 1; i > -1; i--) { if (spilled_arg_sizes[i] == 1) { - out_ins(I_SPOPB, 0, 0); - out_ins(I_STB, T_LITERAL, (intptr_t)spilled_args[i]); + out_ins(I_SPOP_UR, 0, 0); + out_ins(I_ST_UM, T_LITERAL, (intptr_t)spilled_args[i]); } else { - out_ins(I_SPOPW, 0, 0); + out_ins(I_SPOP_WR, 0, 0); if (spilled_args[i]) - out_ins(I_STW, T_LITERAL, (intptr_t)spilled_args[i]); + out_ins(I_ST_WM, T_LITERAL, (intptr_t)spilled_args[i]); } } if (uses_acc) - out_ins(I_LDW, T_LITERAL, (intptr_t)"__temp"); + out_ins(I_LD_WM, T_LITERAL, (intptr_t)"__temp"); } if (ptr == NULL) { /* restore indirect call function-ptr from the hardware-stack */ - out_ins(I_SPOPW, 0, 0); + out_ins(I_SPOP_WR, 0, 0); out_ins(I_CALLP, 0, 0); } else { if (fast && !(fast->flags & FASTCALL_XSAFE)) @@ -849,10 +849,10 @@ void arg_flush (int arg, int adj) i++; ins = &ins_stack[idx]; - if ((ins->type == T_STACK) && (ins->code == I_LDW)) { + if ((ins->type == T_STACK) && (ins->code == I_LD_WM)) { if (i < nb) { ins = &ins_stack[idx + 1]; - if ((ins->code == I_ADDWI) && (ins->type == T_VALUE)) + if ((ins->code == I_ADD_WI) && (ins->type == T_VALUE)) ins->data -= adj; } } @@ -896,11 +896,11 @@ void arg_to_fptr (struct fastcall *fast, int i, int arg, int adj) switch (sym->ident) { case FUNCTION: case ARRAY: - if (ins->code == I_LDWI) + if (ins->code == I_LD_WI) err = 0; break; case POINTER: - if (ins->code == I_LDW) + if (ins->code == I_LD_WM) err = 0; break; } @@ -914,12 +914,12 @@ void arg_to_fptr (struct fastcall *fast, int i, int arg, int adj) sym = (SYMBOL *)ins->data; switch (sym->ident) { case ARRAY: - if ((ins->code == I_LDWI) || - (ins->code == I_ADDWI)) + if ((ins->code == I_LD_WI) || + (ins->code == I_ADD_WI)) err = 0; break; case POINTER: - if (ins->code == I_LDW) + if (ins->code == I_LD_WM) err = 0; break; } @@ -929,8 +929,8 @@ void arg_to_fptr (struct fastcall *fast, int i, int arg, int adj) /* check if last instruction is a pointer dereference */ switch (ins_stack[ arg_list[arg][0] + nb - 1 ].code) { - case I_LDBP: - case I_LDWP: + case I_LD_UP: + case I_LD_WP: err = 1; break; default: @@ -1007,7 +1007,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) /* check arg */ if (nb == 1) { /* immediate value */ - if ((ins->code == I_LDWI) && (ins->type == T_VALUE)) { + if ((ins->code == I_LD_WI) && (ins->type == T_VALUE)) { ins->code = X_LDD_I; ins->arg[0] = fast->argname[i + 1]; ins->arg[1] = fast->argname[i + 2]; @@ -1015,7 +1015,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) } /* var/ptr */ - else if ((((ins->code == I_LDW) || (ins->code == I_LDB) || (ins->code == I_LDUB)) + else if ((((ins->code == I_LD_WM) || (ins->code == I_LD_BM) || (ins->code == I_LD_UM)) && (ins->type == T_SYMBOL)) || (ins->type == T_LABEL)) { /* check special cases */ if (ins->type == T_LABEL) { @@ -1030,7 +1030,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) if (sym->ident == POINTER) gen = 1; else if (sym->ident == VARIABLE) { - if (ins->code == I_LDW) + if (ins->code == I_LD_WM) ins->code = X_LDD_W; else ins->code = X_LDD_B; @@ -1044,7 +1044,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) } /* var/ptr */ - else if ((ins->code == X_LDW_S) || (ins->code == X_LDB_S) || ins->code == X_LDUB_S) { + else if ((ins->code == X_LD_WS) || (ins->code == X_LD_BS) || ins->code == X_LD_US) { /* get symbol */ sym = ins->sym; @@ -1053,7 +1053,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) if (sym->ident == POINTER) gen = 1; else if (sym->ident == VARIABLE) { - if (ins->code == X_LDW_S) + if (ins->code == X_LD_WS) ins->code = X_LDD_S_W; else ins->code = X_LDD_S_B; @@ -1077,7 +1077,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) } /* array */ - else if ((ins->code == I_LDWI) && (ins->type == T_SYMBOL)) { + else if ((ins->code == I_LD_WI) && (ins->type == T_SYMBOL)) { /* get symbol */ sym = (SYMBOL *)ins->data; @@ -1088,7 +1088,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) } else if (nb == 2) { /* array */ - if ((ins->code == I_LDWI) && (ins->type == T_SYMBOL)) { + if ((ins->code == I_LD_WI) && (ins->type == T_SYMBOL)) { /* get symbol */ sym = (SYMBOL *)ins->data; @@ -1097,7 +1097,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) ptr = ins; ins = &ins_stack[idx + 1]; - if ((ins->code == I_ADDWI) && (ins->type == T_VALUE)) { + if ((ins->code == I_ADD_WI) && (ins->type == T_VALUE)) { gen_ins(ptr); gen = 1; } @@ -1111,7 +1111,7 @@ void arg_to_dword (struct fastcall *fast, int i, int arg, int adj) err = 0; if (strcmp(fast->argname[i], "#acc") != 0) { - tmp.code = I_STW; + tmp.code = I_ST_WM; tmp.type = T_SYMBOL; tmp.data = (intptr_t)fast->argname[i]; gen_ins(&tmp); diff --git a/src/hucc/gen.c b/src/hucc/gen.c index 371e2320..5aa924b0 100644 --- a/src/hucc/gen.c +++ b/src/hucc/gen.c @@ -39,7 +39,7 @@ void getmem (SYMBOL *sym) char *data; if ((sym->ident != POINTER) && (sym->type == CCHAR || sym->type == CUCHAR)) { - int op = (sym->type & CUNSIGNED) ? I_LDUB : I_LDB; + int op = (sym->type & CUNSIGNED) ? I_LD_UM : I_LD_BM; if ((sym->storage & STORAGE) == LSTATIC) out_ins(op, T_LABEL, glint(sym)); else @@ -47,11 +47,11 @@ void getmem (SYMBOL *sym) } else { if ((sym->storage & STORAGE) == LSTATIC) - out_ins(I_LDW, T_LABEL, glint(sym)); + out_ins(I_LD_WM, T_LABEL, glint(sym)); else if ((sym->storage & STORAGE) == CONST && (data = get_const(sym))) - out_ins(I_LDWI, T_LITERAL, (intptr_t)data); + out_ins(I_LD_WI, T_LITERAL, (intptr_t)data); else - out_ins(I_LDW, T_SYMBOL, (intptr_t)sym); + out_ins(I_LD_WM, T_SYMBOL, (intptr_t)sym); } } @@ -64,7 +64,7 @@ void getloc (SYMBOL *sym) int value; if ((sym->storage & STORAGE) == LSTATIC) - out_ins(I_LDWI, T_LABEL, glint(sym)); + out_ins(I_LD_WI, T_LABEL, glint(sym)); else { #if ULI_NORECURSE value = glint(sym); @@ -74,7 +74,7 @@ void getloc (SYMBOL *sym) if (NAMEALLOC <= sprintf(locsym->name, "_%s_lend - %ld", current_fn, (long) -value)) error("norecurse local name too long"); - out_ins(I_LDWI, T_SYMBOL, (intptr_t)locsym); + out_ins(I_LD_WI, T_SYMBOL, (intptr_t)locsym); } else { value -= stkp; @@ -97,9 +97,9 @@ void putmem (SYMBOL *sym) /* XXX: What about 1-byte structs? */ if ((sym->ident != POINTER) & (sym->type == CCHAR || sym->type == CUCHAR)) - code = I_STB; + code = I_ST_UM; else - code = I_STW; + code = I_ST_WM; if ((sym->storage & STORAGE) == LSTATIC) out_ins(code, T_LABEL, glint(sym)); @@ -115,9 +115,9 @@ void putmem (SYMBOL *sym) void putstk (char typeobj) { if (typeobj == CCHAR || typeobj == CUCHAR) - out_ins(I_STBPS, 0, 0); + out_ins(I_ST_UPT, 0, 0); else - out_ins(I_STWPS, 0, 0); + out_ins(I_ST_WPT, 0, 0); stkp = stkp + INTSIZE; } @@ -128,14 +128,14 @@ void putstk (char typeobj) */ void indirect (char typeobj) { - out_ins(I_STW, T_PTR, 0); + out_ins(I_ST_WM, T_PTR, 0); if (typeobj == CCHAR) - out_ins(I_LDBP, T_PTR, 0); + out_ins(I_LD_BP, T_PTR, 0); else if (typeobj == CUCHAR) - out_ins(I_LDUBP, T_PTR, 0); + out_ins(I_LD_UP, T_PTR, 0); else - out_ins(I_LDWP, T_PTR, 0); + out_ins(I_LD_WP, T_PTR, 0); } void farpeek (SYMBOL *ptr) @@ -157,7 +157,7 @@ void immed (int type, intptr_t data) { if (type == T_VALUE && (data < -32768 || data > 65535)) warning(W_GENERAL, "large integer truncated"); - out_ins(I_LDWI, type, data); + out_ins(I_LD_WI, type, data); } /* @@ -166,7 +166,7 @@ void immed (int type, intptr_t data) */ void gpush (void) { - out_ins(I_PUSHW, T_VALUE, INTSIZE); + out_ins(I_PUSH_WR, T_VALUE, INTSIZE); stkp = stkp - INTSIZE; } @@ -176,7 +176,7 @@ void gpush (void) */ void gpusharg (int size) { - out_ins(I_PUSHW, T_SIZE, size); + out_ins(I_PUSH_WR, T_SIZE, size); stkp = stkp - size; } @@ -186,7 +186,7 @@ void gpusharg (int size) */ void gpop (void) { - out_ins(I_POPW, 0, 0); + out_ins(I_POP_WR, 0, 0); stkp = stkp + INTSIZE; } @@ -223,7 +223,7 @@ void jump (int label) */ void testjump (int label, int ft) { - out_ins(I_TSTW, 0, 0); + out_ins(I_TST_WR, 0, 0); if (ft) out_ins(I_BTRUE, T_LABEL, label); else @@ -252,7 +252,7 @@ int modstk (int newstkp) */ void gaslint (void) { - out_ins(I_ASLW, 0, 0); + out_ins(I_ASL_WR, 0, 0); } /* @@ -260,7 +260,7 @@ void gaslint (void) */ void gasrint (void) { - out_ins(I_ASRW, 0, 0); + out_ins(I_ASR_WR, 0, 0); } /* @@ -268,7 +268,7 @@ void gasrint (void) */ void gswitch (int nlab) { - out_ins(I_SWITCHW, T_LABEL, nlab); + out_ins(I_SWITCH_WR, T_LABEL, nlab); } /* @@ -293,8 +293,8 @@ void gadd (LVALUE *lval, LVALUE *lval2) /* XXX: isn't this done in expr.c already? */ /* Nope, it is used when calculating a pointer variable address into a word array */ if (dbltest(lval2, lval)) - out_ins(I_ASLWS, 0, 0); - out_ins(I_ADDWS, 0, 0); + out_ins(I_ASL_WT, 0, 0); + out_ins(I_ADD_WT, 0, 0); stkp = stkp + INTSIZE; } @@ -304,7 +304,7 @@ void gadd (LVALUE *lval, LVALUE *lval2) */ void gsub (void) { - out_ins(I_SUBWS, 0, 0); + out_ins(I_SUB_WT, 0, 0); stkp = stkp + INTSIZE; } @@ -324,7 +324,7 @@ void gmult (int is_unsigned) void gmult_imm (int value) { - out_ins(I_MULWI, T_VALUE, (intptr_t)value); + out_ins(I_MUL_WI, T_VALUE, (intptr_t)value); } /* @@ -369,7 +369,7 @@ void gmod (int is_unsigned) */ void gor (void) { - out_ins(I_ORWS, 0, 0); + out_ins(I_OR_WT, 0, 0); stkp = stkp + INTSIZE; } @@ -379,7 +379,7 @@ void gor (void) */ void gxor (void) { - out_ins(I_EORWS, 0, 0); + out_ins(I_EOR_WT, 0, 0); stkp = stkp + INTSIZE; } @@ -389,7 +389,7 @@ void gxor (void) */ void gand (void) { - out_ins(I_ANDWS, 0, 0); + out_ins(I_AND_WT, 0, 0); stkp = stkp + INTSIZE; } @@ -426,7 +426,7 @@ void gasl (void) */ void gneg (void) { - out_ins(I_NEGW, 0, 0); + out_ins(I_NEG_WR, 0, 0); } /* @@ -435,7 +435,7 @@ void gneg (void) */ void gcom (void) { - out_ins(I_COMW, 0, 0); + out_ins(I_COM_WR, 0, 0); } /* @@ -444,7 +444,7 @@ void gcom (void) */ void gbool (void) { - out_ins(I_TSTW, 0, 0); + out_ins(I_TST_WR, 0, 0); } /* @@ -453,7 +453,7 @@ void gbool (void) */ void glneg (void) { - out_ins(I_NOTW, 0, 0); + out_ins(I_NOT_WR, 0, 0); } /* @@ -465,11 +465,11 @@ void ginc (LVALUE *lval) if (lval->ptr_type == CINT || lval->ptr_type == CUINT || (sym && (sym->ptr_order > 1 || (sym->ident == ARRAY && sym->ptr_order > 0)))) - out_ins(I_ADDWI, T_VALUE, 2); + out_ins(I_ADD_WI, T_VALUE, 2); else if (lval->ptr_type == CSTRUCT) - out_ins(I_ADDWI, T_VALUE, lval->tagsym->size); + out_ins(I_ADD_WI, T_VALUE, lval->tagsym->size); else - out_ins(I_ADDWI, T_VALUE, 1); + out_ins(I_ADD_WI, T_VALUE, 1); } /* @@ -481,11 +481,11 @@ void gdec (LVALUE *lval) if (lval->ptr_type == CINT || lval->ptr_type == CUINT || (sym && (sym->ptr_order > 1 || (sym->ident == ARRAY && sym->ptr_order > 0)))) - out_ins(I_SUBWI, T_VALUE, 2); + out_ins(I_SUB_WI, T_VALUE, 2); else if (lval->ptr_type == CSTRUCT) - out_ins(I_SUBWI, T_VALUE, lval->tagsym->size); + out_ins(I_SUB_WI, T_VALUE, lval->tagsym->size); else - out_ins(I_SUBWI, T_VALUE, 1); + out_ins(I_SUB_WI, T_VALUE, 1); } /* @@ -503,9 +503,9 @@ void gdec (LVALUE *lval) void geq (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"eq_b"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"eq_b"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"eq_w"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"eq_w"); stkp = stkp + INTSIZE; } @@ -516,9 +516,9 @@ void geq (int is_byte) void gne (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"ne_b"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"ne_b"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"ne_w"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"ne_w"); stkp = stkp + INTSIZE; } @@ -529,9 +529,9 @@ void gne (int is_byte) void glt (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"lt_sb"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"lt_sb"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"lt_sw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"lt_sw"); stkp = stkp + INTSIZE; } @@ -542,9 +542,9 @@ void glt (int is_byte) void gle (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"le_sb"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"le_sb"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"le_sw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"le_sw"); stkp = stkp + INTSIZE; } @@ -555,9 +555,9 @@ void gle (int is_byte) void ggt (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"gt_sb"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"gt_sb"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"gt_sw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"gt_sw"); stkp = stkp + INTSIZE; } @@ -568,9 +568,9 @@ void ggt (int is_byte) void gge (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"ge_sb"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"ge_sb"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"ge_sw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"ge_sw"); stkp = stkp + INTSIZE; } @@ -581,9 +581,9 @@ void gge (int is_byte) void gult (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"lt_ub"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"lt_ub"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"lt_uw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"lt_uw"); stkp = stkp + INTSIZE; } @@ -594,9 +594,9 @@ void gult (int is_byte) void gule (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"le_ub"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"le_ub"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"le_uw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"le_uw"); stkp = stkp + INTSIZE; } @@ -607,9 +607,9 @@ void gule (int is_byte) void gugt (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"gt_ub"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"gt_ub"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"gt_uw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"gt_uw"); stkp = stkp + INTSIZE; } @@ -620,9 +620,9 @@ void gugt (int is_byte) void guge (int is_byte) { if (is_byte) - out_ins(I_CMPW, T_LIB, (intptr_t)"ge_ub"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"ge_ub"); else - out_ins(I_CMPW, T_LIB, (intptr_t)"ge_uw"); + out_ins(I_CMP_WT, T_LIB, (intptr_t)"ge_uw"); stkp = stkp + INTSIZE; } @@ -645,10 +645,10 @@ void gcast (int type) { switch (type) { case CCHAR: - out_ins(I_EXTW, 0, 0); + out_ins(I_EXT_BR, 0, 0); break; case CUCHAR: - out_ins(I_EXTUW, 0, 0); + out_ins(I_EXT_UR, 0, 0); break; case CINT: case CUINT: diff --git a/src/hucc/optimize.c b/src/hucc/optimize.c index 267e7329..d45c335a 100644 --- a/src/hucc/optimize.c +++ b/src/hucc/optimize.c @@ -47,11 +47,11 @@ unsigned char icode_flags[] = { 0, - /* i-code that retires the primary register contents */ + // i-code that retires the primary register contents /* I_FENCE */ 0, - /* i-codes for handling farptr */ + // i-codes for handling farptr /* I_FARPTR */ 0, /* I_FARPTR_I */ 0, @@ -60,19 +60,19 @@ unsigned char icode_flags[] = { /* I_FGETB */ 0, /* I_FGETUB */ 0, - /* i-codes for interrupts */ + // i-codes for interrupts /* I_SEI */ 0, /* I_CLI */ 0, - /* i-codes for calling functions */ + // i-codes for calling functions /* I_MACRO */ 0, /* I_CALL */ 0, /* I_CALLP */ 0, /* I_JSR */ 0, - /* i-codes for C functions and the C parameter stack */ + // i-codes for C functions and the C parameter stack /* I_ENTER */ 0, /* I_LEAVE */ 0, @@ -80,214 +80,214 @@ unsigned char icode_flags[] = { /* I_SAVESP */ 0, /* I_LOADSP */ 0, /* I_MODSP */ 0, - /* I_PUSHW */ 0, - /* I_POPW */ 0, - /* I_SPUSHW */ 0, - /* I_SPUSHB */ 0, - /* I_SPOPW */ 0, - /* I_SPOPB */ 0, + /* I_PUSH_WR */ 0, + /* I_POP_WR */ 0, + /* I_SPUSH_WR */ 0, + /* I_SPUSH_UR */ 0, + /* I_SPOP_WR */ 0, + /* I_SPOP_UR */ 0, - /* i-codes for handling boolean tests and branching */ + // i-codes for handling boolean tests and branching - /* I_SWITCHW */ 0, - /* I_SWITCHB */ 0, + /* I_SWITCH_WR */ 0, + /* I_SWITCH_UR */ 0, /* I_CASE */ 0, /* I_ENDCASE */ 0, /* I_LABEL */ 0, /* I_ALIAS */ 0, /* I_BRA */ 0, /* I_DEF */ 0, - /* I_CMPW */ 0, - /* I_CMPB */ 0, - /* X_CMPWI_EQ */ 0, - /* X_CMPWI_NE */ 0, - /* I_NOTW */ 0, - /* I_TSTW */ 0, + /* I_CMP_WT */ 0, + /* I_CMP_UT */ 0, + /* X_TST_WI */ 0, + /* X_NOT_WI */ 0, + /* I_NOT_WR */ 0, + /* I_TST_WR */ 0, /* I_BFALSE */ 0, /* I_BTRUE */ 0, - /* X_TZB */ 0, - /* X_TZBP */ 0, - /* X_TZB_S */ IS_SPREL, - /* X_TZW */ 0, - /* X_TZWP */ 0, - /* X_TZW_S */ IS_SPREL, - /* X_TNZB */ 0, - /* X_TNZBP */ 0, - /* X_TNZB_S */ IS_SPREL, - /* X_TNZW */ 0, - /* X_TNZWP */ 0, - /* X_TNZW_S */ IS_SPREL, - - /* i-codes for loading the primary register */ - - /* I_LDWI */ 0, + /* X_NOT_UM */ 0, + /* X_NOT_UP */ 0, + /* X_NOT_US */ IS_SPREL, + /* X_NOT_WM */ 0, + /* X_NOT_WP */ 0, + /* X_NOT_WS */ IS_SPREL, + /* X_TST_UM */ 0, + /* X_TST_UP */ 0, + /* X_TST_US */ IS_SPREL, + /* X_TST_WM */ 0, + /* X_TST_WP */ 0, + /* X_TST_WS */ IS_SPREL, + + // i-codes for loading the primary register + + /* I_LD_WI */ 0, /* I_LEA_S */ IS_SPREL, - /* I_LDW */ 0, - /* I_LDB */ 0, - /* I_LDUB */ 0, + /* I_LD_WM */ 0, + /* I_LD_BM */ 0, + /* I_LD_UM */ 0, - /* I_LDWP */ 0, - /* I_LDBP */ 0, - /* I_LDUBP */ 0, + /* I_LD_WP */ 0, + /* I_LD_BP */ 0, + /* I_LD_UP */ 0, /* X_LD_WAR */ 0, /* X_LD_BAR */ 0, - /* X_LD_CAR */ 0, + /* X_LD_UAR */ 0, - /* X_LDW_S */ IS_SPREL, - /* X_LDB_S */ IS_SPREL, - /* X_LDUB_S */ IS_SPREL, + /* X_LD_WS */ IS_SPREL, + /* X_LD_BS */ IS_SPREL, + /* X_LD_US */ IS_SPREL, /* X_LDP_WAR */ 0, /* X_LDP_BAR */ 0, - /* X_LDP_CAR */ 0, + /* X_LDP_UAR */ 0, - /* i-codes for pre- and post- increment and decrement */ + // i-codes for pre- and post- increment and decrement /* X_INCLD_WM */ 0, /* X_INCLD_BM */ 0, - /* X_INCLD_CM */ 0, + /* X_INCLD_UM */ 0, /* X_DECLD_WM */ 0, /* X_DECLD_BM */ 0, - /* X_DECLD_CM */ 0, + /* X_DECLD_UM */ 0, /* X_LDINC_WM */ 0, /* X_LDINC_BM */ 0, - /* X_LDINC_CM */ 0, + /* X_LDINC_UM */ 0, /* X_LDDEC_WM */ 0, /* X_LDDEC_BM */ 0, - /* X_LDDEC_CM */ 0, + /* X_LDDEC_UM */ 0, /* X_INC_WMQ */ 0, - /* X_INC_CMQ */ 0, + /* X_INC_UMQ */ 0, /* X_DEC_WMQ */ 0, - /* X_DEC_CMQ */ 0, + /* X_DEC_UMQ */ 0, /* X_INCLD_WS */ IS_SPREL, /* X_INCLD_BS */ IS_SPREL, - /* X_INCLD_CS */ IS_SPREL, + /* X_INCLD_US */ IS_SPREL, /* X_DECLD_WS */ IS_SPREL, /* X_DECLD_BS */ IS_SPREL, - /* X_DECLD_CS */ IS_SPREL, + /* X_DECLD_US */ IS_SPREL, /* X_LDINC_WS */ IS_SPREL, /* X_LDINC_BS */ IS_SPREL, - /* X_LDINC_CS */ IS_SPREL, + /* X_LDINC_US */ IS_SPREL, /* X_LDDEC_WS */ IS_SPREL, /* X_LDDEC_BS */ IS_SPREL, - /* X_LDDEC_CS */ IS_SPREL, + /* X_LDDEC_US */ IS_SPREL, /* X_INC_WSQ */ IS_SPREL, - /* X_INC_CSQ */ IS_SPREL, + /* X_INC_USQ */ IS_SPREL, /* X_DEC_WSQ */ IS_SPREL, - /* X_DEC_CSQ */ IS_SPREL, + /* X_DEC_USQ */ IS_SPREL, /* X_INCLD_WAR */ 0, /* X_INCLD_BAR */ 0, - /* X_INCLD_CAR */ 0, + /* X_INCLD_UAR */ 0, /* X_DECLD_WAR */ 0, /* X_DECLD_BAR */ 0, - /* X_DECLD_CAR */ 0, + /* X_DECLD_UAR */ 0, /* X_LDINC_WAR */ 0, /* X_LDINC_BAR */ 0, - /* X_LDINC_CAR */ 0, + /* X_LDINC_UAR */ 0, /* X_LDDEC_WAR */ 0, /* X_LDDEC_BAR */ 0, - /* X_LDDEC_CAR */ 0, + /* X_LDDEC_UAR */ 0, /* X_INC_WARQ */ 0, - /* X_INC_CARQ */ 0, + /* X_INC_UARQ */ 0, /* X_DEC_WARQ */ 0, - /* X_DEC_CARQ */ 0, - - /* i-codes for saving the primary register */ - - /* I_STWZ */ 0, - /* I_STBZ */ 0, - /* I_STWI */ 0, - /* I_STBI */ 0, - /* I_STWIP */ 0, - /* I_STBIP */ 0, - /* I_STW */ 0, - /* I_STB */ 0, - /* I_STWP */ 0, - /* I_STBP */ 0, - /* I_STWPS */ 0, - /* I_STBPS */ 0, - /* X_STWI_S */ IS_SPREL, - /* X_STBI_S */ IS_SPREL, - /* X_STW_S */ IS_SPREL, - /* X_STB_S */ IS_SPREL, + /* X_DEC_UARQ */ 0, + + // i-codes for saving the primary register + + /* I_ST_WMZ */ 0, + /* I_ST_UMZ */ 0, + /* I_ST_WMI */ 0, + /* I_ST_UMI */ 0, + /* I_ST_WPI */ 0, + /* I_ST_UPI */ 0, + /* I_ST_WM */ 0, + /* I_ST_UM */ 0, + /* I_ST_WP */ 0, + /* I_ST_UP */ 0, + /* I_ST_WPT */ 0, + /* I_ST_UPT */ 0, + /* X_ST_WSI */ IS_SPREL, + /* X_ST_USI */ IS_SPREL, + /* X_ST_WS */ IS_SPREL, + /* X_ST_US */ IS_SPREL, /* X_INDEX_WR */ 0, - /* X_INDEX_CR */ 0, + /* X_INDEX_UR */ 0, /* X_ST_WAT */ 0, - /* X_ST_CAT */ 0, + /* X_ST_UAT */ 0, - /* i-codes for extending the primary register */ + // i-codes for extending the primary register - /* I_EXTW */ 0, - /* I_EXTUW */ 0, + /* I_EXT_BR */ 0, + /* I_EXT_UR */ 0, - /* i-codes for math with the primary register */ + // i-codes for math with the primary register - /* I_COMW */ 0, - /* I_NEGW */ 0, + /* I_COM_WR */ 0, + /* I_NEG_WR */ 0, - /* I_ADDWS */ 0, - /* I_ADDWI */ 0, - /* I_ADDW */ 0, - /* I_ADDUB */ 0, - /* X_ADDW_S */ IS_SPREL, - /* X_ADDUB_S */ IS_SPREL, + /* I_ADD_WT */ 0, + /* I_ADD_WI */ 0, + /* I_ADD_WM */ 0, + /* I_ADD_UM */ 0, + /* X_ADD_WS */ IS_SPREL, + /* X_ADD_US */ IS_SPREL, /* I_ADDBI_P */ 0, - /* I_SUBWS */ 0, - /* I_SUBWI */ 0, - /* I_SUBW */ 0, - /* I_SUBUB */ 0, + /* I_SUB_WT */ 0, + /* I_SUB_WI */ 0, + /* I_SUB_WM */ 0, + /* I_SUB_UM */ 0, - /* I_ISUBWI */ 0, + /* I_ISUB_WI */ 0, - /* I_ANDWS */ 0, - /* I_ANDWI */ 0, - /* I_ANDW */ 0, - /* I_ANDUB */ 0, + /* I_AND_WT */ 0, + /* I_AND_WI */ 0, + /* I_AND_WM */ 0, + /* I_AND_UM */ 0, - /* I_EORWS */ 0, - /* I_EORWI */ 0, - /* I_EORW */ 0, - /* I_EORUB */ 0, + /* I_EOR_WT */ 0, + /* I_EOR_WI */ 0, + /* I_EOR_WM */ 0, + /* I_EOR_UM */ 0, - /* I_ORWS */ 0, - /* I_ORWI */ 0, - /* I_ORW */ 0, - /* I_ORUB */ 0, + /* I_OR_WT */ 0, + /* I_OR_WI */ 0, + /* I_OR_WM */ 0, + /* I_OR_UM */ 0, - /* I_ASLWS */ 0, - /* I_ASLWI */ 0, - /* I_ASLW */ 0, + /* I_ASL_WT */ 0, + /* I_ASL_WI */ 0, + /* I_ASL_WR */ 0, - /* I_ASRWI */ 0, - /* I_ASRW */ 0, + /* I_ASR_WI */ 0, + /* I_ASR_WR */ 0, - /* I_LSRWI */ 0, + /* I_LSR_WI */ 0, - /* I_MULWI */ 0, + /* I_MUL_WI */ 0, - /* i-codes for 32-bit longs */ + // i-codes for 32-bit longs /* X_LDD_I */ 0, /* X_LDD_W */ 0, @@ -416,23 +416,23 @@ void push_ins (INS *ins) * __getacc --> * __fence * - * __addwi / __subwi --> + * __add.wi / __sub.wi --> * __fence */ if ((q_nb >= 2) && - (p[1]->code == I_ADDWI || - p[1]->code == I_SUBWI || + (p[1]->code == I_ADD_WI || + p[1]->code == I_SUB_WI || p[1]->code == I_GETACC) ) { nb = 2; } /* - * __ldinc_wm / __incld_wm --> __inc_wm + * __ldinc.wm / __incld.wm --> __inc.wm * __fence * - * __lddec_wm / __decld_wm --> __dec_wm + * __lddec.wm / __decld.wm --> __dec.wm * __fence * * unused pre-increment or post-increment value @@ -442,79 +442,79 @@ void push_ins (INS *ins) ((q_nb >= 2) && (p[1]->code == X_INCLD_WM || p[1]->code == X_INCLD_BM || - p[1]->code == X_INCLD_CM || + p[1]->code == X_INCLD_UM || p[1]->code == X_LDINC_WM || p[1]->code == X_LDINC_BM || - p[1]->code == X_LDINC_CM || + p[1]->code == X_LDINC_UM || p[1]->code == X_DECLD_WM || p[1]->code == X_DECLD_BM || - p[1]->code == X_DECLD_CM || + p[1]->code == X_DECLD_UM || p[1]->code == X_LDDEC_WM || p[1]->code == X_LDDEC_BM || - p[1]->code == X_LDDEC_CM || + p[1]->code == X_LDDEC_UM || p[1]->code == X_INCLD_WS || p[1]->code == X_INCLD_BS || - p[1]->code == X_INCLD_CS || + p[1]->code == X_INCLD_US || p[1]->code == X_LDINC_WS || p[1]->code == X_LDINC_BS || - p[1]->code == X_LDINC_CS || + p[1]->code == X_LDINC_US || p[1]->code == X_DECLD_WS || p[1]->code == X_DECLD_BS || - p[1]->code == X_DECLD_CS || + p[1]->code == X_DECLD_US || p[1]->code == X_LDDEC_WS || p[1]->code == X_LDDEC_BS || - p[1]->code == X_LDDEC_CS || + p[1]->code == X_LDDEC_US || p[1]->code == X_INCLD_WAR || p[1]->code == X_INCLD_BAR || - p[1]->code == X_INCLD_CAR || + p[1]->code == X_INCLD_UAR || p[1]->code == X_LDINC_WAR || p[1]->code == X_LDINC_BAR || - p[1]->code == X_LDINC_CAR || + p[1]->code == X_LDINC_UAR || p[1]->code == X_DECLD_WAR || p[1]->code == X_DECLD_BAR || - p[1]->code == X_DECLD_CAR || + p[1]->code == X_DECLD_UAR || p[1]->code == X_LDDEC_WAR || p[1]->code == X_LDDEC_BAR || - p[1]->code == X_LDDEC_CAR) + p[1]->code == X_LDDEC_UAR) ) { /* replace code */ switch (p[1]->code) { case X_INCLD_WM: case X_LDINC_WM: p[1]->code = X_INC_WMQ; break; case X_INCLD_BM: - case X_INCLD_CM: + case X_INCLD_UM: case X_LDINC_BM: - case X_LDINC_CM: p[1]->code = X_INC_CMQ; break; + case X_LDINC_UM: p[1]->code = X_INC_UMQ; break; case X_DECLD_WM: case X_LDDEC_WM: p[1]->code = X_DEC_WMQ; break; case X_DECLD_BM: - case X_DECLD_CM: + case X_DECLD_UM: case X_LDDEC_BM: - case X_LDDEC_CM: p[1]->code = X_DEC_CMQ; break; + case X_LDDEC_UM: p[1]->code = X_DEC_UMQ; break; case X_INCLD_WS: case X_LDINC_WS: p[1]->code = X_INC_WSQ; break; case X_INCLD_BS: - case X_INCLD_CS: + case X_INCLD_US: case X_LDINC_BS: - case X_LDINC_CS: p[1]->code = X_INC_CSQ; break; + case X_LDINC_US: p[1]->code = X_INC_USQ; break; case X_DECLD_WS: case X_LDDEC_WS: p[1]->code = X_DEC_WSQ; break; case X_DECLD_BS: - case X_DECLD_CS: + case X_DECLD_US: case X_LDDEC_BS: - case X_LDDEC_CS: p[1]->code = X_DEC_CSQ; break; + case X_LDDEC_US: p[1]->code = X_DEC_USQ; break; case X_INCLD_WAR: case X_LDINC_WAR: p[1]->code = X_INC_WARQ; break; case X_INCLD_BAR: - case X_INCLD_CAR: + case X_INCLD_UAR: case X_LDINC_BAR: - case X_LDINC_CAR: p[1]->code = X_INC_CARQ; break; + case X_LDINC_UAR: p[1]->code = X_INC_UARQ; break; case X_DECLD_WAR: case X_LDDEC_WAR: p[1]->code = X_DEC_WARQ; break; case X_DECLD_BAR: - case X_DECLD_CAR: + case X_DECLD_UAR: case X_LDDEC_BAR: - case X_LDDEC_CAR: p[1]->code = X_DEC_CARQ; break; + case X_LDDEC_UAR: p[1]->code = X_DEC_UARQ; break; default: abort(); } nb = 1; @@ -537,28 +537,30 @@ void push_ins (INS *ins) /* 6-instruction patterns */ if (q_nb >= 6) { /* - * __ldwi p --> __ldw p - * __pushw __addwi i - * __stw __ptr __stw p - * __ldwp __ptr - * __addwi i - * __stwps + * __ld.wi p --> __ld.wm p + * __push.wr __add.wi i + * __st.wm __ptr __st.wm p + * __ld.wp __ptr + * __add.wi i + * __st.wpt + * + * JCB: Isn't this already handled by other rules? */ if - ((p[0]->code == I_STWPS) && - (p[1]->code == I_ADDWI || - p[1]->code == I_SUBWI) && - (p[2]->code == I_LDWP) && + ((p[0]->code == I_ST_WPT) && + (p[1]->code == I_ADD_WI || + p[1]->code == I_SUB_WI) && + (p[2]->code == I_LD_WP) && (p[2]->type == T_PTR) && - (p[3]->code == I_STW) && + (p[3]->code == I_ST_WM) && (p[3]->type == T_PTR) && - (p[4]->code == I_PUSHW) && - (p[5]->code == I_LDWI) + (p[4]->code == I_PUSH_WR) && + (p[5]->code == I_LD_WI) ) { *p[3] = *p[5]; - p[3]->code = I_STW; + p[3]->code = I_ST_WM; *p[4] = *p[1]; - p[5]->code = I_LDW; + p[5]->code = I_LD_WM; nb = 3; } @@ -594,106 +596,106 @@ void push_ins (INS *ins) /* 4-instruction patterns */ if (q_nb >= 4) { - /* __ldwi i --> __ldwi i - * __pushw __pushw - * __stw __ptr __ldw/_ldub i - * __ldwp/__ldubp __ptr + /* __ld.wi i --> __ld.wi i + * __push.wr __push.wr + * __st.wm __ptr __ld.{w/u}m i + * __ld.{w/u}p __ptr * * Load a variable from memory, this is generated for * code like a "+=", where the store can be optimized * later on. */ if - ((p[0]->code == I_LDWP || - p[0]->code == I_LDBP || - p[0]->code == I_LDUBP) && + ((p[0]->code == I_LD_WP || + p[0]->code == I_LD_BP || + p[0]->code == I_LD_UP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && - (p[2]->code == I_PUSHW) && - (p[3]->code == I_LDWI) + (p[2]->code == I_PUSH_WR) && + (p[3]->code == I_LD_WI) ) { /* replace code */ *p[1] = *p[3]; - if (p[0]->code == I_LDWP) - p[1]->code = I_LDW; + if (p[0]->code == I_LD_WP) + p[1]->code = I_LD_WM; else - if (p[0]->code == I_LDBP) - p[1]->code = I_LDB; + if (p[0]->code == I_LD_BP) + p[1]->code = I_LD_BM; else - p[1]->code = I_LDUB; + p[1]->code = I_LD_UM; nb = 1; } /* - * __lea_s i --> __lea_s i - * __pushw __pushw - * __stw __ptr __ldw_s/_ldub_s i + 2 - * __ldwp/__ldubp __ptr + * __lea.s i --> __lea.s i + * __push.wr __push.wr + * __st.wm __ptr __ld.{w/b/u}s (i + 2) + * __ld.{w/b/u}p __ptr * * Load a variable from memory, this is generated for * code like a "+=", where the store can be optimized * later on. */ else if - ((p[0]->code == I_LDWP || - p[0]->code == I_LDBP || - p[0]->code == I_LDUBP) && + ((p[0]->code == I_LD_WP || + p[0]->code == I_LD_BP || + p[0]->code == I_LD_UP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && - (p[2]->code == I_PUSHW) && + (p[2]->code == I_PUSH_WR) && (p[3]->code == I_LEA_S) ) { /* replace code */ *p[1] = *p[3]; - if (p[0]->code == I_LDWP) - p[1]->code = X_LDW_S; + if (p[0]->code == I_LD_WP) + p[1]->code = X_LD_WS; else - if (p[0]->code == I_LDBP) - p[1]->code = X_LDB_S; + if (p[0]->code == I_LD_BP) + p[1]->code = X_LD_BS; else - p[1]->code = X_LDUB_S; + p[1]->code = X_LD_US; p[1]-> data += 2; nb = 1; } /* - * __lea_s i --> __stwi_s/__stbi_s i,j - * __pushw - * __ldwi i - * __stwps/__stbps + * __lea.s i --> __st.{w/u}si i, j + * __push.wr + * __ld.wi j + * __st.{w/u}pt */ else if - ((p[0]->code == I_STWPS || - p[0]->code == I_STBPS) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ST_WPT || + p[0]->code == I_ST_UPT) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) && - (p[2]->code == I_PUSHW) && + (p[2]->code == I_PUSH_WR) && (p[3]->code == I_LEA_S) ) { /* replace code */ - p[3]->code = (p[0]->code == I_STWPS) ? X_STWI_S : X_STBI_S; + p[3]->code = (p[0]->code == I_ST_WPT) ? X_ST_WSI : X_ST_USI; p[3]->imm_type = p[1]->type; p[3]->imm_data = p[1]->data; nb = 3; } /* - * __lea_s i --> __lea_s i+j - * __pushw - * __ldwi j - * __addws + * __lea.s i --> __lea.s (i + j) + * __push.wr + * __ld.wi j + * __add.wt * * This is generated for address calculations into local * arrays and structs on the stack. */ else if - ((p[0]->code == I_ADDWS) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ADD_WT) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) && - (p[2]->code == I_PUSHW) && + (p[2]->code == I_PUSH_WR) && (p[3]->code == I_LEA_S) ) { /* replace code */ @@ -703,19 +705,19 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi i * j - * __pushw - * __ldwi j - * jsr umul + * __ld.wi i --> __ld.wi (i * j) + * __push.wr + * __ld.wi j + * jsr umul */ else if ((p[0]->code == I_JSR) && (p[0]->type == T_LIB) && (!strcmp((char *)p[0]->data, "umul")) && - (p[1]->code == I_LDWI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) && - (p[2]->code == I_PUSHW) && - (p[3]->code == I_LDWI) && + (p[2]->code == I_PUSH_WR) && + (p[3]->code == I_LD_WI) && (p[3]->type == T_VALUE) ) { p[3]->data *= p[1]->data; @@ -723,20 +725,20 @@ void push_ins (INS *ins) } /* - * __ldwi p --> __stwi p, i - * __pushw - * __ldwi i - * __st{b|w}ps + * __ld.wi p --> __st.wmi p, i + * __push.wr + * __ld.wi i + * __st{w/u}pt */ else if - ((p[0]->code == I_STWPS || - p[0]->code == I_STBPS) && - (p[1]->code == I_LDWI) && - (p[2]->code == I_PUSHW) && - (p[3]->code == I_LDWI) + ((p[0]->code == I_ST_WPT || + p[0]->code == I_ST_UPT) && + (p[1]->code == I_LD_WI) && + (p[2]->code == I_PUSH_WR) && + (p[3]->code == I_LD_WI) ) { /* replace code */ - p[3]->code = p[0]->code == I_STWPS ? I_STWI : I_STBI; + p[3]->code = p[0]->code == I_ST_WPT ? I_ST_WMI : I_ST_UMI; p[3]->imm_type = p[1]->type; p[3]->imm_data = p[1]->data; nb = 3; @@ -744,27 +746,27 @@ void push_ins (INS *ins) #if 0 /* - * __pushw --> __addbi_p i - * __ldb_p - * __addwi i - * __stbps + * __push.wr --> __addbi_p i + * __ld.bp + * __add.wi i + * __st.upt * */ /* - * __pushw --> __addbi_p i - * __stw __ptr - * __ldbp __ptr - * __addwi i - * __stbps + * __push.wr --> __addbi_p i + * __st.wm __ptr + * __ld.bp __ptr + * __add.wi i + * __st.upt * */ else if - ((p[0]->code == I_STBPS) && - (p[1]->code == I_ADDWI) && + ((p[0]->code == I_ST_UPT) && + (p[1]->code == I_ADD_WI) && (p[2]->code == X_LDB_P) && - (p[3]->code == I_PUSHW) + (p[3]->code == I_PUSH_WR) ) { *p[3] = *p[1]; p[3]->code = I_ADDBI_P; @@ -774,22 +776,22 @@ void push_ins (INS *ins) #if OPT_ARRAY_RD /* - * __aslw --> __ldwa array - * __addwi array - * __stw _ptr - * __ldwp _ptr + * __asl.wr --> __ld.war array + * __add.wi array + * __st.wm _ptr + * __ld.wp _ptr * * Classic base+offset word-array access. */ else if - ((p[0]->code == I_LDWP) && + ((p[0]->code == I_LD_WP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && - (p[2]->code == I_ADDWI) && + (p[2]->code == I_ADD_WI) && (p[2]->type == T_SYMBOL) && (is_small_array((SYMBOL *)p[2]->data)) && - (p[3]->code == I_ASLW) + (p[3]->code == I_ASL_WR) ) { /* replace code */ p[3]->code = X_LD_WAR; @@ -837,162 +839,180 @@ void push_ins (INS *ins) nb = 2; } - /* __ldwi i --> __ldw/_ldub i - * __stw __ptr - * __ldwp/__ldubp __ptr + /* __ld.wi i --> __ld.{w/b/u}m i + * __st.wm __ptr + * __ld.{w/b/u}p __ptr * * Load a global/static variable from memory */ else if - ((p[0]->code == I_LDWP || - p[0]->code == I_LDBP || - p[0]->code == I_LDUBP) && + ((p[0]->code == I_LD_WP || + p[0]->code == I_LD_BP || + p[0]->code == I_LD_UP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && - (p[2]->code == I_LDWI) + (p[2]->code == I_LD_WI) ) { /* replace code */ - if (p[0]->code == I_LDWP) - p[2]->code = I_LDW; + if (p[0]->code == I_LD_WP) + p[2]->code = I_LD_WM; else - if (p[0]->code == I_LDBP) - p[2]->code = I_LDB; + if (p[0]->code == I_LD_BP) + p[2]->code = I_LD_BM; else - p[2]->code = I_LDUB; + p[2]->code = I_LD_UM; nb = 2; } /* - * __lea_s i --> __ldw_s/_ldub_s i - * __stw __ptr - * __ldwp __ptr + * __lea.s i --> __ld.{w/b/u}s i + * __st.wm __ptr + * __ld.{w/b/u}p __ptr * * Load a local variable from memory */ else if - ((p[0]->code == I_LDWP || - p[0]->code == I_LDBP || - p[0]->code == I_LDUBP) && + ((p[0]->code == I_LD_WP || + p[0]->code == I_LD_BP || + p[0]->code == I_LD_UP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && (p[2]->code == I_LEA_S) ) { /* replace code */ - if (p[0]->code == I_LDWP) - p[2]->code = X_LDW_S; + if (p[0]->code == I_LD_WP) + p[2]->code = X_LD_WS; else - if (p[0]->code == I_LDBP) - p[2]->code = X_LDB_S; + if (p[0]->code == I_LD_BP) + p[2]->code = X_LD_BS; else - p[2]->code = X_LDUB_S; + p[2]->code = X_LD_US; nb = 2; } /* - * __pushw --> __addwi/__subwi/__andwi/etc i - * __ldwi i - * __addws/__subws/__andws/etc + * __push.wr --> __add.wi i + * __ld.wi i + * __add.wt + * + * __push.wr --> __sub.wi i + * __ld.wi i + * __sub.wt + * + * etc/etc */ else if - ((p[0]->code == I_ADDWS || - p[0]->code == I_SUBWS || - p[0]->code == I_ANDWS || - p[0]->code == I_EORWS || - p[0]->code == I_ORWS) && - (p[1]->code == I_LDWI) && - (p[2]->code == I_PUSHW) + ((p[0]->code == I_ADD_WT || + p[0]->code == I_SUB_WT || + p[0]->code == I_AND_WT || + p[0]->code == I_EOR_WT || + p[0]->code == I_OR_WT) && + (p[1]->code == I_LD_WI) && + (p[2]->code == I_PUSH_WR) ) { /* replace code */ *p[2] = *p[1]; switch (p[0]->code) { - case I_ADDWS: p[2]->code = I_ADDWI; break; - case I_SUBWS: p[2]->code = I_SUBWI; break; - case I_ANDWS: p[2]->code = I_ANDWI; break; - case I_EORWS: p[2]->code = I_EORWI; break; - case I_ORWS: p[2]->code = I_ORWI; break; + case I_ADD_WT: p[2]->code = I_ADD_WI; break; + case I_SUB_WT: p[2]->code = I_SUB_WI; break; + case I_AND_WT: p[2]->code = I_AND_WI; break; + case I_EOR_WT: p[2]->code = I_EOR_WI; break; + case I_OR_WT: p[2]->code = I_OR_WI; break; default: abort(); } nb = 2; if (p[2]->type == T_VALUE && p[2]->data == 0) { - if (p[2]->code == I_ANDWI) - p[2]->code = I_LDWI; + if (p[2]->code == I_AND_WI) + p[2]->code = I_LD_WI; else nb = 3; } } /* - * __pushw --> __addw/__subw/__andw/etc symbol - * __ldw symbol - * __addws/__subws/__andws/etc + * __push.wr --> __add.wm symbol + * __ld.wm symbol + * __add.wt + * + * __push.wr --> __sub.wm symbol + * __ld.wm symbol + * __sub.wt + * + * etc/etc */ else if - ((p[0]->code == I_ADDWS || - p[0]->code == I_SUBWS || - p[0]->code == I_ANDWS || - p[0]->code == I_EORWS || - p[0]->code == I_ORWS) && - (p[1]->code == I_LDW) && - (p[2]->code == I_PUSHW) + ((p[0]->code == I_ADD_WT || + p[0]->code == I_SUB_WT || + p[0]->code == I_AND_WT || + p[0]->code == I_EOR_WT || + p[0]->code == I_OR_WT) && + (p[1]->code == I_LD_WM) && + (p[2]->code == I_PUSH_WR) ) { /* replace code */ *p[2] = *p[1]; switch (p[0]->code) { - case I_ADDWS: p[2]->code = I_ADDW; break; - case I_SUBWS: p[2]->code = I_SUBW; break; - case I_ANDWS: p[2]->code = I_ANDW; break; - case I_EORWS: p[2]->code = I_EORW; break; - case I_ORWS: p[2]->code = I_ORW; break; + case I_ADD_WT: p[2]->code = I_ADD_WM; break; + case I_SUB_WT: p[2]->code = I_SUB_WM; break; + case I_AND_WT: p[2]->code = I_AND_WM; break; + case I_EOR_WT: p[2]->code = I_EOR_WM; break; + case I_OR_WT: p[2]->code = I_OR_WM; break; default: abort(); } nb = 2; } /* - * __pushw --> __addub/__subub/__andub/etc symbol - * __ldub symbol - * __addws/__subws/__andws/etc + * __push.wr --> __add.um symbol + * __ld.um symbol + * __add.wt + * + * __push.wr --> __sub.um symbol + * __ld.um symbol + * __sub.wt + * + * etc/etc */ else if - ((p[0]->code == I_ADDWS || - p[0]->code == I_SUBWS || - p[0]->code == I_ANDWS || - p[0]->code == I_EORWS || - p[0]->code == I_ORWS) && - (p[1]->code == I_LDUB) && - (p[2]->code == I_PUSHW) + ((p[0]->code == I_ADD_WT || + p[0]->code == I_SUB_WT || + p[0]->code == I_AND_WT || + p[0]->code == I_EOR_WT || + p[0]->code == I_OR_WT) && + (p[1]->code == I_LD_UM) && + (p[2]->code == I_PUSH_WR) ) { /* replace code */ *p[2] = *p[1]; switch (p[0]->code) { - case I_ADDWS: p[2]->code = I_ADDUB; break; - case I_SUBWS: p[2]->code = I_SUBUB; break; - case I_ANDWS: p[2]->code = I_ANDUB; break; - case I_EORWS: p[2]->code = I_EORUB; break; - case I_ORWS: p[2]->code = I_ORUB; break; + case I_ADD_WT: p[2]->code = I_ADD_UM; break; + case I_SUB_WT: p[2]->code = I_SUB_UM; break; + case I_AND_WT: p[2]->code = I_AND_UM; break; + case I_EOR_WT: p[2]->code = I_EOR_UM; break; + case I_OR_WT: p[2]->code = I_OR_UM; break; default: abort(); } nb = 2; } /* - * __pushw --> __addw_s i-2 - * __ldw_s i - * __addws + * __push.wr --> __add.ws (i - 2) + * __ld.ws i + * __add.wt */ else if - ((p[0]->code == I_ADDWS) && - (p[1]->code == X_LDW_S || - p[1]->code == X_LDUB_S) && - (p[2]->code == I_PUSHW) + ((p[0]->code == I_ADD_WT) && + (p[1]->code == X_LD_WS || + p[1]->code == X_LD_US) && + (p[2]->code == I_PUSH_WR) ) { /* replace code */ *p[2] = *p[1]; switch (p[1]->code) { - case X_LDW_S: p[2]->code = X_ADDW_S; break; - case X_LDUB_S: p[2]->code = X_ADDUB_S; break; + case X_LD_WS: p[2]->code = X_ADD_WS; break; + case X_LD_US: p[2]->code = X_ADD_US; break; default: abort(); } p[2]->data -= 2; @@ -1000,25 +1020,26 @@ void push_ins (INS *ins) } /* - * __pushw --> __asl/lsr/asrwi i - * __ldwi i - * jsr asl/lsr/asr + * __push.wr --> __as{l/r}.wi i + * __ld.wi i + * jsr asl/asr/lsr */ else if ((p[0]->code == I_JSR) && (!strcmp((char *)p[0]->data, "aslw") || - !strcmp((char *)p[0]->data, "lsrw") || - !strcmp((char *)p[0]->data, "asrw")) && - (p[1]->code == I_LDWI) && - (p[2]->code == I_PUSHW) + !strcmp((char *)p[0]->data, "asrw") || + !strcmp((char *)p[0]->data, "lsrw")) && + (p[1]->code == I_LD_WI) && + (p[2]->code == I_PUSH_WR) ) { /* replace code */ if (!strcmp((char *)p[0]->data, "aslw")) - p[2]->code = I_ASLWI; - else if (!strcmp((char *)p[0]->data, "lsrw")) - p[2]->code = I_LSRWI; + p[2]->code = I_ASL_WI; + else + if (!strcmp((char *)p[0]->data, "asrw")) + p[2]->code = I_ASR_WI; else - p[2]->code = I_ASRWI; + p[2]->code = I_LSR_WI; p[2]->type = p[1]->type; p[2]->data = p[1]->data; nb = 2; @@ -1028,45 +1049,53 @@ void push_ins (INS *ins) } /* - * __pushw --> __aslwi log2(i) - * __ldwi i or __mulwi i + * __push.wr --> __asl.wi log2(i) + * __ld.wi i or __mul.wi i * jsr {u|s}mul */ else if ((p[0]->code == I_JSR) && (!strcmp((char *)p[0]->data, "umul") || !strcmp((char *)p[0]->data, "smul")) && - (p[1]->code == I_LDWI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) && (p[1]->data > 0) && (p[1]->data < 0x8000) && - (p[2]->code == I_PUSHW) + (p[2]->code == I_PUSH_WR) ) { p[2]->type = T_VALUE; if (__builtin_popcount((unsigned int)p[1]->data) == 1) { - p[2]->code = I_ASLWI; + p[2]->code = I_ASL_WI; p[2]->data = __builtin_ctz((unsigned int)p[1]->data); } else { - p[2]->code = I_MULWI; + p[2]->code = I_MUL_WI; p[2]->data = p[1]->data; } nb = 2; } /* - * __pushw --> __notw - * __ldwi 0 - * __cmpw eq_w + * __push.wr --> __tst.wi i + * __ld.wi i + * __cmp.wt eq_w + * + * __push.wr --> __not.wi i + * __ld.wi i + * __cmp.wt ne_w * - * __pushw --> __tstw - * __ldwi 0 - * __cmpw ne_w + * __push.wr --> __not.wr + * __ld.wi 0 + * __cmp.wt eq_w + * + * __push.wr --> __tst.wr + * __ld.wi 0 + * __cmp.wt ne_w */ else if - ((p[0]->code == I_CMPW) && - (p[1]->code == I_LDWI) && - (p[2]->code == I_PUSHW) && + ((p[0]->code == I_CMP_WT) && + (p[1]->code == I_LD_WI) && + (p[2]->code == I_PUSH_WR) && (p[1]->type == T_VALUE || p[1]->type == T_SYMBOL) && (strcmp((char *)p[0]->data, "eq_w") == 0 || @@ -1077,24 +1106,24 @@ void push_ins (INS *ins) /* replace code */ if (p[1]->data == 0) { if (strcmp((char *)p[0]->data, "eq_w") == 0) - p[2]->code = I_NOTW; + p[2]->code = I_NOT_WR; else if (strcmp((char *)p[0]->data, "eq_b") == 0) - p[2]->code = I_NOTW; + p[2]->code = I_NOT_WR; else if (strcmp((char *)p[0]->data, "ne_w") == 0) - p[2]->code = I_TSTW; + p[2]->code = I_TST_WR; else if (strcmp((char *)p[0]->data, "ne_b") == 0) - p[2]->code = I_TSTW; + p[2]->code = I_TST_WR; p[2]->type = 0; p[2]->data = 0; } else { if (strcmp((char *)p[0]->data, "eq_w") == 0) - p[2]->code = X_CMPWI_EQ; + p[2]->code = X_TST_WI; else if (strcmp((char *)p[0]->data, "eq_b") == 0) - p[2]->code = X_CMPWI_EQ; + p[2]->code = X_TST_WI; else if (strcmp((char *)p[0]->data, "ne_w") == 0) - p[2]->code = X_CMPWI_NE; + p[2]->code = X_NOT_WI; else if (strcmp((char *)p[0]->data, "ne_b") == 0) - p[2]->code = X_CMPWI_NE; + p[2]->code = X_NOT_WI; p[2]->type = p[1]->type; p[2]->data = p[1]->data; } @@ -1103,166 +1132,182 @@ void push_ins (INS *ins) } /* - * __ld{w/b/c} n --> __incld_{w/b/c}m n - * __addwi 1 - * __st{w/c} n + * __ld{w/b/u}m symbol --> __incld.{w/b/u}m symbol + * __add.wi 1 + * __st.{w/u}m symbol * - * __ld{w/b/c} n --> __decld_{w/b/c}m n - * __subwi 1 - * __st{w/c} n + * __ld{w/b/u} symbol --> __decld.{w/b/u}m symbol + * __sub.wi 1 + * __st.{w/u}m symbol * * pre-increment, post-increment, * pre-decrement, post-decrement! */ else if - ((p[1]->code == I_ADDWI || - p[1]->code == I_SUBWI) && + ((p[1]->code == I_ADD_WI || + p[1]->code == I_SUB_WI) && (p[1]->type == T_VALUE) && (p[1]->data == 1) && - (p[0]->code == I_STW || - p[0]->code == I_STB) && - (p[2]->code == I_LDW || - p[2]->code == I_LDB || - p[2]->code == I_LDUB) && + (p[0]->code == I_ST_WM || + p[0]->code == I_ST_UM) && + (p[2]->code == I_LD_WM || + p[2]->code == I_LD_BM || + p[2]->code == I_LD_UM) && (p[0]->type == p[2]->type) && (p[0]->data == p[2]->data) // (cmp_operands(p[0], p[2]) == 1) ) { /* replace code */ switch (p[2]->code) { - case I_LDW: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_WM : X_DECLD_WM; break; - case I_LDB: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_BM : X_DECLD_BM; break; - case I_LDUB: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_CM : X_DECLD_CM; break; + case I_LD_WM: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_WM : X_DECLD_WM; break; + case I_LD_BM: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_BM : X_DECLD_BM; break; + case I_LD_UM: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_UM : X_DECLD_UM; break; default: break; } nb = 2; } /* - * __ld{w/b/c}_s n --> __incld_{w/b/c}s n - * __addwi 1 - * __st{w/c}_s n + * __ld{w/b/u}s symbol --> __incld.{w/b/u}s symbol + * __add.wi 1 + * __st.{w/u}s symbol * - * __ld{w/b/c}_s n --> __decld_{w/b/c}s n - * __subwi 1 - * __st{w/c}_s n + * __ld{w/b/u}s symbol --> __decld.{w/b/u}s symbol + * __sub.wi 1 + * __st.{w/u}s symbol * * C pre-increment, post-increment, * C pre-decrement, post-decrement! */ else if - ((p[1]->code == I_ADDWI || - p[1]->code == I_SUBWI) && + ((p[1]->code == I_ADD_WI || + p[1]->code == I_SUB_WI) && (p[1]->type == T_VALUE) && (p[1]->data == 1) && - (p[0]->code == X_STW_S || - p[0]->code == X_STB_S) && - (p[2]->code == X_LDW_S || - p[2]->code == X_LDB_S || - p[2]->code == X_LDUB_S) && + (p[0]->code == X_ST_WS || + p[0]->code == X_ST_US) && + (p[2]->code == X_LD_WS || + p[2]->code == X_LD_BS || + p[2]->code == X_LD_US) && (p[0]->type == p[2]->type) && (p[0]->data == p[2]->data) ) { /* replace code */ switch (p[2]->code) { - case X_LDW_S: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_WS : X_DECLD_WS; break; - case X_LDB_S: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_BS : X_DECLD_BS; break; - case X_LDUB_S: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_CS : X_DECLD_CS; break; + case X_LD_WS: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_WS : X_DECLD_WS; break; + case X_LD_BS: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_BS : X_DECLD_BS; break; + case X_LD_US: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_US : X_DECLD_US; break; default: break; } nb = 2; } /* - * __ldp_{w/b/c}ar n --> __incld_{w/b/c}ar n - * __addwi 1 - * __st{w/c} n + * __ldp.{w/b/u}ar symbol --> __incld_{w/b/u}ar symbol + * __add.wi 1 + * __st.{w/u}at symbol * - * __ldp_{w/b/c}ar n --> __decld_{w/b/c}ar n - * __subwi 1 - * __st{w/c} n + * __ldp.{w/b/u}ar symbol --> __decld_{w/b/u}ar symbol + * __sub.wi 1 + * __st.{w/u}at symbol * * pre-increment, post-increment, * pre-decrement, post-decrement! */ else if - ((p[1]->code == I_ADDWI || - p[1]->code == I_SUBWI) && + ((p[1]->code == I_ADD_WI || + p[1]->code == I_SUB_WI) && (p[1]->type == T_VALUE) && (p[1]->data == 1) && (p[0]->code == X_ST_WAT || - p[0]->code == X_ST_CAT) && + p[0]->code == X_ST_UAT) && (p[2]->code == X_LDP_WAR || p[2]->code == X_LDP_BAR || - p[2]->code == X_LDP_CAR) && + p[2]->code == X_LDP_UAR) && (p[0]->type == p[2]->type) && (p[0]->data == p[2]->data) // (cmp_operands(p[0], p[2]) == 1) ) { /* replace code */ switch (p[2]->code) { - case X_LDP_WAR: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_WAR : X_DECLD_WAR; break; - case X_LDP_BAR: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_BAR : X_DECLD_BAR; break; - case X_LDP_CAR: p[2]->code = (p[1]->code == I_ADDWI) ? X_INCLD_CAR : X_DECLD_CAR; break; + case X_LDP_WAR: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_WAR : X_DECLD_WAR; break; + case X_LDP_BAR: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_BAR : X_DECLD_BAR; break; + case X_LDP_UAR: p[2]->code = (p[1]->code == I_ADD_WI) ? X_INCLD_UAR : X_DECLD_UAR; break; default: break; } nb = 2; } /* - * __ldw/b/ub --> __tzw/b/ub - * __tstw __btrue (or __bfalse) - * __btrue (or __bfalse) + * __ld.{w/b/u}p symbol --> __tz.{w/b/u}p symbol + * __tst.wr __b{true/false} + * __b{true/false} + * + * __ld.{w/b/u}p symbol --> __tnz.{w/b/u}p symbol + * __not.wr __b{true/false} + * __b{true/false} * - * __ldw/b/ub --> __tnzw/b/ub - * __notw __btrue (or __bfalse) - * __btrue (or __bfalse) + * __ld.{w/b/u}m symbol --> __tz.{w/b/u}m symbol + * __tst.wr __b{true/false} + * __b{true/false} + * + * __ld.{w/b/u}m symbol --> __tnz.{w/b/u}m symbol + * __not.wr __b{true/false} + * __b{true/false} + * + * __ld.{w/b/u}s symbol --> __tz.{w/b/u}s symbol + * __tst.wr __b{true/false} + * __b{true/false} + * + * __ld.{w/b/u}s symbol --> __tnz.{w/b/u}s symbol + * __not.wr __b{true/false} + * __b{true/false} * * N.B. This deliberately tests for the branch/label * i-codes in order to delay a match until after any - * duplicate I_TSTW and I_NOTW i-codes are merged. + * duplicate I_TST_WR and I_NOT_WR i-codes are merged. */ else if ((p[0]->code == I_LABEL || p[0]->code == I_BTRUE || p[0]->code == I_BFALSE) && - (p[1]->code == I_TSTW || - p[1]->code == I_NOTW) && - (p[2]->code == I_LDB || - p[2]->code == I_LDUB || - p[2]->code == I_LDBP || - p[2]->code == I_LDUBP || - p[2]->code == I_LDW || - p[2]->code == I_LDWP || - p[2]->code == X_LDB_S || - p[2]->code == X_LDUB_S || - p[2]->code == X_LDW_S) + (p[1]->code == I_TST_WR || + p[1]->code == I_NOT_WR) && + (p[2]->code == I_LD_BM || + p[2]->code == I_LD_UM || + p[2]->code == I_LD_BP || + p[2]->code == I_LD_UP || + p[2]->code == I_LD_WM || + p[2]->code == I_LD_WP || + p[2]->code == X_LD_BS || + p[2]->code == X_LD_US || + p[2]->code == X_LD_WS) ) { /* remove code */ - if (p[1]->code == I_TSTW) { + if (p[1]->code == I_TST_WR) { switch (p[2]->code) { - case I_LDB: - case I_LDUB: p[2]->code = X_TNZB; break; - case I_LDBP: - case I_LDUBP: p[2]->code = X_TNZBP; break; - case I_LDW: p[2]->code = X_TNZW; break; - case I_LDWP: p[2]->code = X_TNZWP; break; - case X_LDB_S: - case X_LDUB_S: p[2]->code = X_TNZB_S; break; - case X_LDW_S: p[2]->code = X_TNZW_S; break; + case I_LD_BM: + case I_LD_UM: p[2]->code = X_TST_UM; break; + case I_LD_BP: + case I_LD_UP: p[2]->code = X_TST_UP; break; + case I_LD_WM: p[2]->code = X_TST_WM; break; + case I_LD_WP: p[2]->code = X_TST_WP; break; + case X_LD_BS: + case X_LD_US: p[2]->code = X_TST_US; break; + case X_LD_WS: p[2]->code = X_TST_WS; break; default: abort(); } } else { switch (p[2]->code) { - case I_LDB: - case I_LDUB: p[2]->code = X_TZB; break; - case I_LDBP: - case I_LDUBP: p[2]->code = X_TZBP; break; - case I_LDW: p[2]->code = X_TZW; break; - case I_LDWP: p[2]->code = X_TZWP; break; - case X_LDB_S: - case X_LDUB_S: p[2]->code = X_TZB_S; break; - case X_LDW_S: p[2]->code = X_TZW_S; break; + case I_LD_BM: + case I_LD_UM: p[2]->code = X_NOT_UM; break; + case I_LD_BP: + case I_LD_UP: p[2]->code = X_NOT_UP; break; + case I_LD_WM: p[2]->code = X_NOT_WM; break; + case I_LD_WP: p[2]->code = X_NOT_WP; break; + case X_LD_BS: + case X_LD_US: p[2]->code = X_NOT_US; break; + case X_LD_WS: p[2]->code = X_NOT_WS; break; default: abort(); } } @@ -1273,56 +1318,55 @@ void push_ins (INS *ins) #if OPT_ARRAY_RD /* - * __addwi array --> __ldba/__lduba array - * __stw _ptr - * __ldbp/__ldubp _ptr + * __add.wi array --> __ld.{b/u}ar array + * __st.wm _ptr + * __ld.{b/u}p _ptr * * Classic base+offset byte-array access. */ else if - ((p[0]->code == I_LDBP || - p[0]->code == I_LDUBP) && + ((p[0]->code == I_LD_BP || + p[0]->code == I_LD_UP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && - (p[2]->code == I_ADDWI) && + (p[2]->code == I_ADD_WI) && (p[2]->type == T_SYMBOL) && (is_small_array((SYMBOL *)p[2]->data)) ) { /* replace code */ - p[2]->code = (p[0]->code == I_LDBP) ? X_LD_BAR : X_LD_CAR; + p[2]->code = (p[0]->code == I_LD_BP) ? X_LD_BAR : X_LD_UAR; nb = 2; } #endif #if OPT_ARRAY_WR /* - * __index.wr or __index.cr --> __ldp.{w/b/c}ar array - * __stw _ptr - * __ldwp/__ldbp/__ldubp _ptr + * __index.{w/u}r array --> __ldp.{w/b/u}ar array + * __st.wm _ptr + * __ld.{w/b/u}p _ptr * * Optimized base+offset array access. * - * This MUST be enabled when the X_INDEXW/X_INDEXB - * optimization is enabled, else array loads break - * because the index is pushed instead of an array - * address! + * This MUST be enabled when the X_INDEX_WR / X_INDEX_UR + * optimization is enabled, or array loads break because + * the index is put into __ptr instead of an address! */ else if - ((p[0]->code == I_LDWP || - p[0]->code == I_LDBP || - p[0]->code == I_LDUBP) && + ((p[0]->code == I_LD_WP || + p[0]->code == I_LD_BP || + p[0]->code == I_LD_UP) && (p[0]->type == T_PTR) && - (p[1]->code == I_STW) && + (p[1]->code == I_ST_WM) && (p[1]->type == T_PTR) && (p[2]->code == X_INDEX_WR || - p[2]->code == X_INDEX_CR) + p[2]->code == X_INDEX_UR) ) { /* replace code */ - if (p[0]->code == I_LDWP) + if (p[0]->code == I_LD_WP) p[2]->code = X_LDP_WAR; else - p[2]->code = (p[0]->code == I_LDBP) ? X_LDP_BAR : X_LDP_CAR; + p[2]->code = (p[0]->code == I_LD_BP) ? X_LDP_BAR : X_LDP_UAR; nb = 2; } #endif @@ -1387,28 +1431,36 @@ void push_ins (INS *ins) } /* - * __ldb/__lbub/etc --> __ldb/__lbub/etc - * __switchw __switchb + * __ld.{b/u}p __ptr --> __ld.{b/u}p __ptr + * __switch.wr __switch.ur + * + * __ld.{b/u}m symbol --> __ld.{b/u}m symbol + * __switch.wr __switch.ur + * + * __ld.{b/u}s n --> __ld.{b/u}s n + * __switch.wr __switch.ur * + * __ld.{b/u}ar array --> __ld.{b/u}ar array + * __switch.wr __switch.ur */ else if - ((p[0]->code == I_SWITCHW) && - (p[1]->code == I_LDB || - p[1]->code == I_LDUB || - p[1]->code == I_LDBP || - p[1]->code == I_LDUBP || + ((p[0]->code == I_SWITCH_WR) && + (p[1]->code == I_LD_BP || + p[1]->code == I_LD_UP || + p[1]->code == I_LD_BM || + p[1]->code == I_LD_UM || + p[1]->code == X_LD_BS || + p[1]->code == X_LD_US || p[1]->code == X_LD_BAR || - p[1]->code == X_LD_CAR || - p[1]->code == X_LDB_S || - p[1]->code == X_LDUB_S) + p[1]->code == X_LD_UAR) ) { /* optimize code */ - p[0]->code = I_SWITCHB; + p[0]->code = I_SWITCH_UR; nb = 0; } /* - * __switchw/__switchb --> __switchw/__switchb + * __switch.{w/u}r --> __switch.{w/u}rw * __endcase * * __bra LLnn --> __bra LLnn @@ -1416,14 +1468,15 @@ void push_ins (INS *ins) * * I_ENDCASE is only generated in order to catch which * case statements could fall through to the next case - * so that an SAX instruction can be inserted. + * so that an SAX instruction could be inserted, which + * is only needed *IF* "doswitch" uses "JMP table, x". * * This removes obviously-redundant I_ENDCASE i-codes. */ else if ((p[0]->code == I_ENDCASE) && - (p[1]->code == I_SWITCHW || - p[1]->code == I_SWITCHB || + (p[1]->code == I_SWITCH_WR || + p[1]->code == I_SWITCH_UR || p[1]->code == I_BRA) ) { /* remove code */ @@ -1431,59 +1484,59 @@ void push_ins (INS *ins) } /* - * __tstw --> __notw - * __notw + * __tst.wr --> __not.wr + * __not.wr */ else if - ((p[0]->code == I_NOTW) && - (p[1]->code == I_TSTW) + ((p[0]->code == I_NOT_WR) && + (p[1]->code == I_TST_WR) ) { - p[1]->code = I_NOTW; + p[1]->code = I_NOT_WR; nb = 1; } /* - * __notw --> __tstw - * __notw + * __not.wr --> __tst.wr + * __not.wr */ else if - ((p[0]->code == I_NOTW) && - (p[1]->code == I_NOTW) + ((p[0]->code == I_NOT_WR) && + (p[1]->code == I_NOT_WR) ) { - p[1]->code = I_TSTW; + p[1]->code = I_TST_WR; nb = 1; } /* - * __cmpw --> __cmpw - * __tstw + * __cmp.wt --> __cmp.wt + * __tst.wr * - * __notw --> __notw - * __tstw + * __not.wr --> __not.wr + * __tst.wr * - * __tstw --> __tstw - * __tstw + * __tst.wr --> __tst.wr + * __tst.wr * * This removes redundant tests in compound conditionals ... * * LLnn: --> LLnn: - * __tstw + * __tst.wr */ else if - ((p[0]->code == I_TSTW) && - (p[1]->code == I_CMPW || - p[1]->code == X_CMPWI_EQ || - p[1]->code == X_CMPWI_NE || - p[1]->code == I_NOTW || - p[1]->code == I_TSTW || + ((p[0]->code == I_TST_WR) && + (p[1]->code == I_CMP_WT || + p[1]->code == X_TST_WI || + p[1]->code == X_NOT_WI || + p[1]->code == I_NOT_WR || + p[1]->code == I_TST_WR || p[1]->code == I_LABEL) ) { nb = 1; } /* - * __addmi i, __stack --> __addmi i+j, __stack - * __addmi j, __stack + * __modsp i --> __modsp (i + j) + * __modsp j */ else if ((p[0]->code == I_MODSP) && @@ -1498,13 +1551,13 @@ void push_ins (INS *ins) } /* - * __addwi i --> __addwi i+j - * __addwi j + * __add.wi i --> __add.wi (i + j) + * __add.wi j */ else if - ((p[0]->code == I_ADDWI) && + ((p[0]->code == I_ADD_WI) && (p[0]->type == T_VALUE) && - (p[1]->code == I_ADDWI) && + (p[1]->code == I_ADD_WI) && (p[1]->type == T_VALUE) ) { /* replace code */ @@ -1513,12 +1566,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi i+j - * __addwi j + * __ld.wi i --> __ld.wi (i + j) + * __add.wi j */ else if - ((p[0]->code == I_ADDWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ADD_WI) && + (p[1]->code == I_LD_WI) && (p[0]->type == T_VALUE) && (p[1]->type == T_VALUE) @@ -1529,12 +1582,12 @@ void push_ins (INS *ins) } /* - * __ldwi sym --> __ldwi sym+j - * __addwi j + * __ld.wi symbol --> __ld.wi (symbol + j) + * __add.wi j */ else if - ((p[0]->code == I_ADDWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ADD_WI) && + (p[1]->code == I_LD_WI) && (p[0]->type == T_VALUE) && (p[1]->type == T_SYMBOL) @@ -1553,12 +1606,12 @@ void push_ins (INS *ins) } /* - * __ldwi j --> __ldwi sym+j - * __addwi sym + * __ld.wi j --> __ld.wi (symbol + j) + * __add.wi symbol */ else if - ((p[0]->code == I_ADDWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ADD_WI) && + (p[1]->code == I_LD_WI) && (p[0]->type == T_SYMBOL) && (p[1]->type == T_VALUE) @@ -1574,18 +1627,18 @@ void push_ins (INS *ins) p[1]->data = (intptr_t)newsym; } else { *p[1] = *p[0]; - p[1]->code = I_LDWI; + p[1]->code = I_LD_WI; } nb = 1; } /* - * __ldwi i --> __ldwi (i-j) - * __subwi j + * __ld.wi i --> __ld.wi (i - j) + * __sub.wi j */ else if - ((p[0]->code == I_SUBWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_SUB_WI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1595,12 +1648,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi (i&j) - * __andwi j + * __ld.wi i --> __ld.wi (i & j) + * __and.wi j */ else if - ((p[0]->code == I_ANDWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_AND_WI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1610,12 +1663,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi (i|j) - * __orwi j + * __ld.wi i --> __ld.wi (i | j) + * __or.wi j */ else if - ((p[0]->code == I_ORWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_OR_WI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1625,12 +1678,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi (i*j) - * __mulwi j + * __ld.wi i --> __ld.wi (i * j) + * __mul.wi j */ else if - ((p[0]->code == I_MULWI) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_MUL_WI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1640,12 +1693,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi i+i - * __aslw + * __ld.wi i --> __ld.wi (i + i) + * __asl.wr */ else if - ((p[0]->code == I_ASLW) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ASL_WR) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1655,12 +1708,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi i ^ 0xffff - * __comw + * __ld.wi i --> __ld.wi (i ^ 0xffff) + * __com.wr */ else if - ((p[0]->code == I_COMW) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_COM_WR) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1670,12 +1723,12 @@ void push_ins (INS *ins) } /* - * __ldwi i --> __ldwi i ^ 0xffff - * __negw + * __ld.wi i --> __ld.wi (-i) + * __neg.wr */ else if - ((p[0]->code == I_NEGW) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_NEG_WR) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) ) { @@ -1685,14 +1738,14 @@ void push_ins (INS *ins) } /* - * __ldwi --> __ldwi - * jsr {u|s}mul --> __jsr asl + * __ld.wi --> __ld.wi + * jsr {u|s}mul jsr asl */ else if ((p[0]->code == I_JSR) && (!strcmp((char *)p[0]->data, "umul") || !strcmp((char *)p[0]->data, "smul")) && - (p[1]->code == I_LDWI) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) && (__builtin_popcount((unsigned int)p[1]->data) == 1) && (p[1]->data > 0) && @@ -1704,12 +1757,12 @@ void push_ins (INS *ins) } /* - * __stw a --> __stw a - * __ldw a + * __st.wm a --> __st.wm a + * __ld.wm a */ else if - ((p[0]->code == I_LDW) && - (p[1]->code == I_STW) && + ((p[0]->code == I_LD_WM) && + (p[1]->code == I_ST_WM) && (cmp_operands(p[0], p[1]) == 1) ) { /* remove code */ @@ -1717,79 +1770,80 @@ void push_ins (INS *ins) } /* - * __ldw a (or __ldwi a) --> __ldw b (or __ldwi b) - * __ldw b (or __ldwi b) + * __st.ws i --> __st.ws i + * __ld.ws i */ else if - ((p[0]->code == I_LDW || - p[0]->code == I_LDWI || - p[0]->code == X_LDW_S || - p[0]->code == I_LEA_S || - p[0]->code == I_LDB || - p[0]->code == I_LDBP || - p[0]->code == X_LDB_S || - p[0]->code == I_LDUB || - p[0]->code == I_LDUBP || - p[0]->code == X_LDUB_S) && - (p[1]->code == I_LDW || - p[1]->code == I_LDWI || - p[1]->code == X_LDW_S || - p[1]->code == I_LEA_S || - p[1]->code == I_LDB || - p[1]->code == I_LDBP || - p[1]->code == X_LDB_S || - p[1]->code == I_LDUB || - p[1]->code == I_LDUBP || - p[1]->code == X_LDUB_S) - ) { + ((p[0]->code == X_LD_WS) && + (p[1]->code == X_ST_WS) && + (p[0]->data == p[1]->data)) { /* remove code */ - *p[1] = *p[0]; nb = 1; } /* - * __stw_s i --> __stw_s i - * __ldw_s i + * __st.us i --> __st.us i + * __ld.us i */ else if - ((p[0]->code == X_LDW_S) && - (p[1]->code == X_STW_S) && - - (p[0]->data == p[1]->data)) { - /* remove code */ - nb = 1; + ((p[0]->code == X_LD_BS || + p[0]->code == X_LD_US) && + (p[1]->code == X_ST_US) && + (p[0]->data == p[1]->data) + ) { + if (p[0]->code == X_LD_BS) + p[0]->code = I_EXT_BR; + else + p[0]->code = I_EXT_UR; + p[0]->data = p[0]->type = 0; } /* - * __stb_s i --> __stb_s i - * __ldb_s i + * __ld.wm a (or __ld.wi a) --> __ld.wm b (or __ld.wi b) + * __ld.wm b (or __ld.wi b) + * + * JCB: Orphaned load, does this really happen? */ else if - ((p[0]->code == X_LDB_S || - p[0]->code == X_LDUB_S) && - (p[1]->code == X_STB_S) && - (p[0]->data == p[1]->data) + ((p[0]->code == I_LD_WM || + p[0]->code == I_LD_WI || + p[0]->code == X_LD_WS || + p[0]->code == I_LEA_S || + p[0]->code == I_LD_BM || + p[0]->code == I_LD_BP || + p[0]->code == X_LD_BS || + p[0]->code == I_LD_UM || + p[0]->code == I_LD_UP || + p[0]->code == X_LD_US) && + (p[1]->code == I_LD_WM || + p[1]->code == I_LD_WI || + p[1]->code == X_LD_WS || + p[1]->code == I_LEA_S || + p[1]->code == I_LD_BM || + p[1]->code == I_LD_BP || + p[1]->code == X_LD_BS || + p[1]->code == I_LD_UM || + p[1]->code == I_LD_UP || + p[1]->code == X_LD_US) ) { - if (p[0]->code == X_LDB_S) - p[0]->code = I_EXTW; - else - p[0]->code = I_EXTUW; - p[0]->data = p[0]->type = 0; + /* remove code */ + *p[1] = *p[0]; + nb = 1; } /* - * ldwi i --> stwi const, i - * stw const + * __ld.wi i --> __st.wmi const, i + * __st.wm const * * XXX: This doesn't really do anything... */ else if - ((p[0]->code == I_STW || - p[0]->code == I_STB) && + ((p[0]->code == I_ST_WM || + p[0]->code == I_ST_UM) && (p[0]->type == T_VALUE) && - (p[1]->code == I_LDWI) + (p[1]->code == I_LD_WI) ) { - p[1]->code = (p[0]->code == I_STW) ? I_STWI : I_STBI; + p[1]->code = (p[0]->code == I_ST_WM) ? I_ST_WMI : I_ST_UMI; p[1]->imm_type = p[1]->type; p[1]->imm_data = p[1]->data; p[1]->type = p[0]->type; @@ -1798,84 +1852,84 @@ void push_ins (INS *ins) } /* - * __decld_{w/b/c}m n --> __lddec_{w/b/c}m n - * __addwi 1 + * __decld.{w/b/u}m symbol --> __lddec.{w/b/u}m symbol + * __add.wi 1 * - * __decld_{w/b/c}s n --> __lddec_{w/b/c}s n - * __addwi 1 + * __decld.{w/b/u}s n --> __lddec.{w/b/u}s n + * __add.wi 1 * - * __decld_{w/b/c}ar n --> __lddec_{w/b/c}ar n - * __addwi 1 + * __decld.{w/b/u}ar array --> __lddec.{w/b/u}ar array + * __add.wi 1 * * C post-decrement! */ else if - ((p[0]->code == I_ADDWI) && + ((p[0]->code == I_ADD_WI) && (p[0]->type == T_VALUE) && (p[0]->data == 1) && (p[1]->code == X_DECLD_WM || p[1]->code == X_DECLD_BM || - p[1]->code == X_DECLD_CM || + p[1]->code == X_DECLD_UM || p[1]->code == X_DECLD_WS || p[1]->code == X_DECLD_BS || - p[1]->code == X_DECLD_CS || + p[1]->code == X_DECLD_US || p[1]->code == X_DECLD_WAR || p[1]->code == X_DECLD_BAR || - p[1]->code == X_DECLD_CAR) + p[1]->code == X_DECLD_UAR) ) { /* replace code */ switch (p[1]->code) { case X_DECLD_WM: p[1]->code = X_LDDEC_WM; break; case X_DECLD_BM: p[1]->code = X_LDDEC_BM; break; - case X_DECLD_CM: p[1]->code = X_LDDEC_CM; break; + case X_DECLD_UM: p[1]->code = X_LDDEC_UM; break; case X_DECLD_WS: p[1]->code = X_LDDEC_WS; break; case X_DECLD_BS: p[1]->code = X_LDDEC_BS; break; - case X_DECLD_CS: p[1]->code = X_LDDEC_CS; break; + case X_DECLD_US: p[1]->code = X_LDDEC_US; break; case X_DECLD_WAR: p[1]->code = X_LDDEC_WAR; break; case X_DECLD_BAR: p[1]->code = X_LDDEC_BAR; break; - case X_DECLD_CAR: p[1]->code = X_LDDEC_CAR; break; + case X_DECLD_UAR: p[1]->code = X_LDDEC_UAR; break; default: break; } nb = 1; } /* - * __incld_{w/b/c}m n --> __ldinc_{w/b/c}m n - * __subwi 1 + * __incld.{w/b/u}m symbol --> __ldinc.{w/b/u}m symbol + * __sub.wi 1 * - * __incld_{w/b/c}s n --> __ldinc_{w/b/c}s n - * __subwi 1 + * __incld.{w/b/u}s n --> __ldinc.{w/b/u}s n + * __sub.wi 1 * - * __incld_{w/b/c}ar n --> __ldinc_{w/b/c}ar n - * __subwi 1 + * __incld.{w/b/u}ar array --> __ldinc.{w/b/u}ar array + * __sub.wi 1 * * C post-increment! */ else if - ((p[0]->code == I_SUBWI) && + ((p[0]->code == I_SUB_WI) && (p[0]->type == T_VALUE) && (p[0]->data == 1) && (p[1]->code == X_INCLD_WM || p[1]->code == X_INCLD_BM || - p[1]->code == X_INCLD_CM || + p[1]->code == X_INCLD_UM || p[1]->code == X_INCLD_WS || p[1]->code == X_INCLD_BS || - p[1]->code == X_INCLD_CS || + p[1]->code == X_INCLD_US || p[1]->code == X_INCLD_WAR || p[1]->code == X_INCLD_BAR || - p[1]->code == X_INCLD_CAR) + p[1]->code == X_INCLD_UAR) ) { /* replace code */ switch (p[1]->code) { case X_INCLD_WM: p[1]->code = X_LDINC_WM; break; case X_INCLD_BM: p[1]->code = X_LDINC_BM; break; - case X_INCLD_CM: p[1]->code = X_LDINC_CM; break; + case X_INCLD_UM: p[1]->code = X_LDINC_UM; break; case X_INCLD_WS: p[1]->code = X_LDINC_WS; break; case X_INCLD_BS: p[1]->code = X_LDINC_BS; break; - case X_INCLD_CS: p[1]->code = X_LDINC_CS; break; + case X_INCLD_US: p[1]->code = X_LDINC_US; break; case X_INCLD_WAR: p[1]->code = X_LDINC_WAR; break; case X_INCLD_BAR: p[1]->code = X_LDINC_BAR; break; - case X_INCLD_CAR: p[1]->code = X_LDINC_CAR; break; + case X_INCLD_UAR: p[1]->code = X_LDINC_UAR; break; default: break; } nb = 1; @@ -1883,33 +1937,33 @@ void push_ins (INS *ins) #if 0 /* - * __stwi 0 --> __stwz + * __st.wmi sym, 0 --> __st.wz sym * is_load() * * BETTER HANDLED WITH I_FENCE! */ else if - ((p[1]->code == I_STWI) && + ((p[1]->code == I_ST_WMI) && (p[1]->imm_type == T_VALUE) && (p[1]->imm_data == 0) && (is_load(p[0])) ) { - p[1]->code = I_STWZ; + p[1]->code = I_ST_WMZ; } /* - * __stbi 0 --> __stwz + * __stbmi sym, 0 --> __st.wz sym * is_load() * * BETTER HANDLED WITH I_FENCE! */ else if - ((p[1]->code == I_STBI) && + ((p[1]->code == I_ST_UMI) && (p[1]->imm_type == T_VALUE) && (p[1]->imm_data == 0) && (is_load(p[0])) ) { - p[1]->code = I_STBZ; + p[1]->code = I_ST_UMZ; } #endif @@ -1936,50 +1990,56 @@ void push_ins (INS *ins) * or things like "var++" that are not covered by the simpler peephole * rules earlier. * - * this covers storing to global and static variables, plus - * a whole bunch of math with integers ... + * this covers a bunch of math with immediate integers ... + * + * __ld.wi i --> ... + * __push.wr __{add/sub}.wi i + * ... + * __{add/sub}.wt + * + * this covers storing to global and static variables ... * - * __ldwi i --> ... - * __pushw __stw i or __stb i or __addwi i + * __ld.wi i --> ... + * __push.wr __st.{w/u}m i * ... - * __stwps or __stbps or __addws + * __st.{w/u}pt * * this covers storing to local variables ... * - * __lea_s i --> ... - * __pushw __stw_s i or __stb_s i + * __lea.s i --> ... + * __push.wr __st.{w/u}s i * ... - * __stwps or __stbps + * __st.{w/u}pt * * this covers storing to global and static arrays with "=" ... * - * __aslw --> __index.wr - * __addwi array ... - * __pushw __st.wat array + * __asl.wr --> __index.wr array + * __add.wi array ... + * __push.wr __st.wat array * ... - * __stwps + * __st.wpt * - * __addwi array --> __index.cr - * __pushw ... - * ... __st.cat array - * __stbps + * __add.wi array --> __index.ur array + * __push.wr ... + * ... __st.uat array + * __st.upt * * this covers storing to global and static arrays with "+=", "-=", etc ... * - * __aslw --> __ldp.war array - * __addwi array ... - * __pushw __st.wat array - * __stw _ptr - * __ldwp _ptr + * __asl.wr --> __ldp.war array + * __add.wi array ... + * __push.wr __st.wat array + * __st.wm __ptr + * __ld.wp __ptr * ... - * __stwps + * __st.wpt * - * __addwi array --> __ldp.car array - * __pushw ... - * __stw _ptr __st.cat array - * __ldubp _ptr + * __add.wi array --> __ldp.uar array + * __push.wr ... + * __st.wm __ptr __st.uat array + * __ld.up __ptr * ... - * __stbps + * __st.upt */ if (optimize >= 2) { int offset; @@ -1987,13 +2047,13 @@ void push_ins (INS *ins) /* check last instruction */ if (q_nb > 1 && - (q_ins[q_wr].code == I_STWPS || - q_ins[q_wr].code == I_STBPS || - q_ins[q_wr].code == I_ADDWS || - q_ins[q_wr].code == I_SUBWS || - q_ins[q_wr].code == I_ANDWS || - q_ins[q_wr].code == I_EORWS || - q_ins[q_wr].code == I_ORWS) + (q_ins[q_wr].code == I_ST_WPT || + q_ins[q_wr].code == I_ST_UPT || + q_ins[q_wr].code == I_ADD_WT || + q_ins[q_wr].code == I_SUB_WT || + q_ins[q_wr].code == I_AND_WT || + q_ins[q_wr].code == I_EOR_WT || + q_ins[q_wr].code == I_OR_WT) ) { /* browse back the instruction list and * establish a stack history @@ -2014,8 +2074,8 @@ void push_ins (INS *ins) /* check instruction */ switch (q_ins[scan].code) { case I_JSR: - case I_CMPW: - case I_CMPB: + case I_CMP_WT: + case I_CMP_UT: if (q_ins[scan].type == T_LIB) offset += 2; break; @@ -2026,18 +2086,18 @@ void push_ins (INS *ins) offset += (int)q_ins[scan].data; break; - case I_POPW: - case I_STWPS: - case I_STBPS: - case I_ADDWS: - case I_SUBWS: - case I_ANDWS: - case I_EORWS: - case I_ORWS: + case I_POP_WR: + case I_ST_WPT: + case I_ST_UPT: + case I_ADD_WT: + case I_SUB_WT: + case I_AND_WT: + case I_EOR_WT: + case I_OR_WT: offset += 2; break; - case I_PUSHW: + case I_PUSH_WR: offset -= 2; break; default: @@ -2047,15 +2107,15 @@ void push_ins (INS *ins) /* check offset */ if (offset == 0) { /* - * found the I_PUSHW that matches the I_STWPS + * found the I_PUSH_WR that matches the I_ST_WPT */ - int from = scan + 1; /* begin copying after the I_PUSHW */ - int drop = 2; /* drop I_PUSHW and the i-code before it */ + int from = scan + 1; /* begin copying after the I_PUSH_WR */ + int drop = 2; /* drop I_PUSH_WR and the i-code before it */ if (copy == 1) { /* hmm, may be not... * there should be at least one instruction - * between I_PUSHW and I_STWPS. + * between I_PUSH_WR and I_ST_WPT. * this case should never happen, though, * but better skipping it */ @@ -2068,63 +2128,63 @@ void push_ins (INS *ins) { /* * only handle sequences that start with an - * I_PUSHW preceded by I_LEA_S/I_LDWI/I_ADDWI + * I_PUSH_WR preceded by I_LEA_S/I_LD_WI/I_ADD_WI */ - if (q_ins[scan].code != I_PUSHW) + if (q_ins[scan].code != I_PUSH_WR) break; #if OPT_ARRAY_WR - if (q_ins[prev].code != I_LDWI && + if (q_ins[prev].code != I_LD_WI && q_ins[prev].code != I_LEA_S && - q_ins[prev].code != I_ADDWI) + q_ins[prev].code != I_ADD_WI) break; #else - if (q_ins[prev].code != I_LDWI && + if (q_ins[prev].code != I_LD_WI && q_ins[prev].code != I_LEA_S) break; #endif - if (q_ins[prev].code != I_LDWI && - q_ins[q_wr].code != I_STWPS && - q_ins[q_wr].code != I_STBPS) + if (q_ins[prev].code != I_LD_WI && + q_ins[q_wr].code != I_ST_WPT && + q_ins[q_wr].code != I_ST_UPT) break; - /* change stwps into stw_s/stw */ - if (q_ins[prev].code == I_LDWI) { + /* change __st.wpt into __st.w{m/s} */ + if (q_ins[prev].code == I_LD_WI) { switch (q_ins[q_wr].code) { - case I_STWPS: - q_ins[q_wr].code = I_STW; + case I_ST_WPT: + q_ins[q_wr].code = I_ST_WM; break; - case I_STBPS: - q_ins[q_wr].code = I_STB; + case I_ST_UPT: + q_ins[q_wr].code = I_ST_UM; break; - case I_ADDWS: - q_ins[q_wr].code = I_ADDWI; + case I_ADD_WT: + q_ins[q_wr].code = I_ADD_WI; break; - case I_SUBWS: - q_ins[q_wr].code = I_ISUBWI; + case I_SUB_WT: + q_ins[q_wr].code = I_ISUB_WI; break; - case I_ANDWS: - q_ins[q_wr].code = I_ANDWI; + case I_AND_WT: + q_ins[q_wr].code = I_AND_WI; break; - case I_EORWS: - q_ins[q_wr].code = I_EORWI; + case I_EOR_WT: + q_ins[q_wr].code = I_EOR_WI; break; - case I_ORWS: - q_ins[q_wr].code = I_ORWI; + case I_OR_WT: + q_ins[q_wr].code = I_OR_WI; break; default: abort(); } - /* use data from the preceding I_LDWI */ + /* use data from the preceding I_LD_WI */ q_ins[q_wr].type = q_ins[prev].type; q_ins[q_wr].data = q_ins[prev].data; } else if (q_ins[prev].code == I_LEA_S) { - if (q_ins[q_wr].code == I_STWPS) - q_ins[q_wr].code = X_STW_S; + if (q_ins[q_wr].code == I_ST_WPT) + q_ins[q_wr].code = X_ST_WS; else - q_ins[q_wr].code = X_STB_S; + q_ins[q_wr].code = X_ST_US; /* use data from the preceding I_LEA_S */ q_ins[q_wr].type = q_ins[prev].type; q_ins[q_wr].data = q_ins[prev].data; @@ -2132,10 +2192,10 @@ void push_ins (INS *ins) #if OPT_ARRAY_WR } else { - int push = X_INDEX_CR; - int code = X_ST_CAT; + int push = X_INDEX_UR; + int code = X_ST_UAT; - /* make sure that I_ADDWI is really a short array */ + /* make sure that I_ADD_WI is really a short array */ if (q_ins[prev].type != T_SYMBOL || !is_small_array((SYMBOL *)q_ins[prev].data)) break; @@ -2144,24 +2204,24 @@ void push_ins (INS *ins) from = scan; drop = 1; - /* make sure that an I_STWPS has an I_ASLW */ - if (q_ins[q_wr].code == I_STWPS) { + /* make sure that an I_ST_WPT has an I_ASL_WR */ + if (q_ins[q_wr].code == I_ST_WPT) { int aslw = prev - 1; if (aslw < 0) aslw += Q_SIZE; - if (copy == q_nb || q_ins[aslw].code != I_ASLW) + if (copy == q_nb || q_ins[aslw].code != I_ASL_WR) break; drop = 2; push = X_INDEX_WR; code = X_ST_WAT; } - /* push the index from the preceding I_ADDWI */ + /* push the index from the preceding I_ADD_WI */ q_ins[scan].code = push; q_ins[scan].type = T_SYMBOL; q_ins[scan].data = q_ins[prev].data; - /* use data from the preceding I_ADDWI */ + /* use data from the preceding I_ADD_WI */ q_ins[q_wr].code = code; q_ins[q_wr].type = T_SYMBOL; q_ins[q_wr].data = q_ins[prev].data; @@ -2171,7 +2231,7 @@ void push_ins (INS *ins) /* * adjust stack references for the - * removal of the I_PUSHW + * removal of the I_PUSH_WR */ for (int temp = copy; temp > 1; temp--) { scan += 1; @@ -2231,49 +2291,49 @@ void push_ins (INS *ins) } /* - * __pushw --> __st{b|w}ip i - * __ldwi i - * __st{b|w}ps + * __push.wr --> __st.{w/u}pi i + * __ld.wi i + * __st.{w/u}pt * * This cannot be done earlier because it screws up * the reordering optimization above. */ if - ((p[0]->code == I_STWPS || - p[0]->code == I_STBPS) && - (p[1]->code == I_LDWI) && + ((p[0]->code == I_ST_WPT || + p[0]->code == I_ST_UPT) && + (p[1]->code == I_LD_WI) && (p[1]->type == T_VALUE) && - (p[2]->code == I_PUSHW) + (p[2]->code == I_PUSH_WR) ) { /* replace code */ - p[2]->code = p[0]->code == I_STWPS ? I_STWIP : I_STBIP; + p[2]->code = p[0]->code == I_ST_WPT ? I_ST_WPI : I_ST_UPI; p[2]->data = p[1]->data; nb = 2; } /* - * ldwi i --> stwi i, j - * stwip j + * ld.wi i --> st.wmi i, j + * st.wpi j */ else if - ((p[0]->code == I_STWIP) && - (p[1]->code == I_LDWI) + ((p[0]->code == I_ST_WPI) && + (p[1]->code == I_LD_WI) ) { - p[1]->code = I_STWI; + p[1]->code = I_ST_WMI; p[1]->imm_type = p[0]->type; p[1]->imm_data = p[0]->data; nb = 1; } /* - * ldwi i --> stbi i, j - * stbip j + * ld.wi i --> st.bmi i, j + * st.upi j */ else if - ((p[0]->code == I_STBIP) && - (p[1]->code == I_LDWI) + ((p[0]->code == I_ST_UPI) && + (p[1]->code == I_LD_WI) ) { - p[1]->code = I_STBI; + p[1]->code = I_ST_UMI; p[1]->imm_type = p[0]->type; p[1]->imm_data = p[0]->data; nb = 1; @@ -2281,9 +2341,9 @@ void push_ins (INS *ins) #if 0 /* - * __pushw --> __stw __ptr + * __push.wr --> __st.wm __ptr * - * __st{b|w}ps __st{b|w}p __ptr + * __st.{w/u}pt __st.{w/u}p __ptr * * This cannot be done earlier because it screws up * the reordering optimization above. @@ -2291,21 +2351,21 @@ void push_ins (INS *ins) * THIS IS VERY RARE, REMOVE IT FOR NOW AND RETHINK IT */ else if - ((p[0]->code == I_STBPS || - p[0]->code == I_STWPS) && + ((p[0]->code == I_ST_UPT || + p[0]->code == I_ST_WPT) && (is_load(p[1])) && - (p[2]->code == I_PUSHW) + (p[2]->code == I_PUSH_WR) ) { - p[2]->code = I_STW; + p[2]->code = I_ST_WM; p[2]->type = T_PTR; /* We just removed a push, adjust SP-relative addresses. */ if (is_sprel(p[1])) p[1]->data -= 2; - if (p[0]->code == I_STBPS) - p[0]->code = I_STBP; + if (p[0]->code == I_ST_UPT) + p[0]->code = I_ST_UP; else - p[0]->code = I_STWP; + p[0]->code = I_ST_WP; q_ins[q_wr].type = T_PTR; } #endif diff --git a/src/hucc/pseudo.c b/src/hucc/pseudo.c index 2d4ffa62..6b573d73 100644 --- a/src/hucc/pseudo.c +++ b/src/hucc/pseudo.c @@ -829,7 +829,7 @@ void do_asm_func (int type) /* gen code */ if (ptr) - out_ins(I_LDWI, type, (intptr_t)ptr); + out_ins(I_LD_WI, type, (intptr_t)ptr); else error("out of memory"); } diff --git a/src/hucc/sym.c b/src/hucc/sym.c index 02e34bd8..7b63b649 100644 --- a/src/hucc/sym.c +++ b/src/hucc/sym.c @@ -425,37 +425,37 @@ void declloc (char typ, char stclass, int otag) #if ULI_NORECURSE if (norecurse) { sprintf(locsym, "_%s_lend - %d", current_fn, (int) -locals_ptr); - out_ins_ex(I_STBI, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); + out_ins_ex(I_ST_UMI, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); } else #else if (stclass == (LSTATIC | WASAUTO)) { if (num == 0) - out_ins(I_STBZ, T_SYMBOL, (intptr_t)ssym); + out_ins(I_ST_UMZ, T_SYMBOL, (intptr_t)ssym); else - out_ins_ex(I_STBI, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); + out_ins_ex(I_ST_UMI, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); } else #endif - out_ins_ex(X_STBI_S, T_VALUE, 0, T_VALUE, num); + out_ins_ex(X_ST_USI, T_VALUE, 0, T_VALUE, num); } else if (k == 2) { #if ULI_NORECURSE if (norecurse) { sprintf(locsym, "_%s_lend - %d", current_fn, (int) -locals_ptr); - out_ins_ex(I_STWI, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); + out_ins_ex(I_ST_WMI, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); } else #else if (stclass == (LSTATIC | WASAUTO)) { if (num == 0) - out_ins(I_STWZ, T_SYMBOL, (intptr_t)ssym); + out_ins(I_ST_WMZ, T_SYMBOL, (intptr_t)ssym); else - out_ins_ex(I_STWI, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); + out_ins_ex(I_ST_WMI, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); } else #endif - out_ins_ex(X_STWI_S, T_VALUE, 0, T_VALUE, num); + out_ins_ex(X_ST_WSI, T_VALUE, 0, T_VALUE, num); } else error("complex type initialization not implemented"); From 0484ec66bc95634de20fe3c9be7ecc6aacb9bd65 Mon Sep 17 00:00:00 2001 From: John Brandwood Date: Mon, 16 Sep 2024 13:16:07 -0400 Subject: [PATCH 4/5] Teach HuCC to use I_FENCE to optimize "var=69" immediate stores to the stack and memory when the value is not needed afterwards. Teach HuCC to optimize __fastcall "acc" immediate values that are byte-sized. Generate I_FENCE after function parameters so that they can be optimized. Remove a couple of peephole optimizer rules that aren't relevant anymore. --- include/hucc/hucc-codegen.asm | 115 ++++++++++++++---- src/hucc/code.c | 37 ++++-- src/hucc/defs.h | 13 +- src/hucc/fastcall.h | 11 +- src/hucc/function.c | 39 ++++-- src/hucc/gen.c | 4 + src/hucc/gen.h | 1 + src/hucc/optimize.c | 219 +++++++++++++--------------------- src/hucc/pragma.c | 4 +- src/hucc/sym.c | 18 +-- 10 files changed, 263 insertions(+), 198 deletions(-) diff --git a/include/hucc/hucc-codegen.asm b/include/hucc/hucc-codegen.asm index 62e71e26..9faf2f65 100644 --- a/include/hucc/hucc-codegen.asm +++ b/include/hucc/hucc-codegen.asm @@ -72,6 +72,20 @@ __fence .macro +; *************************************************************************** +; *************************************************************************** +; i-code that declares a byte sized primary register +; *************************************************************************** +; *************************************************************************** + +; ************** +; this exists to mark that the primary register only needs byte accuracy + +__short .macro + .endm + + + ; *************************************************************************** ; *************************************************************************** ; i-codes for handling farptr @@ -781,12 +795,34 @@ __tst.ws .macro ; __STACK ; ************** __ld.wi .macro - .if ((\?1 == ARG_ABS) && (\1 >= 0) && (\1 < 256)) + .if (\?1 != ARG_ABS) lda.l #\1 - cly + ldy.h #\1 .else + .if (\1 & $00FF) lda.l #\1 + .else + cla + .endif + .if (\1 & $FF00) ldy.h #\1 + .else + cly + .endif + .endif + .endm + +; ************** + +__ld.uiq .macro + .if (\?1 != ARG_ABS) + lda.l #\1 + .else + .if (\1 & $00FF) + lda #\1 + .else + cla + .endif .endif .endm @@ -962,7 +998,7 @@ __ld.ws .macro ; __STACK ; ************** __ld.bs .macro ; __STACK - lda.l <__stack + \1, x + lda <__stack + \1, x cly bpl !+ ; signed dey @@ -1534,18 +1570,37 @@ __st.umz .macro ; ************** -__st.wmi .macro - lda.l #\2 - sta.l \1 - ldy.h #\2 - sty.h \1 +__st.wmiq .macro + .if (\?1 != ARG_ABS) + lda.l #\1 + sta.l \2 + lda.h #\1 + sta.h \2 + .else + .if (\1 & $00FF) + lda.l #\1 + sta.l \2 + .else + stz.l \2 + .endif + .if (\1 & $FF00) + lda.h #\1 + sta.h \2 + .else + stz.h \2 + .endif + .endif .endm ; ************** -__st.umi .macro - lda.l #\2 - sta \1 +__st.umiq .macro + .if (\1 != 0) + lda.l #\1 + sta \2 + .else + stz \2 + .endif .endm ; ************** @@ -1553,8 +1608,8 @@ __st.umi .macro __st.wpi .macro sta.l <__ptr sty.h <__ptr - lda.h #\1 ldy #1 + lda.h #\1 sta [__ptr], y tay lda.l #\1 @@ -1567,8 +1622,8 @@ __st.upi .macro sta.l <__ptr sty.h <__ptr lda.l #\1 + ldy.h #\1 sta [__ptr] - cly .endm ; ************** @@ -1662,25 +1717,43 @@ __st.wat .macro __st.uat .macro plx - sta.l \1, x + sta \1, x plx .endm ; ************** -__st.wsi .macro ; __STACK +__st.wsiq .macro + .if (\?1 != ARG_ABS) lda.l #\1 sta.l <__stack + \2, x - ldy.h #\1 - sty.h <__stack + \2, x + lda.h #\1 + sta.h <__stack + \2, x + .else + .if (\1 & $00FF) + lda.l #\1 + sta.l <__stack + \2, x + .else + stz.l <__stack + \2, x + .endif + .if (\1 & $FF00) + lda.h #\1 + sta.h <__stack + \2, x + .else + stz.h <__stack + \2, x + .endif + .endif .endm ; ************** -__st.usi .macro ; __STACK +__st.usiq .macro + .if (\1 != 0) lda.l #\1 - sta.l <__stack + \2, x - cly + sta <__stack + \2, x + .else + stz <__stack + \2, x + .endif .endm ; ************** @@ -1693,7 +1766,7 @@ __st.ws .macro ; __STACK ; ************** __st.us .macro ; __STACK - sta.l <__stack + \1, x + sta <__stack + \1, x .endm ; ************** diff --git a/src/hucc/code.c b/src/hucc/code.c index 938564af..f4c5f714 100644 --- a/src/hucc/code.c +++ b/src/hucc/code.c @@ -270,6 +270,13 @@ void gen_code (INS *tmp) nl(); break; + /* i-code that declares a byte sized primary register */ + + case I_SHORT: + ot("__short"); + nl(); + break; + /* i-codes for handling farptr */ case I_FARPTR: @@ -654,6 +661,12 @@ void gen_code (INS *tmp) nl(); break; + case X_LD_UIQ: + ot("__ld.uiq\t"); + out_type(type, data); + nl(); + break; + case I_LEA_S: ot("__lea.s\t\t"); outdec((int)data); @@ -1101,19 +1114,19 @@ void gen_code (INS *tmp) nl(); break; - case I_ST_WMI: - ot("__st.wmi\t"); - out_type(type, data); - outstr(", "); + case I_ST_WMIQ: + ot("__st.wmiq\t"); out_type(imm_type, imm_data); + outstr(", "); + out_type(type, data); nl(); break; - case I_ST_UMI: - ot("__st.umi\t"); - out_type(type, data); - outstr(", "); + case I_ST_UMIQ: + ot("__st.umiq\t"); out_type(imm_type, imm_data); + outstr(", "); + out_type(type, data); nl(); break; @@ -1161,8 +1174,8 @@ void gen_code (INS *tmp) ol("__st.upt"); break; - case X_ST_WSI: - ot("__st.wsi\t"); + case X_ST_WSIQ: + ot("__st.wsiq\t"); outdec((int)imm_data); outstr(", "); outdec((int)data); @@ -1170,8 +1183,8 @@ void gen_code (INS *tmp) nl(); break; - case X_ST_USI: - ot("__st.usi\t"); + case X_ST_USIQ: + ot("__st.usiq\t"); outdec((int)imm_data); outstr(", "); outdec((int)data); diff --git a/src/hucc/defs.h b/src/hucc/defs.h index 93e4b92e..06bb7d0a 100644 --- a/src/hucc/defs.h +++ b/src/hucc/defs.h @@ -43,6 +43,10 @@ enum ICODE { I_FENCE = 1, + /* i-code that declares a byte sized primary register */ + + I_SHORT, + /* i-codes for handling farptr */ I_FARPTR, @@ -113,6 +117,7 @@ enum ICODE { /* i-codes for loading the primary register */ I_LD_WI, + X_LD_UIQ, I_LEA_S, I_LD_WM, @@ -207,8 +212,8 @@ enum ICODE { I_ST_WMZ, I_ST_UMZ, - I_ST_WMI, - I_ST_UMI, + I_ST_WMIQ, + I_ST_UMIQ, I_ST_WPI, I_ST_UPI, I_ST_WM, @@ -217,8 +222,8 @@ enum ICODE { I_ST_UP, I_ST_WPT, I_ST_UPT, - X_ST_WSI, - X_ST_USI, + X_ST_WSIQ, + X_ST_USIQ, X_ST_WS, X_ST_US, diff --git a/src/hucc/fastcall.h b/src/hucc/fastcall.h index 5d4f536b..5dd9b3a5 100644 --- a/src/hucc/fastcall.h +++ b/src/hucc/fastcall.h @@ -1,9 +1,10 @@ /* defines */ -#define TYPE_ACC 0x00 -#define TYPE_BYTE 0x01 -#define TYPE_WORD 0x02 -#define TYPE_FARPTR 0x03 -#define TYPE_DWORD 0x04 +#define TYPE_BYTEACC 0x00 +#define TYPE_WORDACC 0x01 +#define TYPE_BYTE 0x02 +#define TYPE_WORD 0x03 +#define TYPE_FARPTR 0x04 +#define TYPE_DWORD 0x05 extern struct fastcall ftemp; extern struct fastcall *fastcall_tbl[256]; diff --git a/src/hucc/function.c b/src/hucc/function.c index f1f44e9f..e3c4519b 100644 --- a/src/hucc/function.c +++ b/src/hucc/function.c @@ -204,7 +204,8 @@ void newfunc (const char *sname, int ret_ptr_order, int ret_type, int ret_otag, } if (!strcmp(fc->argname[fc_args], "acc")) - fc->argtype[fc_args] = TYPE_ACC; + fc->argtype[fc_args] = + (fc->argtype[fc_args] == TYPE_BYTE) ? TYPE_BYTEACC : TYPE_WORDACC; } nbarg++; if (is_fastcall) { @@ -271,7 +272,7 @@ void newfunc (const char *sname, int ret_ptr_order, int ret_type, int ret_otag, int i; for (i = 0; i < fc_args - 1; i++) { - if (fc->argtype[i] == TYPE_ACC) { + if (fc->argtype[i] == TYPE_WORDACC || fc->argtype[i] == TYPE_BYTEACC) { error("fastcall accumulator argument must come last"); kill(); return; @@ -616,6 +617,7 @@ void callfunction (char *ptr) else { expression(NO); gpusharg(INTSIZE); + gfence(); } argsiz = argsiz + INTSIZE; argcnt++; @@ -657,14 +659,18 @@ void callfunction (char *ptr) case TYPE_BYTE: if (i < max_fc_arg) SPILLB(fast->argname[j]) - else + else { out_ins(I_ST_UM, T_LITERAL, (intptr_t)fast->argname[j]); + gfence(); + } break; case TYPE_WORD: if (i < max_fc_arg) SPILLW(fast->argname[j]) - else + else { out_ins(I_ST_WM, T_LITERAL, (intptr_t)fast->argname[j]); + gfence(); + } break; case TYPE_FARPTR: arg_to_fptr(fast, j, arg_idx + i, adj); @@ -688,10 +694,17 @@ void callfunction (char *ptr) } j += 2; break; - case TYPE_ACC: + case TYPE_WORDACC: + if (i < max_fc_arg) + SPILLW(0) + uses_acc = 1; + break; + case TYPE_BYTEACC: if (i < max_fc_arg) SPILLW(0) - uses_acc = 1; + else + gshort(); + uses_acc = 1; break; default: error("fastcall internal error"); @@ -708,6 +721,7 @@ void callfunction (char *ptr) for (i = 0; i < argcnt; i++) { arg_flush(arg_idx + i, 0); gpusharg(0); + gfence(); } } } @@ -724,18 +738,25 @@ void callfunction (char *ptr) if (sparg_idx) { /* Reloading corrupts acc, so we need to save it if it is used by the callee. */ - if (uses_acc) + if (uses_acc) { out_ins(I_ST_WM, T_LITERAL, (intptr_t)"__temp"); + gfence(); + } for (i = sparg_idx - 1; i > -1; i--) { if (spilled_arg_sizes[i] == 1) { out_ins(I_SPOP_UR, 0, 0); - out_ins(I_ST_UM, T_LITERAL, (intptr_t)spilled_args[i]); + if (spilled_args[i]) { + out_ins(I_ST_UM, T_LITERAL, (intptr_t)spilled_args[i]); + gfence(); + } } else { out_ins(I_SPOP_WR, 0, 0); - if (spilled_args[i]) + if (spilled_args[i]) { out_ins(I_ST_WM, T_LITERAL, (intptr_t)spilled_args[i]); + gfence(); + } } } diff --git a/src/hucc/gen.c b/src/hucc/gen.c index 5aa924b0..2a8f1e7d 100644 --- a/src/hucc/gen.c +++ b/src/hucc/gen.c @@ -672,3 +672,7 @@ void gfence (void) { out_ins(I_FENCE, 0, 0); } +void gshort (void) +{ + out_ins(I_SHORT, 0, 0); +} diff --git a/src/hucc/gen.h b/src/hucc/gen.h index 3aed119d..f487efb5 100644 --- a/src/hucc/gen.h +++ b/src/hucc/gen.h @@ -53,6 +53,7 @@ void gcast (int type); void gsei (void); void gcli (void); void gfence (void); +void gshort (void); void scale_const (int type, int otag, int *size); diff --git a/src/hucc/optimize.c b/src/hucc/optimize.c index d45c335a..ffc49b61 100644 --- a/src/hucc/optimize.c +++ b/src/hucc/optimize.c @@ -51,6 +51,10 @@ unsigned char icode_flags[] = { /* I_FENCE */ 0, + /* i-code that declares a byte sized primary register */ + + /* I_SHORT */ 0, + // i-codes for handling farptr /* I_FARPTR */ 0, @@ -121,6 +125,7 @@ unsigned char icode_flags[] = { // i-codes for loading the primary register /* I_LD_WI */ 0, + /* X_LD_UIQ */ 0, /* I_LEA_S */ IS_SPREL, /* I_LD_WM */ 0, @@ -215,8 +220,8 @@ unsigned char icode_flags[] = { /* I_ST_WMZ */ 0, /* I_ST_UMZ */ 0, - /* I_ST_WMI */ 0, - /* I_ST_UMI */ 0, + /* I_ST_WMIQ */ 0, + /* I_ST_UMIQ */ 0, /* I_ST_WPI */ 0, /* I_ST_UPI */ 0, /* I_ST_WM */ 0, @@ -225,8 +230,8 @@ unsigned char icode_flags[] = { /* I_ST_UP */ 0, /* I_ST_WPT */ 0, /* I_ST_UPT */ 0, - /* X_ST_WSI */ IS_SPREL, - /* X_ST_USI */ IS_SPREL, + /* X_ST_WSIQ */ IS_SPREL, + /* X_ST_USIQ */ IS_SPREL, /* X_ST_WS */ IS_SPREL, /* X_ST_US */ IS_SPREL, @@ -407,11 +412,44 @@ void push_ins (INS *ins) /* LEVEL 1 - FUN STUFF STARTS HERE */ nb = 0; - /* first check for I_FENCE, then remove it ASAP */ + /* first check for I_FENCE, and remove it ASAP */ if (q_nb >= 1 && p[0]->code == I_FENCE) { /* remove I_FENCE after it has been checked */ nb = 1; + /* + * __ld.wi i --> __st.{w/u}miq symbol, i + * __st.{w/u}m symbol + * __fence + * + * __ld.wi i --> __st.{w/u}siq n, 1 + * __st.{w/u}s n + * __fence + */ + if + ((q_nb >= 3) && + (p[1]->code == I_ST_WM || + p[1]->code == I_ST_UM || + p[1]->code == X_ST_WS || + p[1]->code == X_ST_US) && + (p[2]->code == I_LD_WI) && + (p[2]->type == T_VALUE) + ) { + /* replace code */ + intptr_t data = p[2]->data; + *p[2] = *p[1]; + switch (p[1]->code) { + case I_ST_WM: p[2]->code = I_ST_WMIQ; break; + case I_ST_UM: p[2]->code = I_ST_UMIQ; break; + case X_ST_WS: p[2]->code = X_ST_WSIQ; break; + case X_ST_US: p[2]->code = X_ST_USIQ; break; + default: abort(); + } + p[2]->imm_type = T_VALUE; + p[2]->imm_data = data; + nb = 2; + } + /* * __getacc --> * __fence @@ -419,7 +457,7 @@ void push_ins (INS *ins) * __add.wi / __sub.wi --> * __fence */ - if + else if ((q_nb >= 2) && (p[1]->code == I_ADD_WI || p[1]->code == I_SUB_WI || @@ -534,6 +572,37 @@ void push_ins (INS *ins) } } + /* then check for I_SHORT, and remove it ASAP */ + if (q_nb >= 1 && p[0]->code == I_SHORT) { + /* remove I_SHORT after it has been checked */ + nb = 1; + + /* + * __ld.wi i --> __ld.uiq i + * __short + */ + if + ((q_nb >= 2) && + (p[1]->code == I_LD_WI) + ) { + p[1]->code = X_LD_UIQ; + nb = 1; + } + + /* flush queue */ + if (nb) { + q_wr -= nb; + q_nb -= nb; + nb = 0; + + if (q_wr < 0) + q_wr += Q_SIZE; + + /* loop */ + goto lv1_loop; + } + } + /* 6-instruction patterns */ if (q_nb >= 6) { /* @@ -660,28 +729,6 @@ void push_ins (INS *ins) nb = 1; } - /* - * __lea.s i --> __st.{w/u}si i, j - * __push.wr - * __ld.wi j - * __st.{w/u}pt - */ - else if - ((p[0]->code == I_ST_WPT || - p[0]->code == I_ST_UPT) && - (p[1]->code == I_LD_WI) && - (p[1]->type == T_VALUE) && - (p[2]->code == I_PUSH_WR) && - (p[3]->code == I_LEA_S) - - ) { - /* replace code */ - p[3]->code = (p[0]->code == I_ST_WPT) ? X_ST_WSI : X_ST_USI; - p[3]->imm_type = p[1]->type; - p[3]->imm_data = p[1]->data; - nb = 3; - } - /* * __lea.s i --> __lea.s (i + j) * __push.wr @@ -724,26 +771,6 @@ void push_ins (INS *ins) nb = 3; } - /* - * __ld.wi p --> __st.wmi p, i - * __push.wr - * __ld.wi i - * __st{w/u}pt - */ - else if - ((p[0]->code == I_ST_WPT || - p[0]->code == I_ST_UPT) && - (p[1]->code == I_LD_WI) && - (p[2]->code == I_PUSH_WR) && - (p[3]->code == I_LD_WI) - ) { - /* replace code */ - p[3]->code = p[0]->code == I_ST_WPT ? I_ST_WMI : I_ST_UMI; - p[3]->imm_type = p[1]->type; - p[3]->imm_data = p[1]->data; - nb = 3; - } - #if 0 /* * __push.wr --> __addbi_p i @@ -1584,10 +1611,14 @@ void push_ins (INS *ins) /* * __ld.wi symbol --> __ld.wi (symbol + j) * __add.wi j + * + * __add.wi symbol --> __add.wi (symbol + j) + * __add.wi j */ else if ((p[0]->code == I_ADD_WI) && - (p[1]->code == I_LD_WI) && + (p[1]->code == I_LD_WI || + p[1]->code == I_ADD_WI) && (p[0]->type == T_VALUE) && (p[1]->type == T_SYMBOL) @@ -1831,26 +1862,6 @@ void push_ins (INS *ins) nb = 1; } - /* - * __ld.wi i --> __st.wmi const, i - * __st.wm const - * - * XXX: This doesn't really do anything... - */ - else if - ((p[0]->code == I_ST_WM || - p[0]->code == I_ST_UM) && - (p[0]->type == T_VALUE) && - (p[1]->code == I_LD_WI) - ) { - p[1]->code = (p[0]->code == I_ST_WM) ? I_ST_WMI : I_ST_UMI; - p[1]->imm_type = p[1]->type; - p[1]->imm_data = p[1]->data; - p[1]->type = p[0]->type; - p[1]->data = p[0]->data; - nb = 1; - } - /* * __decld.{w/b/u}m symbol --> __lddec.{w/b/u}m symbol * __add.wi 1 @@ -1935,38 +1946,6 @@ void push_ins (INS *ins) nb = 1; } -#if 0 - /* - * __st.wmi sym, 0 --> __st.wz sym - * is_load() - * - * BETTER HANDLED WITH I_FENCE! - */ - else if - ((p[1]->code == I_ST_WMI) && - (p[1]->imm_type == T_VALUE) && - (p[1]->imm_data == 0) && - (is_load(p[0])) - ) { - p[1]->code = I_ST_WMZ; - } - - /* - * __stbmi sym, 0 --> __st.wz sym - * is_load() - * - * BETTER HANDLED WITH I_FENCE! - */ - else if - ((p[1]->code == I_ST_UMI) && - (p[1]->imm_type == T_VALUE) && - (p[1]->imm_data == 0) && - (is_load(p[0])) - ) { - p[1]->code = I_ST_UMZ; - } -#endif - /* flush queue */ if (nb) { q_wr -= nb; @@ -1999,15 +1978,15 @@ void push_ins (INS *ins) * * this covers storing to global and static variables ... * - * __ld.wi i --> ... - * __push.wr __st.{w/u}m i + * __ld.wi symbol --> ... + * __push.wr __st.{w/u}m symbol * ... * __st.{w/u}pt * * this covers storing to local variables ... * - * __lea.s i --> ... - * __push.wr __st.{w/u}s i + * __lea.s n --> ... + * __push.wr __st.{w/u}s n * ... * __st.{w/u}pt * @@ -2297,6 +2276,8 @@ void push_ins (INS *ins) * * This cannot be done earlier because it screws up * the reordering optimization above. + * + * JCB: This is optimizing writes though a pointer variable! */ if ((p[0]->code == I_ST_WPT || @@ -2311,34 +2292,6 @@ void push_ins (INS *ins) nb = 2; } - /* - * ld.wi i --> st.wmi i, j - * st.wpi j - */ - else if - ((p[0]->code == I_ST_WPI) && - (p[1]->code == I_LD_WI) - ) { - p[1]->code = I_ST_WMI; - p[1]->imm_type = p[0]->type; - p[1]->imm_data = p[0]->data; - nb = 1; - } - - /* - * ld.wi i --> st.bmi i, j - * st.upi j - */ - else if - ((p[0]->code == I_ST_UPI) && - (p[1]->code == I_LD_WI) - ) { - p[1]->code = I_ST_UMI; - p[1]->imm_type = p[0]->type; - p[1]->imm_data = p[0]->data; - nb = 1; - } - #if 0 /* * __push.wr --> __st.wm __ptr diff --git a/src/hucc/pragma.c b/src/hucc/pragma.c index 2accc4c2..3a04ebb1 100644 --- a/src/hucc/pragma.c +++ b/src/hucc/pragma.c @@ -279,7 +279,7 @@ void new_fastcall (void) if (!symget(sname)) { /* auto */ if (*cmdptr != ',') - ptr->argtype[i] = TYPE_ACC; + ptr->argtype[i] = TYPE_WORDACC; else { error("fastcall register missing"); return; @@ -347,7 +347,7 @@ void new_fastcall (void) else { if (strcmp(sname, "acc") == 0) { /* accumulator */ - ptr->argtype[i] = TYPE_ACC; + ptr->argtype[i] = TYPE_WORDACC; } else { /* variable */ diff --git a/src/hucc/sym.c b/src/hucc/sym.c index 7b63b649..853e8319 100644 --- a/src/hucc/sym.c +++ b/src/hucc/sym.c @@ -425,37 +425,31 @@ void declloc (char typ, char stclass, int otag) #if ULI_NORECURSE if (norecurse) { sprintf(locsym, "_%s_lend - %d", current_fn, (int) -locals_ptr); - out_ins_ex(I_ST_UMI, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); + out_ins_ex(I_ST_UMIQ, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); } else #else if (stclass == (LSTATIC | WASAUTO)) { - if (num == 0) - out_ins(I_ST_UMZ, T_SYMBOL, (intptr_t)ssym); - else - out_ins_ex(I_ST_UMI, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); + out_ins_ex(I_ST_UMIQ, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); } else #endif - out_ins_ex(X_ST_USI, T_VALUE, 0, T_VALUE, num); + out_ins_ex(X_ST_USIQ, T_VALUE, 0, T_VALUE, num); } else if (k == 2) { #if ULI_NORECURSE if (norecurse) { sprintf(locsym, "_%s_lend - %d", current_fn, (int) -locals_ptr); - out_ins_ex(I_ST_WMI, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); + out_ins_ex(I_ST_WMIQ, T_SYMBOL, (intptr_t)locsym, T_VALUE, num); } else #else if (stclass == (LSTATIC | WASAUTO)) { - if (num == 0) - out_ins(I_ST_WMZ, T_SYMBOL, (intptr_t)ssym); - else - out_ins_ex(I_ST_WMI, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); + out_ins_ex(I_ST_WMIQ, T_SYMBOL, (intptr_t)ssym, T_VALUE, num); } else #endif - out_ins_ex(X_ST_WSI, T_VALUE, 0, T_VALUE, num); + out_ins_ex(X_ST_WSIQ, T_VALUE, 0, T_VALUE, num); } else error("complex type initialization not implemented"); From a3f4bc4cdb8c152931b9728e6fbe27357a4b6573 Mon Sep 17 00:00:00 2001 From: John Brandwood Date: Mon, 16 Sep 2024 13:17:46 -0400 Subject: [PATCH 5/5] Change PCEAS to omit the output of .if/.else/.endif while expanding a macro because they just make the listing hard to read. --- src/mkit/as/assemble.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mkit/as/assemble.c b/src/mkit/as/assemble.c index 0ab83ac7..95036097 100644 --- a/src/mkit/as/assemble.c +++ b/src/mkit/as/assemble.c @@ -140,7 +140,7 @@ assemble(int do_label) } if (if_state[if_level]) { skip_lines = !if_flag[if_level]; - if (pass == LAST_PASS) + if (pass == LAST_PASS && !expand_macro) println(); } return; @@ -155,7 +155,7 @@ assemble(int do_label) return; } } - if (if_state[if_level] && (pass == LAST_PASS)) + if (if_state[if_level] && (pass == LAST_PASS) && !expand_macro) println(); skip_lines = !if_state[if_level]; if_level--; @@ -528,7 +528,7 @@ do_if(int *ip) if (!skip_lines) skip_lines = if_flag[if_level] = value ? 0 : 1; - if (pass == LAST_PASS) { + if (pass == LAST_PASS && !expand_macro) { loadlc(value, 1); println(); } @@ -600,7 +600,7 @@ do_ifdef(int *ip) } } - if (pass == LAST_PASS) { + if (pass == LAST_PASS && !expand_macro) { loadlc(!skip_lines, 1); println(); }