2001-09-25 20:37:58 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* coptstop.c */
|
|
|
|
/* */
|
|
|
|
/* Optimize operations that take operands via the stack */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2009-08-19 13:36:26 +00:00
|
|
|
/* (C) 2001-2009 Ullrich von Bassewitz */
|
|
|
|
/* Roemerstrasse 52 */
|
2003-10-13 18:31:09 +00:00
|
|
|
/* D-70794 Filderstadt */
|
2001-09-25 20:37:58 +00:00
|
|
|
/* EMail: uz@cc65.org */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-01 19:40:01 +00:00
|
|
|
#include <stdlib.h>
|
2004-05-02 19:17:10 +00:00
|
|
|
|
|
|
|
/* common */
|
|
|
|
#include "chartype.h"
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2001-09-25 20:37:58 +00:00
|
|
|
/* cc65 */
|
|
|
|
#include "codeent.h"
|
|
|
|
#include "codeinfo.h"
|
|
|
|
#include "coptstop.h"
|
2009-09-11 16:36:17 +00:00
|
|
|
#include "error.h"
|
2001-09-25 20:37:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Load tracking data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* LoadRegInfo flags set by DirectOp */
|
2009-08-28 17:38:24 +00:00
|
|
|
typedef enum {
|
|
|
|
LI_NONE = 0x00,
|
|
|
|
LI_DIRECT = 0x01, /* Direct op may be used */
|
|
|
|
LI_RELOAD_Y = 0x02, /* Reload index register Y */
|
2009-09-11 16:36:17 +00:00
|
|
|
LI_REMOVE = 0x04, /* Load may be removed */
|
2010-01-20 19:47:44 +00:00
|
|
|
LI_DUP_LOAD = 0x08, /* Duplicate load */
|
2009-08-28 17:38:24 +00:00
|
|
|
} LI_FLAGS;
|
2009-08-27 22:07:28 +00:00
|
|
|
|
|
|
|
/* Structure that tells us how to load the lhs values */
|
|
|
|
typedef struct LoadRegInfo LoadRegInfo;
|
|
|
|
struct LoadRegInfo {
|
2009-09-01 20:57:39 +00:00
|
|
|
LI_FLAGS Flags; /* Tells us how to load */
|
2009-08-27 22:07:28 +00:00
|
|
|
int LoadIndex; /* Index of load insn, -1 if invalid */
|
|
|
|
CodeEntry* LoadEntry; /* The actual entry, 0 if invalid */
|
2009-09-01 20:57:39 +00:00
|
|
|
int XferIndex; /* Index of transfer insn */
|
|
|
|
CodeEntry* XferEntry; /* The actual transfer entry */
|
2009-09-11 16:36:17 +00:00
|
|
|
int Offs; /* Stack offset if data is on stack */
|
2009-08-27 22:07:28 +00:00
|
|
|
};
|
2009-09-03 11:58:11 +00:00
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Now combined for both registers */
|
|
|
|
typedef struct LoadInfo LoadInfo;
|
|
|
|
struct LoadInfo {
|
|
|
|
LoadRegInfo A; /* Info for A register */
|
|
|
|
LoadRegInfo X; /* Info for X register */
|
|
|
|
LoadRegInfo Y; /* Info for Y register */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-25 20:37:58 +00:00
|
|
|
/*****************************************************************************/
|
2002-10-04 19:27:15 +00:00
|
|
|
/* Data */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Flags for the functions */
|
|
|
|
typedef enum {
|
2009-08-27 22:07:28 +00:00
|
|
|
OP_NONE = 0x00, /* Nothing special */
|
|
|
|
OP_A_KNOWN = 0x01, /* Value of A must be known */
|
|
|
|
OP_X_ZERO = 0x02, /* X must be zero */
|
|
|
|
OP_LHS_LOAD = 0x04, /* Must have load insns for LHS */
|
2009-08-28 16:32:58 +00:00
|
|
|
OP_LHS_LOAD_DIRECT = 0x0C, /* Must have direct load insn for LHS */
|
|
|
|
OP_RHS_LOAD = 0x10, /* Must have load insns for RHS */
|
|
|
|
OP_RHS_LOAD_DIRECT = 0x30, /* Must have direct load insn for RHS */
|
2009-08-27 22:07:28 +00:00
|
|
|
} OP_FLAGS;
|
2009-08-17 12:52:50 +00:00
|
|
|
|
|
|
|
/* Structure forward decl */
|
2002-10-05 20:32:31 +00:00
|
|
|
typedef struct StackOpData StackOpData;
|
2009-08-17 12:52:50 +00:00
|
|
|
|
|
|
|
/* Structure that describes an optimizer subfunction for a specific op */
|
|
|
|
typedef unsigned (*OptFunc) (StackOpData* D);
|
|
|
|
typedef struct OptFuncDesc OptFuncDesc;
|
|
|
|
struct OptFuncDesc {
|
2009-08-19 13:36:26 +00:00
|
|
|
const char* Name; /* Name of the replaced runtime function */
|
|
|
|
OptFunc Func; /* Function pointer */
|
2009-08-20 16:06:20 +00:00
|
|
|
unsigned UnusedRegs; /* Regs that must not be used later */
|
2009-08-27 22:07:28 +00:00
|
|
|
OP_FLAGS Flags; /* Flags */
|
2009-08-17 12:52:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Structure that holds the needed data */
|
2002-10-05 20:32:31 +00:00
|
|
|
struct StackOpData {
|
2009-08-17 12:52:50 +00:00
|
|
|
CodeSeg* Code; /* Pointer to code segment */
|
|
|
|
unsigned Flags; /* Flags to remember things */
|
|
|
|
|
|
|
|
/* Pointer to optimizer subfunction description */
|
|
|
|
const OptFuncDesc* OptFunc;
|
|
|
|
|
|
|
|
/* ZP register usage inside the sequence */
|
|
|
|
unsigned UsedRegs;
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Register load information for lhs and rhs */
|
|
|
|
LoadInfo Lhs;
|
|
|
|
LoadInfo Rhs;
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* Several indices of insns in the code segment */
|
2009-08-17 12:52:50 +00:00
|
|
|
int PushIndex; /* Index of call to pushax in codeseg */
|
|
|
|
int OpIndex; /* Index of actual operation */
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* Pointers to insns in the code segment */
|
2009-08-17 12:52:50 +00:00
|
|
|
CodeEntry* PrevEntry; /* Entry before the call to pushax */
|
|
|
|
CodeEntry* PushEntry; /* Pointer to entry with call to pushax */
|
|
|
|
CodeEntry* OpEntry; /* Pointer to entry with op */
|
|
|
|
CodeEntry* NextEntry; /* Entry after the op */
|
2009-08-18 15:10:15 +00:00
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
const char* ZPLo; /* Lo byte of zero page loc to use */
|
|
|
|
const char* ZPHi; /* Hi byte of zero page loc to use */
|
|
|
|
unsigned IP; /* Insertion point used by some routines */
|
2002-10-05 20:32:31 +00:00
|
|
|
};
|
|
|
|
|
2002-10-04 19:27:15 +00:00
|
|
|
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* Load tracking code */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ClearLoadRegInfo (LoadRegInfo* RI)
|
|
|
|
/* Clear a LoadRegInfo struct */
|
|
|
|
{
|
2009-09-01 20:57:39 +00:00
|
|
|
RI->Flags = LI_NONE;
|
|
|
|
RI->LoadIndex = -1;
|
|
|
|
RI->XferIndex = -1;
|
2009-09-11 16:36:17 +00:00
|
|
|
RI->Offs = 0;
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void FinalizeLoadRegInfo (LoadRegInfo* RI, CodeSeg* S)
|
|
|
|
/* Prepare a LoadRegInfo struct for use */
|
|
|
|
{
|
2009-09-01 20:57:39 +00:00
|
|
|
/* Get the entries */
|
2009-08-27 22:07:28 +00:00
|
|
|
if (RI->LoadIndex >= 0) {
|
|
|
|
RI->LoadEntry = CS_GetEntry (S, RI->LoadIndex);
|
|
|
|
} else {
|
|
|
|
RI->LoadEntry = 0;
|
|
|
|
}
|
2009-09-01 20:57:39 +00:00
|
|
|
if (RI->XferIndex >= 0) {
|
|
|
|
RI->XferEntry = CS_GetEntry (S, RI->XferIndex);
|
|
|
|
} else {
|
|
|
|
RI->XferEntry = 0;
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void ClearLoadInfo (LoadInfo* LI)
|
|
|
|
/* Clear a LoadInfo struct */
|
|
|
|
{
|
|
|
|
ClearLoadRegInfo (&LI->A);
|
|
|
|
ClearLoadRegInfo (&LI->X);
|
|
|
|
ClearLoadRegInfo (&LI->Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
static void AdjustLoadRegInfo (LoadRegInfo* RI, int Index, int Change)
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Adjust a load register info struct after deleting or inserting an entry
|
|
|
|
* with a given index
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CHECK (abs (Change) == 1);
|
|
|
|
if (Change < 0) {
|
|
|
|
/* Deletion */
|
2009-09-01 20:57:39 +00:00
|
|
|
if (Index < RI->LoadIndex) {
|
2009-08-27 22:07:28 +00:00
|
|
|
--RI->LoadIndex;
|
2009-09-01 20:57:39 +00:00
|
|
|
} else if (Index == RI->LoadIndex) {
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Has been removed */
|
|
|
|
RI->LoadIndex = -1;
|
|
|
|
RI->LoadEntry = 0;
|
|
|
|
}
|
2009-09-01 20:57:39 +00:00
|
|
|
if (Index < RI->XferIndex) {
|
|
|
|
--RI->XferIndex;
|
|
|
|
} else if (Index == RI->XferIndex) {
|
|
|
|
/* Has been removed */
|
|
|
|
RI->XferIndex = -1;
|
|
|
|
RI->XferEntry = 0;
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
} else {
|
|
|
|
/* Insertion */
|
2009-09-01 20:57:39 +00:00
|
|
|
if (Index <= RI->LoadIndex) {
|
2009-08-27 22:07:28 +00:00
|
|
|
++RI->LoadIndex;
|
|
|
|
}
|
2009-09-01 20:57:39 +00:00
|
|
|
if (Index <= RI->XferIndex) {
|
|
|
|
++RI->XferIndex;
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void FinalizeLoadInfo (LoadInfo* LI, CodeSeg* S)
|
|
|
|
/* Prepare a LoadInfo struct for use */
|
|
|
|
{
|
|
|
|
/* Get the entries */
|
|
|
|
FinalizeLoadRegInfo (&LI->A, S);
|
|
|
|
FinalizeLoadRegInfo (&LI->X, S);
|
|
|
|
FinalizeLoadRegInfo (&LI->Y, S);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
static void AdjustLoadInfo (LoadInfo* LI, int Index, int Change)
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Adjust a load info struct after deleting entry with a given index */
|
|
|
|
{
|
2009-09-01 20:57:39 +00:00
|
|
|
AdjustLoadRegInfo (&LI->A, Index, Change);
|
|
|
|
AdjustLoadRegInfo (&LI->X, Index, Change);
|
|
|
|
AdjustLoadRegInfo (&LI->Y, Index, Change);
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void TrackLoads (LoadInfo* LI, CodeEntry* E, int I)
|
|
|
|
/* Track loads for a code entry */
|
|
|
|
{
|
|
|
|
if (E->Info & OF_LOAD) {
|
2009-09-11 16:36:17 +00:00
|
|
|
|
|
|
|
LoadRegInfo* RI = 0;
|
|
|
|
|
|
|
|
/* Determine, which register was loaded */
|
2009-08-27 22:07:28 +00:00
|
|
|
if (E->Chg & REG_A) {
|
2009-09-11 16:36:17 +00:00
|
|
|
RI = &LI->A;
|
|
|
|
} else if (E->Chg & REG_X) {
|
|
|
|
RI = &LI->X;
|
|
|
|
} else if (E->Chg & REG_Y) {
|
|
|
|
RI = &LI->Y;
|
2010-01-20 19:47:44 +00:00
|
|
|
}
|
2009-09-11 16:36:17 +00:00
|
|
|
CHECK (RI != 0);
|
|
|
|
|
2010-01-20 19:47:44 +00:00
|
|
|
/* If we had a load or xfer op before, this is a duplicate load which
|
|
|
|
* can cause problems if it encountered between the pushax and the op,
|
|
|
|
* so remember it.
|
|
|
|
*/
|
|
|
|
if (RI->LoadIndex >= 0 || RI->XferIndex >= 0) {
|
|
|
|
RI->Flags |= LI_DUP_LOAD;
|
|
|
|
}
|
|
|
|
|
2009-09-11 16:36:17 +00:00
|
|
|
/* Remember the load */
|
|
|
|
RI->LoadIndex = I;
|
|
|
|
RI->XferIndex = -1;
|
|
|
|
|
|
|
|
/* Set load flags */
|
|
|
|
RI->Flags &= ~(LI_DIRECT | LI_RELOAD_Y);
|
|
|
|
if (E->AM == AM65_IMM || E->AM == AM65_ZP || E->AM == AM65_ABS) {
|
|
|
|
/* These insns are all ok and replaceable */
|
|
|
|
RI->Flags |= LI_DIRECT;
|
|
|
|
} else if (E->AM == AM65_ZP_INDY &&
|
|
|
|
RegValIsKnown (E->RI->In.RegY) &&
|
|
|
|
strcmp (E->Arg, "sp") == 0) {
|
|
|
|
/* A load from the stack with known offset is also ok, but in this
|
|
|
|
* case we must reload the index register later. Please note that
|
|
|
|
* a load indirect via other zero page locations is not ok, since
|
|
|
|
* these locations may change between the push and the actual
|
|
|
|
* operation.
|
|
|
|
*/
|
|
|
|
RI->Offs = (unsigned char) E->RI->In.RegY;
|
|
|
|
RI->Flags |= (LI_DIRECT | LI_RELOAD_Y);
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
2009-09-11 16:36:17 +00:00
|
|
|
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
} else if (E->Info & OF_XFR) {
|
2009-09-11 16:36:17 +00:00
|
|
|
|
|
|
|
/* Determine source and target of the transfer and handle the TSX insn */
|
|
|
|
LoadRegInfo* Src;
|
|
|
|
LoadRegInfo* Tgt;
|
2009-08-27 22:07:28 +00:00
|
|
|
switch (E->OPC) {
|
2009-09-11 16:36:17 +00:00
|
|
|
case OP65_TAX: Src = &LI->A; Tgt = &LI->X; break;
|
|
|
|
case OP65_TAY: Src = &LI->A; Tgt = &LI->Y; break;
|
|
|
|
case OP65_TXA: Src = &LI->X; Tgt = &LI->A; break;
|
|
|
|
case OP65_TYA: Src = &LI->Y; Tgt = &LI->A; break;
|
|
|
|
case OP65_TSX: ClearLoadRegInfo (&LI->X); return;
|
|
|
|
case OP65_TXS: return;
|
|
|
|
default: Internal ("Unknown XFR insn in TrackLoads");
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
2009-09-11 16:36:17 +00:00
|
|
|
|
2010-01-20 19:47:44 +00:00
|
|
|
/* If we had a load or xfer op before, this is a duplicate load which
|
|
|
|
* can cause problems if it encountered between the pushax and the op,
|
|
|
|
* so remember it.
|
|
|
|
*/
|
|
|
|
if (Tgt->LoadIndex >= 0 || Tgt->XferIndex >= 0) {
|
|
|
|
Tgt->Flags |= LI_DUP_LOAD;
|
|
|
|
}
|
|
|
|
|
2009-09-11 16:36:17 +00:00
|
|
|
/* Transfer the data */
|
|
|
|
Tgt->LoadIndex = Src->LoadIndex;
|
|
|
|
Tgt->XferIndex = I;
|
|
|
|
Tgt->Offs = Src->Offs;
|
|
|
|
Tgt->Flags &= ~(LI_DIRECT | LI_RELOAD_Y);
|
|
|
|
Tgt->Flags |= Src->Flags & (LI_DIRECT | LI_RELOAD_Y);
|
|
|
|
|
|
|
|
} else if (CE_IsCallTo (E, "ldaxysp") && RegValIsKnown (E->RI->In.RegY)) {
|
|
|
|
|
2010-01-20 19:47:44 +00:00
|
|
|
/* If we had a load or xfer op before, this is a duplicate load which
|
|
|
|
* can cause problems if it encountered between the pushax and the op,
|
|
|
|
* so remember it for both registers involved.
|
|
|
|
*/
|
|
|
|
if (LI->A.LoadIndex >= 0 || LI->A.XferIndex >= 0) {
|
|
|
|
LI->A.Flags |= LI_DUP_LOAD;
|
|
|
|
}
|
|
|
|
if (LI->X.LoadIndex >= 0 || LI->X.XferIndex >= 0) {
|
|
|
|
LI->X.Flags |= LI_DUP_LOAD;
|
|
|
|
}
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Both registers set, Y changed */
|
|
|
|
LI->A.LoadIndex = I;
|
2009-09-01 20:57:39 +00:00
|
|
|
LI->A.XferIndex = -1;
|
2009-09-11 16:36:17 +00:00
|
|
|
LI->A.Flags |= (LI_DIRECT | LI_RELOAD_Y);
|
|
|
|
LI->A.Offs = (unsigned char) E->RI->In.RegY - 1;
|
|
|
|
|
2009-09-03 11:58:11 +00:00
|
|
|
LI->X.LoadIndex = I;
|
2009-09-01 20:57:39 +00:00
|
|
|
LI->X.XferIndex = -1;
|
2009-09-11 16:36:17 +00:00
|
|
|
LI->X.Flags |= (LI_DIRECT | LI_RELOAD_Y);
|
|
|
|
LI->X.Offs = (unsigned char) E->RI->In.RegY;
|
|
|
|
|
|
|
|
ClearLoadRegInfo (&LI->Y);
|
2009-08-27 22:07:28 +00:00
|
|
|
} else {
|
|
|
|
if (E->Chg & REG_A) {
|
2009-09-11 16:36:17 +00:00
|
|
|
ClearLoadRegInfo (&LI->A);
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
if (E->Chg & REG_X) {
|
2009-09-11 16:36:17 +00:00
|
|
|
ClearLoadRegInfo (&LI->X);
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
if (E->Chg & REG_Y) {
|
2009-09-11 16:36:17 +00:00
|
|
|
ClearLoadRegInfo (&LI->Y);
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-04 19:27:15 +00:00
|
|
|
/*****************************************************************************/
|
2009-09-04 19:54:29 +00:00
|
|
|
/* Helpers */
|
2001-09-25 20:37:58 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
static void InsertEntry (StackOpData* D, CodeEntry* E, int Index)
|
|
|
|
/* Insert a new entry. Depending on Index, D->PushIndex and D->OpIndex will
|
|
|
|
* be adjusted by this function.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* Insert the entry into the code segment */
|
|
|
|
CS_InsertEntry (D->Code, E, Index);
|
|
|
|
|
|
|
|
/* Adjust register loads if necessary */
|
|
|
|
AdjustLoadInfo (&D->Lhs, Index, 1);
|
|
|
|
AdjustLoadInfo (&D->Rhs, Index, 1);
|
|
|
|
|
|
|
|
/* Adjust the indices if necessary */
|
|
|
|
if (D->PushEntry && Index <= D->PushIndex) {
|
|
|
|
++D->PushIndex;
|
|
|
|
}
|
|
|
|
if (D->OpEntry && Index <= D->OpIndex) {
|
|
|
|
++D->OpIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void DelEntry (StackOpData* D, int Index)
|
|
|
|
/* Delete an entry. Depending on Index, D->PushIndex and D->OpIndex will be
|
|
|
|
* adjusted by this function, and PushEntry/OpEntry may get invalidated.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* Delete the entry from the code segment */
|
|
|
|
CS_DelEntry (D->Code, Index);
|
|
|
|
|
|
|
|
/* Adjust register loads if necessary */
|
|
|
|
AdjustLoadInfo (&D->Lhs, Index, -1);
|
|
|
|
AdjustLoadInfo (&D->Rhs, Index, -1);
|
|
|
|
|
|
|
|
/* Adjust the other indices if necessary */
|
|
|
|
if (Index < D->PushIndex) {
|
|
|
|
--D->PushIndex;
|
|
|
|
} else if (Index == D->PushIndex) {
|
|
|
|
D->PushEntry = 0;
|
|
|
|
}
|
|
|
|
if (Index < D->OpIndex) {
|
|
|
|
--D->OpIndex;
|
|
|
|
} else if (Index == D->OpIndex) {
|
|
|
|
D->OpEntry = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
static void AdjustStackOffset (StackOpData* D, unsigned Offs)
|
|
|
|
/* Adjust the offset for all stack accesses in the range PushIndex to OpIndex.
|
|
|
|
* OpIndex is adjusted according to the insertions.
|
2001-10-02 10:55:04 +00:00
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* Walk over all entries */
|
2009-08-17 12:52:50 +00:00
|
|
|
int I = D->PushIndex + 1;
|
|
|
|
while (I < D->OpIndex) {
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
CodeEntry* E = CS_GetEntry (D->Code, I);
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2002-10-06 19:03:12 +00:00
|
|
|
int NeedCorrection = 0;
|
|
|
|
if ((E->Use & REG_SP) != 0) {
|
2001-10-02 10:55:04 +00:00
|
|
|
|
|
|
|
/* Check for some things that should not happen */
|
|
|
|
CHECK (E->AM == AM65_ZP_INDY || E->RI->In.RegY >= (short) Offs);
|
|
|
|
CHECK (strcmp (E->Arg, "sp") == 0);
|
|
|
|
|
2002-10-06 19:03:12 +00:00
|
|
|
/* We need to correct this one */
|
|
|
|
NeedCorrection = 1;
|
|
|
|
|
2002-10-06 20:54:01 +00:00
|
|
|
} else if (CE_IsCallTo (E, "ldaxysp")) {
|
2002-10-06 19:03:12 +00:00
|
|
|
|
|
|
|
/* We need to correct this one */
|
|
|
|
NeedCorrection = 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NeedCorrection) {
|
|
|
|
|
2001-10-02 10:55:04 +00:00
|
|
|
/* Get the code entry before this one. If it's a LDY, adjust the
|
|
|
|
* value.
|
|
|
|
*/
|
2009-08-17 12:52:50 +00:00
|
|
|
CodeEntry* P = CS_GetPrevEntry (D->Code, I);
|
2005-09-11 12:52:12 +00:00
|
|
|
if (P && P->OPC == OP65_LDY && CE_IsConstImm (P)) {
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2009-08-29 11:31:06 +00:00
|
|
|
/* The Y load is just before the stack access, adjust it */
|
|
|
|
CE_SetNumArg (P, P->Num - Offs);
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2009-08-29 11:31:06 +00:00
|
|
|
} else {
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2009-08-29 11:31:06 +00:00
|
|
|
/* Insert a new load instruction before the stack access */
|
|
|
|
const char* Arg = MakeHexArg (E->RI->In.RegY - Offs);
|
|
|
|
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
2009-09-01 20:57:39 +00:00
|
|
|
InsertEntry (D, X, I++);
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2009-08-29 11:31:06 +00:00
|
|
|
}
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2003-10-13 18:31:09 +00:00
|
|
|
/* If we need the value of Y later, be sure to reload it */
|
2009-08-17 12:52:50 +00:00
|
|
|
if (RegYUsed (D->Code, I+1)) {
|
2009-08-29 11:31:06 +00:00
|
|
|
const char* Arg = MakeHexArg (E->RI->In.RegY);
|
|
|
|
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
2009-09-01 20:57:39 +00:00
|
|
|
InsertEntry (D, X, I+1);
|
2003-10-13 18:31:09 +00:00
|
|
|
|
2009-08-29 11:31:06 +00:00
|
|
|
/* Skip this instruction in the next round */
|
|
|
|
++I;
|
2003-10-13 18:31:09 +00:00
|
|
|
}
|
2009-08-29 11:31:06 +00:00
|
|
|
}
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2009-08-29 11:31:06 +00:00
|
|
|
/* Next entry */
|
|
|
|
++I;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have rhs load insns that load from stack, we'll have to adjust
|
|
|
|
* the offsets for these also.
|
|
|
|
*/
|
|
|
|
if (D->Rhs.A.Flags & LI_RELOAD_Y) {
|
|
|
|
D->Rhs.A.Offs -= Offs;
|
|
|
|
}
|
|
|
|
if (D->Rhs.X.Flags & LI_RELOAD_Y) {
|
|
|
|
D->Rhs.X.Offs -= Offs;
|
2001-10-02 10:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-28 17:38:24 +00:00
|
|
|
static void AddStoreA (StackOpData* D)
|
|
|
|
/* Add a store to zero page after the push insn */
|
|
|
|
{
|
|
|
|
CodeEntry* X = NewCodeEntry (OP65_STA, AM65_ZP, D->ZPLo, 0, D->PushEntry->LI);
|
|
|
|
InsertEntry (D, X, D->PushIndex+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void AddStoreX (StackOpData* D)
|
|
|
|
/* Add a store to zero page after the push insn */
|
|
|
|
{
|
|
|
|
CodeEntry* X = NewCodeEntry (OP65_STX, AM65_ZP, D->ZPHi, 0, D->PushEntry->LI);
|
|
|
|
InsertEntry (D, X, D->PushIndex+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static void ReplacePushByStore (StackOpData* D)
|
|
|
|
/* Replace the call to the push subroutine by a store into the zero page
|
|
|
|
* location (actually, the push is not replaced, because we need it for
|
|
|
|
* later, but the name is still ok since the push will get removed at the
|
2002-11-25 15:05:15 +00:00
|
|
|
* end of each routine).
|
2002-10-05 20:32:31 +00:00
|
|
|
*/
|
|
|
|
{
|
2009-08-18 15:10:15 +00:00
|
|
|
/* Store the value into the zeropage instead of pushing it. Check high
|
|
|
|
* byte first so that the store is later in A/X order.
|
|
|
|
*/
|
2009-08-27 22:07:28 +00:00
|
|
|
if ((D->Lhs.X.Flags & LI_DIRECT) == 0) {
|
2009-08-28 17:38:24 +00:00
|
|
|
AddStoreX (D);
|
2009-08-18 15:10:15 +00:00
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
if ((D->Lhs.A.Flags & LI_DIRECT) == 0) {
|
2009-08-28 17:38:24 +00:00
|
|
|
AddStoreA (D);
|
2002-10-05 20:32:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-31 18:02:44 +00:00
|
|
|
static void AddOpLow (StackOpData* D, opc_t OPC, LoadInfo* LI)
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Add an op for the low byte of an operator. This function honours the
|
2002-11-25 15:05:15 +00:00
|
|
|
* OP_DIRECT and OP_RELOAD_Y flags and generates the necessary instructions.
|
2002-10-05 20:32:31 +00:00
|
|
|
* All code is inserted at the current insertion point.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
2009-08-31 18:02:44 +00:00
|
|
|
if ((LI->A.Flags & LI_DIRECT) != 0) {
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Op with a variable location. If the location is on the stack, we
|
|
|
|
* need to reload the Y register.
|
|
|
|
*/
|
2009-08-31 18:02:44 +00:00
|
|
|
if ((LI->A.Flags & LI_RELOAD_Y) == 0) {
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* opc ... */
|
2009-08-31 18:02:44 +00:00
|
|
|
CodeEntry* LoadA = LI->A.LoadEntry;
|
2009-08-19 13:36:26 +00:00
|
|
|
X = NewCodeEntry (OPC, LoadA->AM, LoadA->Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* ldy #offs */
|
2009-08-31 18:02:44 +00:00
|
|
|
const char* Arg = MakeHexArg (LI->A.Offs);
|
2002-10-05 20:32:31 +00:00
|
|
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* opc (sp),y */
|
|
|
|
X = NewCodeEntry (OPC, AM65_ZP_INDY, "sp", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2002-10-04 19:27:15 +00:00
|
|
|
}
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* In both cases, we can remove the load */
|
2009-08-31 18:02:44 +00:00
|
|
|
LI->A.Flags |= LI_REMOVE;
|
2009-08-19 13:36:26 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
} else {
|
2009-08-19 13:36:26 +00:00
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* Op with temp storage */
|
|
|
|
X = NewCodeEntry (OPC, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
|
2009-08-19 13:36:26 +00:00
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2002-10-04 19:27:15 +00:00
|
|
|
}
|
2002-10-05 20:32:31 +00:00
|
|
|
}
|
|
|
|
|
2004-03-15 22:03:50 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
static void AddOpHigh (StackOpData* D, opc_t OPC, LoadInfo* LI, int KeepResult)
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Add an op for the high byte of an operator. Special cases (constant values
|
2004-03-15 22:03:50 +00:00
|
|
|
* or similar) have to be checked separately, the function covers only the
|
2002-10-05 20:32:31 +00:00
|
|
|
* generic case. Code is inserted at the insertion point.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
if (KeepResult) {
|
|
|
|
/* pha */
|
|
|
|
X = NewCodeEntry (OP65_PHA, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
}
|
2009-08-18 15:10:15 +00:00
|
|
|
|
|
|
|
/* txa */
|
2002-10-05 20:32:31 +00:00
|
|
|
X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-18 15:10:15 +00:00
|
|
|
|
2009-08-31 18:02:44 +00:00
|
|
|
if ((LI->X.Flags & LI_DIRECT) != 0) {
|
2009-08-19 13:36:26 +00:00
|
|
|
|
2009-08-31 18:02:44 +00:00
|
|
|
if ((LI->X.Flags & LI_RELOAD_Y) == 0) {
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* opc xxx */
|
2009-08-31 18:02:44 +00:00
|
|
|
CodeEntry* LoadX = LI->X.LoadEntry;
|
2009-08-31 18:18:50 +00:00
|
|
|
X = NewCodeEntry (OPC, LoadX->AM, LoadX->Arg, 0, D->OpEntry->LI);
|
2009-08-19 13:36:26 +00:00
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* ldy #const */
|
2009-08-31 18:02:44 +00:00
|
|
|
const char* Arg = MakeHexArg (LI->X.Offs);
|
2009-08-18 15:10:15 +00:00
|
|
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* opc (sp),y */
|
|
|
|
X = NewCodeEntry (OPC, AM65_ZP_INDY, "sp", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-18 15:10:15 +00:00
|
|
|
}
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* In both cases, we can remove the load */
|
2009-08-31 18:02:44 +00:00
|
|
|
LI->X.Flags |= LI_REMOVE;
|
2009-08-19 13:36:26 +00:00
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
/* opc zphi */
|
|
|
|
X = NewCodeEntry (OPC, AM65_ZP, D->ZPHi, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
}
|
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
if (KeepResult) {
|
|
|
|
/* tax */
|
|
|
|
X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-18 15:10:15 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* pla */
|
|
|
|
X = NewCodeEntry (OP65_PLA, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
}
|
|
|
|
}
|
2002-10-05 20:32:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
static void RemoveRegLoads (StackOpData* D, LoadInfo* LI)
|
|
|
|
/* Remove register load insns */
|
|
|
|
{
|
|
|
|
/* Both registers may be loaded with one insn, but DelEntry will in this
|
|
|
|
* case clear the other one.
|
2009-08-31 19:36:06 +00:00
|
|
|
*/
|
2009-09-01 20:57:39 +00:00
|
|
|
if (LI->A.Flags & LI_REMOVE) {
|
|
|
|
if (LI->A.LoadIndex >= 0) {
|
|
|
|
DelEntry (D, LI->A.LoadIndex);
|
|
|
|
}
|
|
|
|
if (LI->A.XferIndex >= 0) {
|
|
|
|
DelEntry (D, LI->A.XferIndex);
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
2009-09-01 20:57:39 +00:00
|
|
|
if (LI->X.Flags & LI_REMOVE) {
|
|
|
|
if (LI->X.LoadIndex >= 0) {
|
|
|
|
DelEntry (D, LI->X.LoadIndex);
|
|
|
|
}
|
|
|
|
if (LI->X.XferIndex >= 0) {
|
|
|
|
DelEntry (D, LI->X.XferIndex);
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-19 13:36:26 +00:00
|
|
|
static void RemoveRemainders (StackOpData* D)
|
|
|
|
/* Remove the code that is unnecessary after translation of the sequence */
|
2002-10-05 20:32:31 +00:00
|
|
|
{
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Remove the register loads for lhs and rhs */
|
|
|
|
RemoveRegLoads (D, &D->Lhs);
|
|
|
|
RemoveRegLoads (D, &D->Rhs);
|
|
|
|
|
2009-08-19 13:36:26 +00:00
|
|
|
/* Remove the push and the operator routine */
|
2002-10-05 20:32:31 +00:00
|
|
|
DelEntry (D, D->OpIndex);
|
|
|
|
DelEntry (D, D->PushIndex);
|
2002-10-04 19:27:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-15 22:03:50 +00:00
|
|
|
static int IsRegVar (StackOpData* D)
|
2009-08-18 15:10:15 +00:00
|
|
|
/* If the value pushed is that of a zeropage variable, replace ZPLo and ZPHi
|
|
|
|
* in the given StackOpData struct by the variable and return true. Otherwise
|
|
|
|
* leave D untouched and return false.
|
2002-11-25 15:05:15 +00:00
|
|
|
*/
|
|
|
|
{
|
2009-08-27 22:07:28 +00:00
|
|
|
CodeEntry* LoadA = D->Lhs.A.LoadEntry;
|
|
|
|
CodeEntry* LoadX = D->Lhs.X.LoadEntry;
|
2009-08-18 15:10:15 +00:00
|
|
|
unsigned Len;
|
|
|
|
|
|
|
|
/* Must have both load insns */
|
|
|
|
if (LoadA == 0 || LoadX == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be loads from zp */
|
|
|
|
if (LoadA->AM != AM65_ZP || LoadX->AM != AM65_ZP) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be the same zp loc with high byte in X */
|
|
|
|
Len = strlen (LoadA->Arg);
|
|
|
|
if (strncmp (LoadA->Arg, LoadX->Arg, Len) != 0 ||
|
|
|
|
strcmp (LoadX->Arg + Len, "+1") != 0) {
|
2002-11-25 15:05:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-08-18 15:10:15 +00:00
|
|
|
|
|
|
|
/* Use the zero page location directly */
|
|
|
|
D->ZPLo = LoadA->Arg;
|
|
|
|
D->ZPHi = LoadX->Arg;
|
|
|
|
return 1;
|
2002-11-25 15:05:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-02 10:55:04 +00:00
|
|
|
/*****************************************************************************/
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Actual optimization functions */
|
2001-10-02 10:55:04 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-28 19:34:35 +00:00
|
|
|
static unsigned Opt_toseqax_tosneax (StackOpData* D, const char* BoolTransformer)
|
|
|
|
/* Optimize the toseqax and tosneax sequences. */
|
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
CodeLabel* L;
|
|
|
|
|
|
|
|
/* Create a call to the boolean transformer function and a label for this
|
|
|
|
* insn. This is needed for all variants. Other insns are inserted *before*
|
|
|
|
* the call.
|
|
|
|
*/
|
|
|
|
X = NewCodeEntry (OP65_JSR, AM65_ABS, BoolTransformer, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex + 1);
|
|
|
|
L = CS_GenLabel (D->Code, X);
|
|
|
|
|
|
|
|
/* If the lhs is direct (but not stack relative), encode compares with lhs
|
|
|
|
* effectively reverting the order (which doesn't matter for ==).
|
|
|
|
*/
|
|
|
|
if ((D->Lhs.A.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT &&
|
|
|
|
(D->Lhs.X.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT) {
|
|
|
|
|
|
|
|
CodeEntry* LoadX = D->Lhs.X.LoadEntry;
|
|
|
|
CodeEntry* LoadA = D->Lhs.A.LoadEntry;
|
|
|
|
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* cpx */
|
|
|
|
X = NewCodeEntry (OP65_CPX, LoadX->AM, LoadX->Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* bne L */
|
|
|
|
X = NewCodeEntry (OP65_BNE, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* cmp */
|
|
|
|
X = NewCodeEntry (OP65_CMP, LoadA->AM, LoadA->Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Lhs load entries can be removed */
|
|
|
|
D->Lhs.X.Flags |= LI_REMOVE;
|
|
|
|
D->Lhs.A.Flags |= LI_REMOVE;
|
|
|
|
|
|
|
|
} else if ((D->Rhs.A.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT &&
|
|
|
|
(D->Rhs.X.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT) {
|
|
|
|
|
|
|
|
CodeEntry* LoadX = D->Rhs.X.LoadEntry;
|
|
|
|
CodeEntry* LoadA = D->Rhs.A.LoadEntry;
|
|
|
|
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* cpx */
|
|
|
|
X = NewCodeEntry (OP65_CPX, LoadX->AM, LoadX->Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* bne L */
|
|
|
|
X = NewCodeEntry (OP65_BNE, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* cmp */
|
|
|
|
X = NewCodeEntry (OP65_CMP, LoadA->AM, LoadA->Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Rhs load entries can be removed */
|
|
|
|
D->Rhs.X.Flags |= LI_REMOVE;
|
|
|
|
D->Rhs.A.Flags |= LI_REMOVE;
|
|
|
|
|
|
|
|
} else if ((D->Rhs.A.Flags & LI_DIRECT) != 0 &&
|
|
|
|
(D->Rhs.X.Flags & LI_DIRECT) != 0) {
|
|
|
|
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add operand for low byte */
|
|
|
|
AddOpLow (D, OP65_CMP, &D->Rhs);
|
2009-08-28 19:34:35 +00:00
|
|
|
|
|
|
|
/* bne L */
|
|
|
|
X = NewCodeEntry (OP65_BNE, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-31 19:36:06 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add operand for high byte */
|
|
|
|
AddOpHigh (D, OP65_CMP, &D->Rhs, 0);
|
2009-08-28 19:34:35 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Save lhs into zeropage, then compare */
|
|
|
|
AddStoreX (D);
|
|
|
|
AddStoreA (D);
|
|
|
|
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* cpx */
|
|
|
|
X = NewCodeEntry (OP65_CPX, AM65_ZP, D->ZPHi, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* bne L */
|
|
|
|
X = NewCodeEntry (OP65_BNE, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* cmp */
|
|
|
|
X = NewCodeEntry (OP65_CMP, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the push and the call to the tosgeax function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-03-15 22:03:50 +00:00
|
|
|
static unsigned Opt___bzero (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the __bzero sequence */
|
2004-03-15 22:03:50 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
const char* Arg;
|
|
|
|
CodeLabel* L;
|
|
|
|
|
|
|
|
/* Check if we're using a register variable */
|
|
|
|
if (!IsRegVar (D)) {
|
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2009-08-28 17:38:24 +00:00
|
|
|
AddStoreX (D);
|
|
|
|
AddStoreA (D);
|
2004-03-15 22:03:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the return value of __bzero is used, we have to add code to reload
|
|
|
|
* a/x from the pointer variable.
|
|
|
|
*/
|
|
|
|
if (RegAXUsed (D->Code, D->OpIndex+1)) {
|
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+1);
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_ZP, D->ZPHi, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* X is always zero, A contains the size of the data area to zero.
|
|
|
|
* Note: A may be zero, in which case the operation is null op.
|
|
|
|
*/
|
|
|
|
if (D->OpEntry->RI->In.RegA != 0) {
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* lda #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+1);
|
|
|
|
|
2004-03-15 22:03:50 +00:00
|
|
|
/* The value of A is known */
|
|
|
|
if (D->OpEntry->RI->In.RegA <= 0x81) {
|
|
|
|
|
|
|
|
/* Loop using the sign bit */
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* ldy #count-1 */
|
2004-03-15 22:03:50 +00:00
|
|
|
Arg = MakeHexArg (D->OpEntry->RI->In.RegA - 1);
|
|
|
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+2);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* L: sta (zp),y */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, D->ZPLo, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+3);
|
|
|
|
L = CS_GenLabel (D->Code, X);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* dey */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+4);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* bpl L */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_BPL, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+5);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* Loop using an explicit compare */
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* ldy #$00 */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+2);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* L: sta (zp),y */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, D->ZPLo, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+3);
|
|
|
|
L = CS_GenLabel (D->Code, X);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* iny */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_INY, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+4);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* cpy #count */
|
2004-03-15 22:03:50 +00:00
|
|
|
Arg = MakeHexArg (D->OpEntry->RI->In.RegA);
|
|
|
|
X = NewCodeEntry (OP65_CPY, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+5);
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
/* bne L */
|
|
|
|
X = NewCodeEntry (OP65_BNE, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
2004-03-15 22:03:50 +00:00
|
|
|
InsertEntry (D, X, D->OpIndex+6);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the push and the call to the __bzero function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2004-03-15 22:03:50 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static unsigned Opt_staspidx (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the staspidx sequence */
|
2001-10-01 19:40:01 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
2002-11-25 15:05:15 +00:00
|
|
|
/* Check if we're using a register variable */
|
2004-03-15 22:03:50 +00:00
|
|
|
if (!IsRegVar (D)) {
|
2002-11-25 15:05:15 +00:00
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2009-08-28 17:38:24 +00:00
|
|
|
AddStoreX (D);
|
|
|
|
AddStoreA (D);
|
2002-11-25 15:05:15 +00:00
|
|
|
}
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Replace the store subroutine call by a direct op */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, D->ZPLo, 0, D->OpEntry->LI);
|
2002-10-05 20:32:31 +00:00
|
|
|
InsertEntry (D, X, D->OpIndex+1);
|
2001-10-01 19:40:01 +00:00
|
|
|
|
|
|
|
/* Remove the push and the call to the staspidx function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2001-10-01 19:40:01 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static unsigned Opt_staxspidx (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the staxspidx sequence */
|
2002-02-13 11:42:56 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
2002-11-25 15:05:15 +00:00
|
|
|
/* Check if we're using a register variable */
|
2004-03-15 22:03:50 +00:00
|
|
|
if (!IsRegVar (D)) {
|
2002-11-25 15:05:15 +00:00
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2009-08-28 17:38:24 +00:00
|
|
|
AddStoreX (D);
|
|
|
|
AddStoreA (D);
|
2002-11-25 15:05:15 +00:00
|
|
|
}
|
2002-02-13 11:42:56 +00:00
|
|
|
|
|
|
|
/* Inline the store */
|
2009-08-18 15:10:15 +00:00
|
|
|
|
|
|
|
/* sta (zp),y */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, D->ZPLo, 0, D->OpEntry->LI);
|
2002-10-05 20:32:31 +00:00
|
|
|
InsertEntry (D, X, D->OpIndex+1);
|
2009-08-18 15:10:15 +00:00
|
|
|
|
2004-06-05 16:18:30 +00:00
|
|
|
if (RegValIsKnown (D->OpEntry->RI->In.RegY)) {
|
|
|
|
/* Value of Y is known */
|
2009-08-18 15:10:15 +00:00
|
|
|
const char* Arg = MakeHexArg (D->OpEntry->RI->In.RegY + 1);
|
2004-06-05 16:18:30 +00:00
|
|
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
} else {
|
|
|
|
X = NewCodeEntry (OP65_INY, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
}
|
2002-10-05 20:32:31 +00:00
|
|
|
InsertEntry (D, X, D->OpIndex+2);
|
2009-08-18 15:10:15 +00:00
|
|
|
|
2002-10-17 21:37:01 +00:00
|
|
|
if (RegValIsKnown (D->OpEntry->RI->In.RegX)) {
|
2009-08-18 15:10:15 +00:00
|
|
|
/* Value of X is known */
|
|
|
|
const char* Arg = MakeHexArg (D->OpEntry->RI->In.RegX);
|
2002-10-05 20:32:31 +00:00
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
2002-02-13 11:42:56 +00:00
|
|
|
} else {
|
2009-08-18 15:10:15 +00:00
|
|
|
/* Value unknown */
|
|
|
|
X = NewCodeEntry (OP65_TXA, AM65_IMP, 0, 0, D->OpEntry->LI);
|
2002-02-13 11:42:56 +00:00
|
|
|
}
|
2002-10-05 20:32:31 +00:00
|
|
|
InsertEntry (D, X, D->OpIndex+3);
|
2009-08-18 15:10:15 +00:00
|
|
|
|
|
|
|
/* sta (zp),y */
|
2004-03-15 22:03:50 +00:00
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, D->ZPLo, 0, D->OpEntry->LI);
|
2002-10-05 20:32:31 +00:00
|
|
|
InsertEntry (D, X, D->OpIndex+4);
|
2002-02-13 11:42:56 +00:00
|
|
|
|
2009-08-20 16:06:20 +00:00
|
|
|
/* If we remove staxspidx, we must restore the Y register to what the
|
2009-08-18 15:10:15 +00:00
|
|
|
* function would return.
|
|
|
|
*/
|
|
|
|
X = NewCodeEntry (OP65_LDY, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex+5);
|
|
|
|
|
2006-04-16 20:32:09 +00:00
|
|
|
/* Remove the push and the call to the staxspidx function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2002-02-13 11:42:56 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static unsigned Opt_tosaddax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosaddax sequence */
|
2001-09-25 20:37:58 +00:00
|
|
|
{
|
2002-10-04 19:27:15 +00:00
|
|
|
CodeEntry* X;
|
2005-09-11 12:52:12 +00:00
|
|
|
CodeEntry* N;
|
2001-09-25 20:37:58 +00:00
|
|
|
|
|
|
|
/* We need the entry behind the add */
|
2002-10-05 20:32:31 +00:00
|
|
|
CHECK (D->NextEntry != 0);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2005-09-11 12:52:12 +00:00
|
|
|
/* Check if the X register is known and zero when the add is done, and
|
|
|
|
* if the add is followed by
|
|
|
|
*
|
|
|
|
* ldy #$00
|
|
|
|
* jsr ldauidx ; or ldaidx
|
|
|
|
*
|
|
|
|
* If this is true, the addition does actually add an offset to a pointer
|
|
|
|
* before it is dereferenced. Since both subroutines take an offset in Y,
|
|
|
|
* we can pass the offset (instead of #$00) and remove the addition
|
|
|
|
* alltogether.
|
2001-10-04 11:34:18 +00:00
|
|
|
*/
|
2005-09-11 12:52:12 +00:00
|
|
|
if (D->OpEntry->RI->In.RegX == 0 &&
|
|
|
|
D->NextEntry->OPC == OP65_LDY &&
|
|
|
|
CE_IsKnownImm (D->NextEntry, 0) &&
|
|
|
|
!CE_HasLabel (D->NextEntry) &&
|
|
|
|
(N = CS_GetNextEntry (D->Code, D->OpIndex + 1)) != 0 &&
|
|
|
|
(CE_IsCallTo (N, "ldauidx") ||
|
|
|
|
CE_IsCallTo (N, "ldaidx"))) {
|
2001-10-04 11:34:18 +00:00
|
|
|
|
2005-09-11 12:52:12 +00:00
|
|
|
int Signed = (strcmp (N->Arg, "ldaidx") == 0);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2005-09-11 12:52:12 +00:00
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2009-08-28 17:38:24 +00:00
|
|
|
AddStoreX (D);
|
|
|
|
AddStoreA (D);
|
2005-09-11 12:52:12 +00:00
|
|
|
|
|
|
|
/* Replace the ldy by a tay. Be sure to create the new entry before
|
|
|
|
* deleting the ldy, since we will reference the line info from this
|
|
|
|
* insn.
|
|
|
|
*/
|
|
|
|
X = NewCodeEntry (OP65_TAY, AM65_IMP, 0, 0, D->NextEntry->LI);
|
|
|
|
DelEntry (D, D->OpIndex + 1);
|
|
|
|
InsertEntry (D, X, D->OpIndex + 1);
|
|
|
|
|
|
|
|
/* Replace the call to ldaidx/ldauidx. Since X is already zero, and
|
|
|
|
* the ptr is in the zero page location, we just need to load from
|
|
|
|
* the pointer, and fix X in case of ldaidx.
|
|
|
|
*/
|
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, D->ZPLo, 0, N->LI);
|
|
|
|
DelEntry (D, D->OpIndex + 2);
|
|
|
|
InsertEntry (D, X, D->OpIndex + 2);
|
|
|
|
if (Signed) {
|
|
|
|
|
|
|
|
CodeLabel* L;
|
|
|
|
|
|
|
|
/* Add sign extension - N is unused now */
|
|
|
|
N = CS_GetNextEntry (D->Code, D->OpIndex + 2);
|
|
|
|
CHECK (N != 0);
|
|
|
|
L = CS_GenLabel (D->Code, N);
|
|
|
|
|
|
|
|
X = NewCodeEntry (OP65_BPL, AM65_BRA, L->Name, L, X->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex + 3);
|
|
|
|
|
|
|
|
X = NewCodeEntry (OP65_DEX, AM65_IMP, 0, 0, X->LI);
|
|
|
|
InsertEntry (D, X, D->OpIndex + 4);
|
|
|
|
}
|
2002-10-05 20:32:31 +00:00
|
|
|
|
2001-09-25 20:37:58 +00:00
|
|
|
} else {
|
2005-09-11 12:52:12 +00:00
|
|
|
|
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
|
|
|
ReplacePushByStore (D);
|
|
|
|
|
|
|
|
/* Inline the add */
|
|
|
|
D->IP = D->OpIndex+1;
|
2009-08-18 15:10:15 +00:00
|
|
|
|
|
|
|
/* clc */
|
2005-09-11 12:52:12 +00:00
|
|
|
X = NewCodeEntry (OP65_CLC, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Low byte */
|
2009-08-31 18:02:44 +00:00
|
|
|
AddOpLow (D, OP65_ADC, &D->Lhs);
|
2005-09-11 12:52:12 +00:00
|
|
|
|
|
|
|
/* High byte */
|
|
|
|
if (D->PushEntry->RI->In.RegX == 0) {
|
2009-08-31 19:36:06 +00:00
|
|
|
|
2005-09-11 12:52:12 +00:00
|
|
|
/* The high byte is the value in X plus the carry */
|
|
|
|
CodeLabel* L = CS_GenLabel (D->Code, D->NextEntry);
|
2009-08-31 18:02:44 +00:00
|
|
|
|
|
|
|
/* bcc L */
|
2005-09-11 12:52:12 +00:00
|
|
|
X = NewCodeEntry (OP65_BCC, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-31 18:02:44 +00:00
|
|
|
|
|
|
|
/* inx */
|
2005-09-11 12:52:12 +00:00
|
|
|
X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-31 18:02:44 +00:00
|
|
|
|
2009-08-31 19:36:06 +00:00
|
|
|
} else if (D->OpEntry->RI->In.RegX == 0 &&
|
|
|
|
(RegValIsKnown (D->PushEntry->RI->In.RegX) ||
|
|
|
|
(D->Lhs.X.Flags & LI_RELOAD_Y) == 0)) {
|
2009-08-31 18:02:44 +00:00
|
|
|
|
2005-09-11 12:52:12 +00:00
|
|
|
/* The high byte is that of the first operand plus carry */
|
|
|
|
CodeLabel* L;
|
|
|
|
if (RegValIsKnown (D->PushEntry->RI->In.RegX)) {
|
|
|
|
/* Value of first op high byte is known */
|
|
|
|
const char* Arg = MakeHexArg (D->PushEntry->RI->In.RegX);
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
} else {
|
2009-08-31 19:36:06 +00:00
|
|
|
/* Value of first op high byte is unknown. Load from ZP or
|
|
|
|
* original storage.
|
|
|
|
*/
|
|
|
|
if (D->Lhs.X.Flags & LI_DIRECT) {
|
|
|
|
CodeEntry* LoadX = D->Lhs.X.LoadEntry;
|
|
|
|
X = NewCodeEntry (OP65_LDX, LoadX->AM, LoadX->Arg, 0, D->OpEntry->LI);
|
|
|
|
} else {
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_ZP, D->ZPHi, 0, D->OpEntry->LI);
|
|
|
|
}
|
2005-09-11 12:52:12 +00:00
|
|
|
}
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* bcc label */
|
2005-09-11 12:52:12 +00:00
|
|
|
L = CS_GenLabel (D->Code, D->NextEntry);
|
|
|
|
X = NewCodeEntry (OP65_BCC, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-08-19 13:36:26 +00:00
|
|
|
|
|
|
|
/* inx */
|
2005-09-11 12:52:12 +00:00
|
|
|
X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
} else {
|
|
|
|
/* High byte is unknown */
|
2009-08-31 18:18:50 +00:00
|
|
|
AddOpHigh (D, OP65_ADC, &D->Lhs, 1);
|
2005-09-11 12:52:12 +00:00
|
|
|
}
|
2001-09-25 20:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the push and the call to the tosaddax function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static unsigned Opt_tosandax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosandax sequence */
|
2001-09-25 20:37:58 +00:00
|
|
|
{
|
2001-10-01 19:40:01 +00:00
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2002-10-05 20:32:31 +00:00
|
|
|
ReplacePushByStore (D);
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Inline the and, low byte */
|
|
|
|
D->IP = D->OpIndex + 1;
|
2009-08-31 18:02:44 +00:00
|
|
|
AddOpLow (D, OP65_AND, &D->Lhs);
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* High byte */
|
2009-08-31 19:36:06 +00:00
|
|
|
AddOpHigh (D, OP65_AND, &D->Lhs, 1);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2001-10-01 19:40:01 +00:00
|
|
|
/* Remove the push and the call to the tosandax function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2001-10-01 19:40:01 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-28 19:34:35 +00:00
|
|
|
static unsigned Opt_toseqax (StackOpData* D)
|
|
|
|
/* Optimize the toseqax sequence */
|
|
|
|
{
|
|
|
|
return Opt_toseqax_tosneax (D, "booleq");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-28 16:32:58 +00:00
|
|
|
static unsigned Opt_tosgeax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosgeax sequence */
|
2009-08-28 16:32:58 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
CodeLabel* L;
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
2009-08-31 18:18:50 +00:00
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for low operand */
|
|
|
|
AddOpLow (D, OP65_CMP, &D->Rhs);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 0);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
|
|
|
/* eor #$80 */
|
|
|
|
X = NewCodeEntry (OP65_EOR, AM65_IMM, "$80", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* asl a */
|
|
|
|
X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
L = CS_GenLabel (D->Code, X);
|
|
|
|
|
|
|
|
/* Insert a bvs L before the eor insn */
|
|
|
|
X = NewCodeEntry (OP65_BVS, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP - 2);
|
|
|
|
++D->IP;
|
|
|
|
|
|
|
|
/* lda #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* ldx #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* rol a */
|
|
|
|
X = NewCodeEntry (OP65_ROL, AM65_ACC, "a", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Remove the push and the call to the tosgeax function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned Opt_tosltax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosltax sequence */
|
2009-08-28 16:32:58 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
CodeLabel* L;
|
|
|
|
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
2009-08-31 18:18:50 +00:00
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for low operand */
|
|
|
|
AddOpLow (D, OP65_CMP, &D->Rhs);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 0);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
|
|
|
/* eor #$80 */
|
|
|
|
X = NewCodeEntry (OP65_EOR, AM65_IMM, "$80", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* asl a */
|
|
|
|
X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
L = CS_GenLabel (D->Code, X);
|
|
|
|
|
|
|
|
/* Insert a bvc L before the eor insn */
|
|
|
|
X = NewCodeEntry (OP65_BVC, AM65_BRA, L->Name, L, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP - 2);
|
|
|
|
++D->IP;
|
|
|
|
|
|
|
|
/* lda #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* ldx #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* rol a */
|
|
|
|
X = NewCodeEntry (OP65_ROL, AM65_ACC, "a", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Remove the push and the call to the tosltax function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-28 19:34:35 +00:00
|
|
|
static unsigned Opt_tosneax (StackOpData* D)
|
|
|
|
/* Optimize the tosneax sequence */
|
|
|
|
{
|
|
|
|
return Opt_toseqax_tosneax (D, "boolne");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static unsigned Opt_tosorax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosorax sequence */
|
2001-10-01 19:40:01 +00:00
|
|
|
{
|
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2002-10-05 20:32:31 +00:00
|
|
|
ReplacePushByStore (D);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Inline the or, low byte */
|
|
|
|
D->IP = D->OpIndex + 1;
|
2009-08-31 18:02:44 +00:00
|
|
|
AddOpLow (D, OP65_ORA, &D->Lhs);
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* High byte */
|
2009-08-31 19:36:06 +00:00
|
|
|
AddOpHigh (D, OP65_ORA, &D->Lhs, 1);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2002-10-04 19:27:15 +00:00
|
|
|
/* Remove the push and the call to the tosorax function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2001-10-02 10:55:04 +00:00
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-18 15:10:15 +00:00
|
|
|
static unsigned Opt_tossubax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tossubax sequence. Note: subtraction is not commutative! */
|
2009-08-18 15:10:15 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* sec */
|
|
|
|
X = NewCodeEntry (OP65_SEC, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
2009-08-31 18:18:50 +00:00
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
2009-08-27 22:07:28 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for low operand */
|
|
|
|
AddOpLow (D, OP65_SBC, &D->Rhs);
|
2009-08-27 22:07:28 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 1);
|
2009-08-27 22:07:28 +00:00
|
|
|
|
|
|
|
/* Remove the push and the call to the tossubax function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2009-08-18 15:10:15 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-28 16:32:58 +00:00
|
|
|
static unsigned Opt_tosugeax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosugeax sequence */
|
2009-08-28 16:32:58 +00:00
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
2009-08-31 18:18:50 +00:00
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for low operand */
|
|
|
|
AddOpLow (D, OP65_CMP, &D->Rhs);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
2009-08-31 18:18:50 +00:00
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 0);
|
2009-08-28 16:32:58 +00:00
|
|
|
|
|
|
|
/* lda #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDA, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* ldx #$00 */
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, "$00", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* rol a */
|
|
|
|
X = NewCodeEntry (OP65_ROL, AM65_ACC, "a", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Remove the push and the call to the tosugeax function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
static unsigned Opt_tosugtax (StackOpData* D)
|
|
|
|
/* Optimize the tosugtax sequence */
|
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
|
|
|
|
2009-09-03 11:58:11 +00:00
|
|
|
/* sec */
|
|
|
|
X = NewCodeEntry (OP65_SEC, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
/* Add code for low operand */
|
2009-09-03 11:58:11 +00:00
|
|
|
AddOpLow (D, OP65_SBC, &D->Rhs);
|
|
|
|
|
|
|
|
/* We need the zero flag, so remember the immediate result */
|
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP, "tmp1", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-09-01 20:57:39 +00:00
|
|
|
|
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 0);
|
|
|
|
|
2009-09-03 11:58:11 +00:00
|
|
|
/* Set Z flag */
|
|
|
|
X = NewCodeEntry (OP65_ORA, AM65_ZP, "tmp1", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
/* Transform to boolean */
|
|
|
|
X = NewCodeEntry (OP65_JSR, AM65_ABS, "boolugt", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Remove the push and the call to the operator function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned Opt_tosuleax (StackOpData* D)
|
|
|
|
/* Optimize the tosuleax sequence */
|
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
|
|
|
|
2009-09-03 11:58:11 +00:00
|
|
|
/* sec */
|
|
|
|
X = NewCodeEntry (OP65_SEC, AM65_IMP, 0, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
/* Add code for low operand */
|
2009-09-03 11:58:11 +00:00
|
|
|
AddOpLow (D, OP65_SBC, &D->Rhs);
|
|
|
|
|
|
|
|
/* We need the zero flag, so remember the immediate result */
|
|
|
|
X = NewCodeEntry (OP65_STA, AM65_ZP, "tmp1", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
2009-09-01 20:57:39 +00:00
|
|
|
|
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 0);
|
|
|
|
|
2009-09-03 11:58:11 +00:00
|
|
|
/* Set Z flag */
|
|
|
|
X = NewCodeEntry (OP65_ORA, AM65_ZP, "tmp1", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
/* Transform to boolean */
|
|
|
|
X = NewCodeEntry (OP65_JSR, AM65_ABS, "boolule", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Remove the push and the call to the operator function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned Opt_tosultax (StackOpData* D)
|
|
|
|
/* Optimize the tosultax sequence */
|
|
|
|
{
|
|
|
|
CodeEntry* X;
|
|
|
|
|
|
|
|
|
|
|
|
/* Inline the sbc */
|
|
|
|
D->IP = D->OpIndex+1;
|
|
|
|
|
|
|
|
/* Must be true because of OP_RHS_LOAD */
|
|
|
|
CHECK ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) != 0);
|
|
|
|
|
|
|
|
/* Add code for low operand */
|
|
|
|
AddOpLow (D, OP65_CMP, &D->Rhs);
|
|
|
|
|
|
|
|
/* Add code for high operand */
|
|
|
|
AddOpHigh (D, OP65_SBC, &D->Rhs, 0);
|
|
|
|
|
|
|
|
/* Transform to boolean */
|
|
|
|
X = NewCodeEntry (OP65_JSR, AM65_ABS, "boolult", 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
|
|
|
|
/* Remove the push and the call to the operator function */
|
|
|
|
RemoveRemainders (D);
|
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static unsigned Opt_tosxorax (StackOpData* D)
|
2009-08-28 19:34:35 +00:00
|
|
|
/* Optimize the tosxorax sequence */
|
2001-10-02 10:55:04 +00:00
|
|
|
{
|
2002-10-04 19:27:15 +00:00
|
|
|
CodeEntry* X;
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2001-10-04 11:34:18 +00:00
|
|
|
|
2001-10-02 10:55:04 +00:00
|
|
|
/* Store the value into the zeropage instead of pushing it */
|
2002-10-05 20:32:31 +00:00
|
|
|
ReplacePushByStore (D);
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* Inline the xor, low byte */
|
|
|
|
D->IP = D->OpIndex + 1;
|
2009-08-31 18:02:44 +00:00
|
|
|
AddOpLow (D, OP65_EOR, &D->Lhs);
|
2001-10-02 10:55:04 +00:00
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
/* High byte */
|
2002-11-22 23:44:36 +00:00
|
|
|
if (RegValIsKnown (D->PushEntry->RI->In.RegX) &&
|
2002-10-17 21:37:01 +00:00
|
|
|
RegValIsKnown (D->OpEntry->RI->In.RegX)) {
|
2001-10-02 10:55:04 +00:00
|
|
|
/* Both values known, precalculate the result */
|
2002-10-05 20:32:31 +00:00
|
|
|
const char* Arg = MakeHexArg (D->PushEntry->RI->In.RegX ^ D->OpEntry->RI->In.RegX);
|
|
|
|
X = NewCodeEntry (OP65_LDX, AM65_IMM, Arg, 0, D->OpEntry->LI);
|
|
|
|
InsertEntry (D, X, D->IP++);
|
|
|
|
} else if (D->PushEntry->RI->In.RegX != 0) {
|
2001-10-02 10:55:04 +00:00
|
|
|
/* High byte is unknown */
|
2009-08-31 18:18:50 +00:00
|
|
|
AddOpHigh (D, OP65_EOR, &D->Lhs, 1);
|
2001-10-02 10:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove the push and the call to the tosandax function */
|
2009-08-19 13:36:26 +00:00
|
|
|
RemoveRemainders (D);
|
2001-09-25 20:37:58 +00:00
|
|
|
|
|
|
|
/* We changed the sequence */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Code */
|
2001-09-25 20:37:58 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-01 19:40:01 +00:00
|
|
|
static const OptFuncDesc FuncTable[] = {
|
2009-08-27 22:07:28 +00:00
|
|
|
{ "__bzero", Opt___bzero, REG_NONE, OP_X_ZERO | OP_A_KNOWN },
|
|
|
|
{ "staspidx", Opt_staspidx, REG_NONE, OP_NONE },
|
|
|
|
{ "staxspidx", Opt_staxspidx, REG_AX, OP_NONE },
|
|
|
|
{ "tosaddax", Opt_tosaddax, REG_NONE, OP_NONE },
|
|
|
|
{ "tosandax", Opt_tosandax, REG_NONE, OP_NONE },
|
2009-08-28 19:34:35 +00:00
|
|
|
{ "toseqax", Opt_toseqax, REG_NONE, OP_NONE },
|
2009-08-28 16:32:58 +00:00
|
|
|
{ "tosgeax", Opt_tosgeax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
|
|
|
{ "tosltax", Opt_tosltax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
2009-08-28 19:34:35 +00:00
|
|
|
{ "tosneax", Opt_tosneax, REG_NONE, OP_NONE },
|
2009-08-27 22:07:28 +00:00
|
|
|
{ "tosorax", Opt_tosorax, REG_NONE, OP_NONE },
|
2009-08-28 16:32:58 +00:00
|
|
|
{ "tossubax", Opt_tossubax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
|
|
|
{ "tosugeax", Opt_tosugeax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
2009-09-01 20:57:39 +00:00
|
|
|
{ "tosugtax", Opt_tosugtax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
|
|
|
{ "tosuleax", Opt_tosuleax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
|
|
|
{ "tosultax", Opt_tosultax, REG_NONE, OP_RHS_LOAD_DIRECT },
|
2009-08-27 22:07:28 +00:00
|
|
|
{ "tosxorax", Opt_tosxorax, REG_NONE, OP_NONE },
|
2001-10-01 19:40:01 +00:00
|
|
|
};
|
|
|
|
#define FUNC_COUNT (sizeof(FuncTable) / sizeof(FuncTable[0]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int CmpFunc (const void* Key, const void* Func)
|
|
|
|
/* Compare function for bsearch */
|
|
|
|
{
|
|
|
|
return strcmp (Key, ((const OptFuncDesc*) Func)->Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const OptFuncDesc* FindFunc (const char* Name)
|
|
|
|
/* Find the function with the given name. Return a pointer to the table entry
|
|
|
|
* or NULL if the function was not found.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
return bsearch (Name, FuncTable, FUNC_COUNT, sizeof(OptFuncDesc), CmpFunc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-05 20:32:31 +00:00
|
|
|
static int CmpHarmless (const void* Key, const void* Entry)
|
|
|
|
/* Compare function for bsearch */
|
|
|
|
{
|
|
|
|
return strcmp (Key, *(const char**)Entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int HarmlessCall (const char* Name)
|
|
|
|
/* Check if this is a call to a harmless subroutine that will not interrupt
|
|
|
|
* the pushax/op sequence when encountered.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
static const char* Tab[] = {
|
2009-08-15 14:18:00 +00:00
|
|
|
"aslax1",
|
|
|
|
"aslax2",
|
2009-08-29 23:19:01 +00:00
|
|
|
"aslax3",
|
|
|
|
"aslax4",
|
2009-08-15 14:18:00 +00:00
|
|
|
"asrax1",
|
|
|
|
"asrax2",
|
2009-08-29 23:19:01 +00:00
|
|
|
"asrax3",
|
|
|
|
"asrax4",
|
2009-08-27 22:07:28 +00:00
|
|
|
"bnegax",
|
2012-06-06 21:52:54 +00:00
|
|
|
"decax1",
|
|
|
|
"decax2",
|
|
|
|
"decax3",
|
|
|
|
"decax4",
|
|
|
|
"decax5",
|
|
|
|
"decax6",
|
|
|
|
"decax7",
|
|
|
|
"decax8",
|
|
|
|
"decaxy",
|
|
|
|
"incax1",
|
|
|
|
"incax2",
|
|
|
|
"incax3",
|
|
|
|
"incax4",
|
|
|
|
"incax5",
|
|
|
|
"incax6",
|
|
|
|
"incax7",
|
|
|
|
"incax8",
|
|
|
|
"incaxy",
|
2002-11-25 15:05:15 +00:00
|
|
|
"ldaxidx",
|
2002-10-05 20:32:31 +00:00
|
|
|
"ldaxysp",
|
2002-12-01 23:32:13 +00:00
|
|
|
"negax",
|
2009-08-15 14:18:00 +00:00
|
|
|
"shlax1",
|
|
|
|
"shlax2",
|
2009-08-29 21:17:28 +00:00
|
|
|
"shlax3",
|
|
|
|
"shlax4",
|
2009-08-15 14:18:00 +00:00
|
|
|
"shrax1",
|
|
|
|
"shrax2",
|
2009-08-29 21:17:28 +00:00
|
|
|
"shrax3",
|
|
|
|
"shrax4",
|
2002-10-05 20:32:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void* R = bsearch (Name,
|
|
|
|
Tab,
|
|
|
|
sizeof (Tab) / sizeof (Tab[0]),
|
|
|
|
sizeof (Tab[0]),
|
|
|
|
CmpHarmless);
|
|
|
|
return (R != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
static void ResetStackOpData (StackOpData* Data)
|
|
|
|
/* Reset the given data structure */
|
|
|
|
{
|
2009-08-19 13:36:26 +00:00
|
|
|
Data->OptFunc = 0;
|
2009-08-27 22:07:28 +00:00
|
|
|
Data->UsedRegs = REG_NONE;
|
|
|
|
|
|
|
|
ClearLoadInfo (&Data->Lhs);
|
|
|
|
ClearLoadInfo (&Data->Rhs);
|
2009-08-17 12:52:50 +00:00
|
|
|
|
2009-08-19 13:36:26 +00:00
|
|
|
Data->PushIndex = -1;
|
|
|
|
Data->OpIndex = -1;
|
2009-08-17 12:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int PreCondOk (StackOpData* D)
|
|
|
|
/* Check if the preconditions for a call to the optimizer subfunction are
|
|
|
|
* satisfied. As a side effect, this function will also choose the zero page
|
|
|
|
* register to use.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
/* Check the flags */
|
2009-08-20 16:06:20 +00:00
|
|
|
unsigned UnusedRegs = D->OptFunc->UnusedRegs;
|
|
|
|
if (UnusedRegs != REG_NONE &&
|
|
|
|
(GetRegInfo (D->Code, D->OpIndex+1, UnusedRegs) & UnusedRegs) != 0) {
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
2009-08-20 16:06:20 +00:00
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
if ((D->OptFunc->Flags & OP_A_KNOWN) != 0 &&
|
2009-08-20 16:06:20 +00:00
|
|
|
RegValIsUnknown (D->OpEntry->RI->In.RegA)) {
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
2009-08-20 16:06:20 +00:00
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
if ((D->OptFunc->Flags & OP_X_ZERO) != 0 &&
|
2009-08-20 16:06:20 +00:00
|
|
|
D->OpEntry->RI->In.RegX != 0) {
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-28 16:32:58 +00:00
|
|
|
if ((D->OptFunc->Flags & OP_LHS_LOAD) != 0) {
|
|
|
|
if (D->Lhs.A.LoadIndex < 0 || D->Lhs.X.LoadIndex < 0) {
|
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
|
|
|
} else if ((D->OptFunc->Flags & OP_LHS_LOAD_DIRECT) != 0) {
|
|
|
|
if ((D->Lhs.A.Flags & D->Lhs.X.Flags & LI_DIRECT) == 0) {
|
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
2009-08-28 16:32:58 +00:00
|
|
|
if ((D->OptFunc->Flags & OP_RHS_LOAD) != 0) {
|
|
|
|
if (D->Rhs.A.LoadIndex < 0 || D->Rhs.X.LoadIndex < 0) {
|
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
|
|
|
} else if ((D->OptFunc->Flags & OP_RHS_LOAD_DIRECT) != 0) {
|
|
|
|
if ((D->Rhs.A.Flags & D->Rhs.X.Flags & LI_DIRECT) == 0) {
|
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
}
|
2010-01-20 19:47:44 +00:00
|
|
|
if ((D->Rhs.A.Flags | D->Rhs.X.Flags) & LI_DUP_LOAD) {
|
|
|
|
/* Cannot optimize */
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-17 12:52:50 +00:00
|
|
|
|
|
|
|
/* Determine the zero page locations to use */
|
2009-08-18 15:10:15 +00:00
|
|
|
if ((D->UsedRegs & REG_PTR1) == REG_NONE) {
|
|
|
|
D->ZPLo = "ptr1";
|
|
|
|
D->ZPHi = "ptr1+1";
|
|
|
|
} else if ((D->UsedRegs & REG_SREG) == REG_NONE) {
|
2009-08-17 12:52:50 +00:00
|
|
|
D->ZPLo = "sreg";
|
|
|
|
D->ZPHi = "sreg+1";
|
|
|
|
} else if ((D->UsedRegs & REG_PTR2) == REG_NONE) {
|
|
|
|
D->ZPLo = "ptr2";
|
|
|
|
D->ZPHi = "ptr2+1";
|
|
|
|
} else {
|
|
|
|
/* No registers available */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Determine if we have a basic block */
|
|
|
|
return CS_IsBasicBlock (D->Code, D->PushIndex, D->OpIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-01 19:40:01 +00:00
|
|
|
/*****************************************************************************/
|
2009-08-15 14:18:00 +00:00
|
|
|
/* Code */
|
2001-10-01 19:40:01 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-25 20:37:58 +00:00
|
|
|
unsigned OptStackOps (CodeSeg* S)
|
|
|
|
/* Optimize operations that take operands via the stack */
|
|
|
|
{
|
2009-08-17 12:52:50 +00:00
|
|
|
unsigned Changes = 0; /* Number of changes in one run */
|
|
|
|
StackOpData Data;
|
2010-04-25 21:51:59 +00:00
|
|
|
int I;
|
|
|
|
int OldEntryCount; /* Old number of entries */
|
2009-08-17 12:52:50 +00:00
|
|
|
|
|
|
|
enum {
|
2009-08-27 22:07:28 +00:00
|
|
|
Initialize,
|
|
|
|
Search,
|
2009-08-17 12:52:50 +00:00
|
|
|
FoundPush,
|
|
|
|
FoundOp
|
2009-08-27 22:07:28 +00:00
|
|
|
} State = Initialize;
|
2002-10-05 20:32:31 +00:00
|
|
|
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Remember the code segment in the info struct */
|
2009-08-17 12:52:50 +00:00
|
|
|
Data.Code = S;
|
|
|
|
|
2001-10-01 19:40:01 +00:00
|
|
|
/* Look for a call to pushax followed by a call to some other function
|
|
|
|
* that takes it's first argument on the stack, and the second argument
|
|
|
|
* in the primary register.
|
|
|
|
* It depends on the code between the two if we can handle/transform the
|
|
|
|
* sequence, so check this code for the following list of things:
|
|
|
|
*
|
2002-10-06 19:03:12 +00:00
|
|
|
* - the range must be a basic block (one entry, one exit)
|
2001-10-02 10:55:04 +00:00
|
|
|
* - there may not be accesses to local variables with unknown
|
|
|
|
* offsets (because we have to adjust these offsets).
|
2001-10-01 19:40:01 +00:00
|
|
|
* - no subroutine calls
|
|
|
|
* - no jump labels
|
|
|
|
*
|
|
|
|
* Since we need a zero page register later, do also check the
|
|
|
|
* intermediate code for zero page use.
|
|
|
|
*/
|
2001-10-02 10:55:04 +00:00
|
|
|
I = 0;
|
2010-04-25 21:51:59 +00:00
|
|
|
while (I < (int)CS_GetEntryCount (S)) {
|
2001-09-25 20:37:58 +00:00
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Get the next entry */
|
|
|
|
CodeEntry* E = CS_GetEntry (S, I);
|
|
|
|
|
|
|
|
/* Actions depend on state */
|
|
|
|
switch (State) {
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
case Initialize:
|
|
|
|
ResetStackOpData (&Data);
|
2009-08-28 16:32:58 +00:00
|
|
|
State = Search;
|
2009-08-27 22:07:28 +00:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case Search:
|
2009-08-17 12:52:50 +00:00
|
|
|
/* While searching, track register load insns, so we can tell
|
|
|
|
* what is in a register once pushax is encountered.
|
|
|
|
*/
|
2009-09-04 19:54:29 +00:00
|
|
|
if (CE_HasLabel (E)) {
|
|
|
|
/* Currently we don't track across branches */
|
2009-09-11 16:36:17 +00:00
|
|
|
ClearLoadInfo (&Data.Lhs);
|
2009-09-04 19:54:29 +00:00
|
|
|
}
|
2009-08-17 12:52:50 +00:00
|
|
|
if (CE_IsCallTo (E, "pushax")) {
|
|
|
|
Data.PushIndex = I;
|
|
|
|
State = FoundPush;
|
2002-11-23 16:33:35 +00:00
|
|
|
} else {
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Track load insns */
|
|
|
|
TrackLoads (&Data.Lhs, E, I);
|
2009-08-17 12:52:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FoundPush:
|
|
|
|
/* We' found a pushax before. Search for a stack op that may
|
|
|
|
* follow and in the meantime, track zeropage usage and check
|
|
|
|
* for code that will disable us from translating the sequence.
|
|
|
|
*/
|
2009-09-04 19:54:29 +00:00
|
|
|
if (CE_HasLabel (E)) {
|
|
|
|
/* Currently we don't track across branches */
|
2009-09-11 16:36:17 +00:00
|
|
|
ClearLoadInfo (&Data.Rhs);
|
2009-09-04 19:54:29 +00:00
|
|
|
}
|
2009-08-17 12:52:50 +00:00
|
|
|
if (E->OPC == OP65_JSR) {
|
|
|
|
|
|
|
|
/* Subroutine call: Check if this is one of the functions,
|
|
|
|
* we're going to replace.
|
|
|
|
*/
|
|
|
|
Data.OptFunc = FindFunc (E->Arg);
|
|
|
|
if (Data.OptFunc) {
|
|
|
|
/* Remember the op index and go on */
|
|
|
|
Data.OpIndex = I;
|
|
|
|
Data.OpEntry = E;
|
|
|
|
State = FoundOp;
|
|
|
|
break;
|
2009-08-27 22:07:28 +00:00
|
|
|
} else if (!HarmlessCall (E->Arg)) {
|
2009-08-17 12:52:50 +00:00
|
|
|
/* A call to an unkown subroutine: We need to start
|
|
|
|
* over after the last pushax. Note: This will also
|
|
|
|
* happen if we encounter a call to pushax!
|
|
|
|
*/
|
|
|
|
I = Data.PushIndex;
|
2009-08-27 22:07:28 +00:00
|
|
|
State = Initialize;
|
2009-08-17 12:52:50 +00:00
|
|
|
break;
|
2009-08-27 22:07:28 +00:00
|
|
|
} else {
|
|
|
|
/* Track register usage */
|
|
|
|
Data.UsedRegs |= (E->Use | E->Chg);
|
|
|
|
TrackLoads (&Data.Rhs, E, I);
|
2009-08-17 12:52:50 +00:00
|
|
|
}
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2009-08-28 09:29:11 +00:00
|
|
|
} else if (E->Info & OF_STORE && (E->Chg & REG_ZP) == 0) {
|
2009-08-27 22:07:28 +00:00
|
|
|
|
|
|
|
/* Too dangerous - there may be a change of a variable
|
|
|
|
* within the sequence.
|
|
|
|
*/
|
|
|
|
I = Data.PushIndex;
|
|
|
|
State = Initialize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else if ((E->Use & REG_SP) != 0 &&
|
|
|
|
(E->AM != AM65_ZP_INDY ||
|
|
|
|
RegValIsUnknown (E->RI->In.RegY) ||
|
|
|
|
E->RI->In.RegY < 2)) {
|
2009-08-17 12:52:50 +00:00
|
|
|
|
|
|
|
/* If we are using the stack, and we don't have "indirect Y"
|
|
|
|
* addressing mode, or the value of Y is unknown, or less
|
|
|
|
* than two, we cannot cope with this piece of code. Having
|
|
|
|
* an unknown value of Y means that we cannot correct the
|
|
|
|
* stack offset, while having an offset less than two means
|
|
|
|
* that the code works with the value on stack which is to
|
|
|
|
* be removed.
|
|
|
|
*/
|
|
|
|
I = Data.PushIndex;
|
2009-08-27 22:07:28 +00:00
|
|
|
State = Initialize;
|
2009-08-17 12:52:50 +00:00
|
|
|
break;
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
} else {
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Other stuff: Track register usage */
|
2009-08-17 12:52:50 +00:00
|
|
|
Data.UsedRegs |= (E->Use | E->Chg);
|
2009-08-27 22:07:28 +00:00
|
|
|
TrackLoads (&Data.Rhs, E, I);
|
2009-08-17 12:52:50 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FoundOp:
|
|
|
|
/* Track zero page location usage beyond this point */
|
|
|
|
Data.UsedRegs |= GetRegInfo (S, I, REG_SREG | REG_PTR1 | REG_PTR2);
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Finalize the load info */
|
|
|
|
FinalizeLoadInfo (&Data.Lhs, S);
|
|
|
|
FinalizeLoadInfo (&Data.Rhs, S);
|
|
|
|
|
|
|
|
/* If the Lhs loads do load from zeropage, we have to include
|
|
|
|
* them into UsedRegs registers used. The Rhs loads have already
|
|
|
|
* been tracked.
|
2009-08-20 16:06:20 +00:00
|
|
|
*/
|
2009-08-27 22:07:28 +00:00
|
|
|
if (Data.Lhs.A.LoadEntry && Data.Lhs.A.LoadEntry->AM == AM65_ZP) {
|
|
|
|
Data.UsedRegs |= Data.Lhs.A.LoadEntry->Use;
|
2009-08-20 16:06:20 +00:00
|
|
|
}
|
2009-08-27 22:07:28 +00:00
|
|
|
if (Data.Lhs.X.LoadEntry && Data.Lhs.X.LoadEntry->AM == AM65_ZP) {
|
|
|
|
Data.UsedRegs |= Data.Lhs.X.LoadEntry->Use;
|
2009-08-20 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Check the preconditions. If they aren't ok, reset the insn
|
|
|
|
* pointer to the pushax and start over. We will loose part of
|
|
|
|
* load tracking but at least a/x has probably lost between
|
|
|
|
* pushax and here and will be tracked again when restarting.
|
|
|
|
*/
|
|
|
|
if (!PreCondOk (&Data)) {
|
|
|
|
I = Data.PushIndex;
|
2009-08-27 22:07:28 +00:00
|
|
|
State = Initialize;
|
2009-08-17 12:52:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-09-01 20:57:39 +00:00
|
|
|
/* Prepare the remainder of the data structure. */
|
|
|
|
Data.PrevEntry = CS_GetPrevEntry (S, Data.PushIndex);
|
|
|
|
Data.PushEntry = CS_GetEntry (S, Data.PushIndex);
|
|
|
|
Data.OpEntry = CS_GetEntry (S, Data.OpIndex);
|
|
|
|
Data.NextEntry = CS_GetNextEntry (S, Data.OpIndex);
|
|
|
|
|
2010-04-25 21:51:59 +00:00
|
|
|
/* Remember the current number of code lines */
|
|
|
|
OldEntryCount = CS_GetEntryCount (S);
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Adjust stack offsets to account for the upcoming removal */
|
|
|
|
AdjustStackOffset (&Data, 2);
|
|
|
|
|
2009-08-27 22:07:28 +00:00
|
|
|
/* Regenerate register info, since AdjustStackOffset changed
|
|
|
|
* the code
|
|
|
|
*/
|
|
|
|
CS_GenRegInfo (S);
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Call the optimizer function */
|
|
|
|
Changes += Data.OptFunc->Func (&Data);
|
|
|
|
|
2010-04-25 21:51:59 +00:00
|
|
|
/* Since the function may have added or deleted entries,
|
|
|
|
* correct the index.
|
|
|
|
*/
|
|
|
|
I += CS_GetEntryCount (S) - OldEntryCount;
|
|
|
|
|
2009-08-17 12:52:50 +00:00
|
|
|
/* Regenerate register info */
|
|
|
|
CS_GenRegInfo (S);
|
|
|
|
|
|
|
|
/* Done */
|
2009-08-27 22:07:28 +00:00
|
|
|
State = Initialize;
|
2010-04-25 21:51:59 +00:00
|
|
|
continue;
|
2001-10-01 19:40:01 +00:00
|
|
|
|
2001-09-25 20:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Next entry */
|
|
|
|
++I;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of changes made */
|
|
|
|
return Changes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|