mirror of
https://github.com/cc65/cc65.git
synced 2024-12-28 22:30:12 +00:00
More optimizations
git-svn-id: svn://svn.cc65.org/cc65/trunk@842 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
185bb4875f
commit
7da0da3cad
@ -67,6 +67,10 @@ struct FuncInfo {
|
|||||||
|
|
||||||
static const FuncInfo FuncInfoTable[] = {
|
static const FuncInfo FuncInfoTable[] = {
|
||||||
{ "addysp", REG_Y, REG_NONE },
|
{ "addysp", REG_Y, REG_NONE },
|
||||||
|
{ "aslax1", REG_AX, REG_AX },
|
||||||
|
{ "aslax2", REG_AX, REG_AX },
|
||||||
|
{ "aslax3", REG_AX, REG_AX },
|
||||||
|
{ "aslax4", REG_AX, REG_AX },
|
||||||
{ "bnega", REG_A, REG_AX },
|
{ "bnega", REG_A, REG_AX },
|
||||||
{ "bnegax", REG_AX, REG_AX },
|
{ "bnegax", REG_AX, REG_AX },
|
||||||
{ "bnegeax", REG_AX, REG_AX },
|
{ "bnegeax", REG_AX, REG_AX },
|
||||||
@ -122,6 +126,10 @@ static const FuncInfo FuncInfoTable[] = {
|
|||||||
{ "pusheax", REG_AX, REG_Y },
|
{ "pusheax", REG_AX, REG_Y },
|
||||||
{ "pushw0sp", REG_NONE, REG_AXY },
|
{ "pushw0sp", REG_NONE, REG_AXY },
|
||||||
{ "pushwysp", REG_Y, REG_AXY },
|
{ "pushwysp", REG_Y, REG_AXY },
|
||||||
|
{ "shlax1", REG_AX, REG_AX },
|
||||||
|
{ "shlax2", REG_AX, REG_AX },
|
||||||
|
{ "shlax3", REG_AX, REG_AX },
|
||||||
|
{ "shlax4", REG_AX, REG_AX },
|
||||||
{ "shrax1", REG_AX, REG_AX },
|
{ "shrax1", REG_AX, REG_AX },
|
||||||
{ "shrax2", REG_AX, REG_AX },
|
{ "shrax2", REG_AX, REG_AX },
|
||||||
{ "shrax3", REG_AX, REG_AX },
|
{ "shrax3", REG_AX, REG_AX },
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
|
|
||||||
/* common */
|
/* common */
|
||||||
#include "abend.h"
|
#include "abend.h"
|
||||||
|
#include "chartype.h"
|
||||||
#include "print.h"
|
#include "print.h"
|
||||||
#include "xsprintf.h"
|
#include "xsprintf.h"
|
||||||
|
|
||||||
@ -692,7 +693,7 @@ static unsigned OptAdd2 (CodeSeg* S)
|
|||||||
strcmp (L[6]->Arg, "addeqysp") == 0 &&
|
strcmp (L[6]->Arg, "addeqysp") == 0 &&
|
||||||
!CE_HasLabel (L[6]) &&
|
!CE_HasLabel (L[6]) &&
|
||||||
(GetRegInfo (S, I+7) & REG_AX) == 0) {
|
(GetRegInfo (S, I+7) & REG_AX) == 0) {
|
||||||
|
|
||||||
char Buf [20];
|
char Buf [20];
|
||||||
CodeEntry* X;
|
CodeEntry* X;
|
||||||
int Offs;
|
int Offs;
|
||||||
@ -809,6 +810,60 @@ static unsigned OptAdd3 (CodeSeg* S)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Optimize shifts */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned OptShift1 (CodeSeg* S)
|
||||||
|
/* A call to the shlaxN routine may get replaced by one or more asl insns
|
||||||
|
* if the value of X is not used later.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
unsigned Changes = 0;
|
||||||
|
|
||||||
|
/* Walk over the entries */
|
||||||
|
unsigned I = 0;
|
||||||
|
while (I < CS_GetEntryCount (S)) {
|
||||||
|
|
||||||
|
/* Get next entry */
|
||||||
|
CodeEntry* E = CS_GetEntry (S, I);
|
||||||
|
|
||||||
|
/* Check for the sequence */
|
||||||
|
if (E->OPC == OP65_JSR &&
|
||||||
|
(strncmp (E->Arg, "shlax", 5) == 0 ||
|
||||||
|
strncmp (E->Arg, "aslax", 5) == 0) &&
|
||||||
|
strlen (E->Arg) == 6 &&
|
||||||
|
IsDigit (E->Arg[5]) &&
|
||||||
|
!RegXUsed (S, I+1)) {
|
||||||
|
|
||||||
|
/* Insert shift insns */
|
||||||
|
unsigned Count = E->Arg[5] - '0';
|
||||||
|
while (Count--) {
|
||||||
|
CodeEntry* X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI);
|
||||||
|
CS_InsertEntry (S, X, I+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete the call to shlax */
|
||||||
|
CS_DelEntry (S, I);
|
||||||
|
|
||||||
|
/* Remember, we had changes */
|
||||||
|
++Changes;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Next entry */
|
||||||
|
++I;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the number of changes made */
|
||||||
|
return Changes;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Optimizations for compares */
|
/* Optimizations for compares */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
@ -984,7 +1039,7 @@ static unsigned OptCmp3 (CodeSeg* S)
|
|||||||
CE_ReplaceOPC (L[1], OP65_CMP);
|
CE_ReplaceOPC (L[1], OP65_CMP);
|
||||||
|
|
||||||
/* Beware: If the first LDA instruction had a label, we have
|
/* Beware: If the first LDA instruction had a label, we have
|
||||||
* to move this label to the top of the sequence again.
|
* to move this label to the top of the sequence again.
|
||||||
*/
|
*/
|
||||||
if (CE_HasLabel (E)) {
|
if (CE_HasLabel (E)) {
|
||||||
CS_MoveLabels (S, E, L[0]);
|
CS_MoveLabels (S, E, L[0]);
|
||||||
@ -1629,7 +1684,7 @@ static unsigned OptNegAX4 (CodeSeg* S)
|
|||||||
|
|
||||||
/* Insert apropriate test code */
|
/* Insert apropriate test code */
|
||||||
if (ByteSized) {
|
if (ByteSized) {
|
||||||
/* Test bytes */
|
/* Test bytes */
|
||||||
X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, L[0]->LI);
|
X = NewCodeEntry (OP65_TAX, AM65_IMP, 0, 0, L[0]->LI);
|
||||||
CS_InsertEntry (S, X, I+2);
|
CS_InsertEntry (S, X, I+2);
|
||||||
} else {
|
} else {
|
||||||
@ -2017,7 +2072,7 @@ static unsigned OptPtrLoad2 (CodeSeg* S)
|
|||||||
L[7]->OPC == OP65_JSR &&
|
L[7]->OPC == OP65_JSR &&
|
||||||
strcmp (L[7]->Arg, "ldauidx") == 0 &&
|
strcmp (L[7]->Arg, "ldauidx") == 0 &&
|
||||||
!CE_HasLabel (L[7])) {
|
!CE_HasLabel (L[7])) {
|
||||||
|
|
||||||
CodeEntry* X;
|
CodeEntry* X;
|
||||||
|
|
||||||
/* Store the low byte and remove the TAY instead */
|
/* Store the low byte and remove the TAY instead */
|
||||||
@ -2278,6 +2333,8 @@ static OptFunc OptFuncs [] = {
|
|||||||
OptEntry (OptAdd1, optPre),
|
OptEntry (OptAdd1, optPre),
|
||||||
OptEntry (OptAdd2, optPre),
|
OptEntry (OptAdd2, optPre),
|
||||||
OptEntry (OptAdd3, optMain),
|
OptEntry (OptAdd3, optMain),
|
||||||
|
/* Optimize shifts */
|
||||||
|
OptEntry (OptShift1, optPre),
|
||||||
/* Optimize jump cascades */
|
/* Optimize jump cascades */
|
||||||
OptEntry (OptJumpCascades, optMain),
|
OptEntry (OptJumpCascades, optMain),
|
||||||
/* Remove dead jumps */
|
/* Remove dead jumps */
|
||||||
|
Loading…
Reference in New Issue
Block a user