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.
This commit is contained in:
Stephen Heumann 2022-12-05 17:58:30 -06:00
parent 8e1db102eb
commit 0c4660d5fc
2 changed files with 26 additions and 10 deletions

View File

@ -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 }

34
Gen.pas
View File

@ -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);