From 0c4660d5fc694b9fc4855d29dce537ea76fb6103 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 5 Dec 2022 17:58:30 -0600 Subject: [PATCH] Generate better code for pc_mov in some cases. This allows it to use MVN-based copying code in more cases, including when moving to/from local variables on the stack. This is slightly shorter and more efficient than calling a helper function. --- CGI.Comments | 2 +- Gen.pas | 34 +++++++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/CGI.Comments b/CGI.Comments index 7f7e3ae..b38d76f 100644 --- a/CGI.Comments +++ b/CGI.Comments @@ -57,7 +57,7 @@ { Gen2(pc_mov, banks, bytes) } { } { The top of stack contains a source address, and TOS-1 has a } -{ destination address. The destination address is removed, } +{ destination address. The source address is removed, } { and BYTES bytes are moved from the source to the } { destination. BANKS is the number of full banks to move; it } { is used when 64K or more must be moved. The memory areas } diff --git a/Gen.pas b/Gen.pas index 376a61b..8265fc0 100644 --- a/Gen.pas +++ b/Gen.pas @@ -6501,7 +6501,7 @@ procedure GenTree {op: icptr}; begin {Load} if op^.opcode = pc_lao then GenNative(opcode, immediate, op^.q, op^.lab, 0) - else begin + else if op^.opcode = pc_lca then begin GenNative(opcode, immediate, stringsize, nil, StringReference); if maxstring-stringsize >= op^.q then begin for i := 1 to op^.q do @@ -6510,16 +6510,29 @@ procedure GenTree {op: icptr}; end {if} else Error(cge3); + end {else if} + else {if op^.opcode = pc_lda then} begin + GenImplied(m_tdc); + GenImplied(m_clc); + GenNative(m_adc_imm, immediate, LabelToDisp(op^.r) + op^.q, nil, 0); + if opcode = m_ldy_imm then + GenImplied(m_tay) + else + GenImplied(m_tax); end; {else} end; {Load} begin {GenMov} + banks := op^.r; {determine if the destination address must be left on the stack} - if smallMemoryModel + if (banks = 0) + and (op^.q <> 0) and (not duplicate) - and (op^.left^.opcode in [pc_lao,pc_lca]) - and (op^.right^.opcode in [pc_lao,pc_lca]) then begin + and ((op^.left^.opcode in [pc_lca,pc_lda]) + or ((op^.left^.opcode = pc_lao) and smallMemoryModel)) + and ((op^.right^.opcode in [pc_lca,pc_lda]) + or ((op^.right^.opcode = pc_lao) and smallMemoryModel)) then begin {take advantage of any available short cuts} Load(m_ldy_imm, op^.left); @@ -6530,13 +6543,17 @@ procedure GenTree {op: icptr}; with op^.left^ do if opcode = pc_lao then GenNative(d_bmov, immediate, q, lab, shift16) - else - GenNative(d_bmov, immediate, 0, nil, stringReference+shift16); + else if opcode = pc_lca then + GenNative(d_bmov, immediate, 0, nil, stringReference+shift16) + else {if opcode = pc_lda then} + GenNative(d_bmov, immediate, 0, nil, 0); with op^.right^ do if opcode = pc_lao then GenNative(d_bmov, immediate, q, lab, shift16) - else - GenNative(d_bmov, immediate, 0, nil, stringReference+shift16); + else if opcode = pc_lca then + GenNative(d_bmov, immediate, 0, nil, stringReference+shift16) + else {if opcode = pc_lda then} + GenNative(d_bmov, immediate, 0, nil, 0); GenImplied(m_plb); end {if} else begin @@ -6546,7 +6563,6 @@ procedure GenTree {op: icptr}; GenTree(op^.left); gLong.preference := onStack; GenTree(op^.right); - banks := op^.r; if banks <> 0 then GenNative(m_pea, immediate, banks, nil, 0); GenNative(m_pea, immediate, op^.q, nil, 0);