From a7ecdc7edca2e202f841300290228c598a918cf6 Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Thu, 22 Mar 2018 16:38:05 -0700 Subject: [PATCH] Save a few bytes so we can test JIT --- src/libsrc/apple/jit.pla | 247 ++++++++++++------------------------- src/vmsrc/apple/cmdjit.pla | 18 +-- 2 files changed, 86 insertions(+), 179 deletions(-) diff --git a/src/libsrc/apple/jit.pla b/src/libsrc/apple/jit.pla index d0470a5..bb066e4 100644 --- a/src/libsrc/apple/jit.pla +++ b/src/libsrc/apple/jit.pla @@ -29,6 +29,20 @@ const codemax = $BEF0 // const interpentry = $03DC // +// Resolve virtual X with real X +// +def resolveX(codeptr, VX)#2 + while VX > 0 + ^codeptr = $E8; codeptr++ // INX + VX-- + loop + while VX < 0 + ^codeptr = $CA; codeptr++ // DEX + VX++ + loop + return codeptr, 0 +end +// // JIT compiler entry // def compiler(defptr)#0 @@ -229,14 +243,7 @@ def compiler(defptr)#0 ^codeptr = $D0+VX; codeptr++ // ESTKL A_IS_TOSL = FALSE fin - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) opcode = opcode & $FE fin if opcode < $20 @@ -276,15 +283,7 @@ def compiler(defptr)#0 puts("BREQ "); puti(dest) //^codeptr = $E8; codeptr++ // INX //^codeptr = $E8; codeptr++ // INX - VX = VX + 2 - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX + 2) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0-2+VX; codeptr++ // ESTKL-2 @@ -314,15 +313,7 @@ def compiler(defptr)#0 puts("BRNE "); puti(dest) //^codeptr = $E8; codeptr++ // INX //^codeptr = $E8; codeptr++ // INX - VX = VX + 2 - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX + 2) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0-2+VX; codeptr++ // ESTKL-2 @@ -762,15 +753,8 @@ def compiler(defptr)#0 dest = i + *(bytecode+i) i++ puts("BRFLS "); puti(dest) - VX++ //^codeptr = $E8; codeptr++ // INX - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + //VX++ //^codeptr = $E8; codeptr++ // INX + codeptr, VX = resolveX(codeptr, VX + 1) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0-1+VX; codeptr++ // ESTKL-1 @@ -792,15 +776,8 @@ def compiler(defptr)#0 dest = i + *(bytecode+i) i++ puts("BRTRU "); puti(dest) - VX++ //^codeptr = $E8; codeptr++ // INX - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + //VX++ //^codeptr = $E8; codeptr++ // INX + codeptr, VX = resolveX(codeptr, VX + 1) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0-1+VX; codeptr++ // ESTKL-1 @@ -847,15 +824,8 @@ def compiler(defptr)#0 fin ^codeptr = $B4; codeptr++ // LDY zp,X ^codeptr = $C0+VX; codeptr++ // ESTKH - VX++ //^codeptr = $E8; codeptr++ // INX - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + //VX++ //^codeptr = $E8; codeptr++ // INX + codeptr, VX = resolveX(codeptr, VX + 1) repeat puts(" $"); puth(*(bytecode+case)) ^codeptr = $C9; codeptr++ // CMP #imm @@ -932,15 +902,8 @@ def compiler(defptr)#0 ^codeptr = $C0+VX; codeptr++ // ESTKH ^codeptr = $85; codeptr++ // STA zp ^codeptr = $E8; codeptr++ // $E8:TMPH - VX++ //^codeptr = $E8; codeptr++ // INX - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + //VX++ //^codeptr = $E8; codeptr++ // INX + codeptr, VX = resolveX(codeptr, VX + 1) // // Call through TMP // @@ -1148,14 +1111,14 @@ def compiler(defptr)#0 is $6C i++ puts("DLB "); puti(^(bytecode+i)) - if ^(bytecode+i) <> 0 - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = ^(bytecode+i); codeptr++ - fin if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL fin + if ^(bytecode+i) <> 0 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = ^(bytecode+i); codeptr++ + fin ^codeptr = $91; codeptr++ // STA (zp),Y ^codeptr = $E0; codeptr++ // IFP // @@ -1170,14 +1133,14 @@ def compiler(defptr)#0 is $6E i++ puts("DLW "); puti(^(bytecode+i)) - if ^(bytecode+i) <> 0 - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = ^(bytecode+i); codeptr++ - fin if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL fin + if ^(bytecode+i) <> 0 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = ^(bytecode+i); codeptr++ + fin ^codeptr = $91; codeptr++ // STA (zp),Y ^codeptr = $E0; codeptr++ // IFP ^codeptr = $C8; codeptr++ // INY @@ -1244,14 +1207,14 @@ def compiler(defptr)#0 is $74 i++ puts("SLB "); puti(^(bytecode+i)) - if ^(bytecode+i) <> 0 - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = ^(bytecode+i); codeptr++ - fin if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL fin + if ^(bytecode+i) <> 0 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = ^(bytecode+i); codeptr++ + fin ^codeptr = $91; codeptr++ // STA (zp),Y ^codeptr = $E0; codeptr++ // IFP // @@ -1267,14 +1230,14 @@ def compiler(defptr)#0 is $76 i++ puts("SLW "); puti(^(bytecode+i)) - if ^(bytecode+i) <> 0 - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = ^(bytecode+i); codeptr++ - fin if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL fin + if ^(bytecode+i) <> 0 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = ^(bytecode+i); codeptr++ + fin ^codeptr = $91; codeptr++ // STA (zp),Y ^codeptr = $E0; codeptr++ // IFP ^codeptr = $C8; codeptr++ // INY @@ -1652,14 +1615,7 @@ def compiler(defptr)#0 dest = i + *(bytecode+i) puts("BRGT "); puti(dest) i++ - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) if A_IS_TOSL ^codeptr = $95; codeptr++ // STA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL @@ -1685,7 +1641,7 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 + codeptr = codeptr + 2 A_IS_TOSL = FALSE break is $A2 @@ -1693,14 +1649,7 @@ def compiler(defptr)#0 dest = i + *(bytecode+i) puts("BRLT "); puti(dest) i++ - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL @@ -1724,7 +1673,7 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 + codeptr = codeptr + 2 A_IS_TOSL = FALSE break is $A4 @@ -1748,14 +1697,7 @@ def compiler(defptr)#0 // // BRLE // - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+1+VX; codeptr++ // ESTKL+1 ^codeptr = $D5; codeptr++ // CMP zp,X @@ -1775,9 +1717,9 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 - ^codeptr = $E8; codeptr++ // INX - ^codeptr = $E8; codeptr++ // INX + codeptr = codeptr + 2 + ^codeptr = $E8; codeptr++ // INX + ^codeptr = $E8; codeptr++ // INX A_IS_TOSL = FALSE break is $A6 @@ -1803,18 +1745,11 @@ def compiler(defptr)#0 ^codeptr = $C0+1+VX; codeptr++ // ESTKH+1 ^codeptr = $95; codeptr++ // STA zp,X ^codeptr = $C0+1+VX; codeptr++ // ESTKH+1 - VX++ //^codeptr = $E8; codeptr++ // INX + //VX++ //^codeptr = $E8; codeptr++ // INX // // BRLE // - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX + 1) ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+1+VX; codeptr++ // ESTKL+1 ^codeptr = $D5; codeptr++ // CMP zp,X @@ -1834,9 +1769,9 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 - ^codeptr = $E8; codeptr++ // INX - ^codeptr = $E8; codeptr++ // INX + codeptr = codeptr + 2 + ^codeptr = $E8; codeptr++ // INX + ^codeptr = $E8; codeptr++ // INX A_IS_TOSL = FALSE break is $A8 @@ -1863,14 +1798,7 @@ def compiler(defptr)#0 // // BRGE // - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL ^codeptr = $D5; codeptr++ // CMP zp,X @@ -1890,9 +1818,9 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 - ^codeptr = $E8; codeptr++ // INX - ^codeptr = $E8; codeptr++ // INX + codeptr = codeptr + 2 + ^codeptr = $E8; codeptr++ // INX + ^codeptr = $E8; codeptr++ // INX A_IS_TOSL = FALSE break is $AA @@ -1920,18 +1848,11 @@ def compiler(defptr)#0 ^codeptr = $C0+VX; codeptr++ // ESTKH ^codeptr = $95; codeptr++ // STA zp,X ^codeptr = $C0+1+VX; codeptr++ // ESTKH+1 - VX++ //^codeptr = $E8; codeptr++ // INX + //VX++ //^codeptr = $E8; codeptr++ // INX // // BRGE // - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX + 1) ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL ^codeptr = $D5; codeptr++ // CMP zp,X @@ -1951,9 +1872,9 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 - ^codeptr = $E8; codeptr++ // INX - ^codeptr = $E8; codeptr++ // INX + codeptr = codeptr + 2 + ^codeptr = $E8; codeptr++ // INX + ^codeptr = $E8; codeptr++ // INX A_IS_TOSL = FALSE break is $AC @@ -1961,14 +1882,7 @@ def compiler(defptr)#0 dest = i + *(bytecode+i) i++ puts("BRAND "); puti(dest) - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL @@ -1982,8 +1896,8 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 - ^codeptr = $E8; codeptr++ // INX + codeptr = codeptr + 2 + ^codeptr = $E8; codeptr++ // INX A_IS_TOSL = FALSE break is $AE @@ -1991,14 +1905,7 @@ def compiler(defptr)#0 dest = i + *(bytecode+i) i++ puts("BROR "); puti(dest) - while VX > 0 - ^codeptr = $E8; codeptr++ // INX - VX-- - loop - while VX < 0 - ^codeptr = $CA; codeptr++ // DEX - VX++ - loop + codeptr, VX = resolveX(codeptr, VX) if not A_IS_TOSL ^codeptr = $B5; codeptr++ // LDA zp,X ^codeptr = $D0+VX; codeptr++ // ESTKL @@ -2012,8 +1919,8 @@ def compiler(defptr)#0 if not (*codeptr & $8000) // Unresolved address list addrxlate=>[dest] = codeptr - *jitcodeptr fin - codeptr = codeptr + 2 - ^codeptr = $E8; codeptr++ // INX + codeptr = codeptr + 2 + ^codeptr = $E8; codeptr++ // INX A_IS_TOSL = FALSE break // ADDLB,ADDLW,ADDAB,ADDAW,IDXLB,IDXLW,IDXAB,IDXAW ; B0 B2 B4 B6 B8 BA BC BE @@ -2154,8 +2061,8 @@ def compiler(defptr)#0 // // Reload zero into Y // - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = $00; codeptr++ // $00 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = $00; codeptr++ // $00 A_IS_TOSL = FALSE break is $BA @@ -2194,8 +2101,8 @@ def compiler(defptr)#0 // // Reload zero into Y // - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = $00; codeptr++ // $00 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = $00; codeptr++ // $00 A_IS_TOSL = FALSE break is $BC @@ -2224,8 +2131,8 @@ def compiler(defptr)#0 // // Reload zero into Y // - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = $00; codeptr++ // $00 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = $00; codeptr++ // $00 A_IS_TOSL = FALSE i++ break @@ -2260,8 +2167,8 @@ def compiler(defptr)#0 // // Reload zero into Y // - ^codeptr = $A0; codeptr++ // LDY #imm - ^codeptr = $00; codeptr++ // $00 + ^codeptr = $A0; codeptr++ // LDY #imm + ^codeptr = $00; codeptr++ // $00 A_IS_TOSL = FALSE i++ break diff --git a/src/vmsrc/apple/cmdjit.pla b/src/vmsrc/apple/cmdjit.pla index ac54e91..686a32f 100755 --- a/src/vmsrc/apple/cmdjit.pla +++ b/src/vmsrc/apple/cmdjit.pla @@ -150,13 +150,13 @@ word lastsym = symtbl // //asm equates included from cmdstub.s // -asm saveX#0 - STX XREG+1 -end -asm restoreX#0 -XREG LDX #$00 - RTS -end +//asm saveX#0 +// STX XREG+1 +//end +//asm restoreX#0 +//XREG LDX #$00 +// RTS +//end // CALL PRODOS // SYSCALL(CMD, PARAMS) // @@ -1512,12 +1512,12 @@ while 1 execsys(getlnbuf) break is '+' - saveX + //saveX execmod(striptrail(getlnbuf)) // // Clean up // - restoreX + //restoreX resetmemfiles break otherwise