1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-14 14:26:27 +00:00

More optimizations

git-svn-id: svn://svn.cc65.org/cc65/trunk@842 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2001-08-05 22:50:00 +00:00
parent 185bb4875f
commit 7da0da3cad
2 changed files with 69 additions and 4 deletions

View File

@@ -67,6 +67,10 @@ struct FuncInfo {
static const FuncInfo FuncInfoTable[] = {
{ "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 },
{ "bnegax", REG_AX, REG_AX },
{ "bnegeax", REG_AX, REG_AX },
@@ -122,6 +126,10 @@ static const FuncInfo FuncInfoTable[] = {
{ "pusheax", REG_AX, REG_Y },
{ "pushw0sp", REG_NONE, 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 },
{ "shrax2", REG_AX, REG_AX },
{ "shrax3", REG_AX, REG_AX },

View File

@@ -37,6 +37,7 @@
/* common */
#include "abend.h"
#include "chartype.h"
#include "print.h"
#include "xsprintf.h"
@@ -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 */
/*****************************************************************************/
@@ -2278,6 +2333,8 @@ static OptFunc OptFuncs [] = {
OptEntry (OptAdd1, optPre),
OptEntry (OptAdd2, optPre),
OptEntry (OptAdd3, optMain),
/* Optimize shifts */
OptEntry (OptShift1, optPre),
/* Optimize jump cascades */
OptEntry (OptJumpCascades, optMain),
/* Remove dead jumps */