Allow a more exact specification which growth factor is allowed when
generating code and favouring speed over size. git-svn-id: svn://svn.cc65.org/cc65/trunk@668 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
4ab743143b
commit
2fead58243
6 changed files with 80 additions and 61 deletions
|
@ -677,7 +677,7 @@ void g_getimmed (unsigned flags, unsigned long val, unsigned offs)
|
|||
AddCodeLine ("\tsta\tsreg+1");
|
||||
AddCodeLine ("\tsta\tsreg");
|
||||
AddCodeLine ("\tldx\t#$%02X", (unsigned char) (val >> 8));
|
||||
} else if ((val & 0xFFFF0000) == 0 && FavourSize == 0) {
|
||||
} else if ((val & 0xFFFF0000) == 0 && CodeSizeFactor > 140) {
|
||||
AddCodeLine ("\tlda\t#$00");
|
||||
AddCodeLine ("\tsta\tsreg+1");
|
||||
AddCodeLine ("\tsta\tsreg");
|
||||
|
@ -820,19 +820,19 @@ void g_getlocal (unsigned flags, int offs)
|
|||
AddCodeLine ("\tdey");
|
||||
AddCodeLine ("\tora\t(sp),y");
|
||||
} else {
|
||||
if (FavourSize) {
|
||||
if (CodeSizeFactor > 180) {
|
||||
ldyconst (offs + 1);
|
||||
AddCodeLine ("\tlda\t(sp),y");
|
||||
AddCodeLine ("\ttax");
|
||||
AddCodeLine ("\tdey");
|
||||
AddCodeLine ("\tlda\t(sp),y");
|
||||
} else {
|
||||
if (offs) {
|
||||
ldyconst (offs+1);
|
||||
AddCodeLine ("\tjsr\tldaxysp");
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\tldax0sp");
|
||||
}
|
||||
} else {
|
||||
ldyconst (offs + 1);
|
||||
AddCodeLine ("\tlda\t(sp),y");
|
||||
AddCodeLine ("\ttax");
|
||||
AddCodeLine ("\tdey");
|
||||
AddCodeLine ("\tlda\t(sp),y");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -878,13 +878,13 @@ void g_getind (unsigned flags, unsigned offs)
|
|||
}
|
||||
} else {
|
||||
if (flags & CF_UNSIGNED) {
|
||||
if (FavourSize) {
|
||||
AddCodeLine ("\tjsr\tldaui");
|
||||
} else {
|
||||
if (CodeSizeFactor > 250) {
|
||||
AddCodeLine ("\tsta\tptr1");
|
||||
AddCodeLine ("\tstx\tptr1+1");
|
||||
AddCodeLine ("\tldx\t#$00");
|
||||
AddCodeLine ("\tlda\t(ptr1,x)");
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\tldaui");
|
||||
}
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\tldai");
|
||||
|
@ -941,7 +941,7 @@ void g_leasp (int offs)
|
|||
AddCodeLine ("\tlda\tsp");
|
||||
AddCodeLine ("\tldx\tsp+1");
|
||||
} else {
|
||||
if (FavourSize) {
|
||||
if (CodeSizeFactor < 300) {
|
||||
ldaconst (offs); /* Load A with offset value */
|
||||
AddCodeLine ("\tjsr\tleaasp"); /* Load effective address */
|
||||
} else {
|
||||
|
@ -1127,7 +1127,7 @@ void g_putlocal (unsigned Flags, int Offs, long Val)
|
|||
AddCodeLine ("\tsta\t(sp),y");
|
||||
}
|
||||
} else {
|
||||
if ((Flags & CF_NOKEEP) == 0 || FavourSize) {
|
||||
if ((Flags & CF_NOKEEP) == 0 || CodeSizeFactor < 160) {
|
||||
if (Offs) {
|
||||
ldyconst (Offs);
|
||||
AddCodeLine ("\tjsr\tstaxysp");
|
||||
|
@ -1315,12 +1315,12 @@ void g_reglong (unsigned flags)
|
|||
case CF_CHAR:
|
||||
case CF_INT:
|
||||
if (flags & CF_UNSIGNED) {
|
||||
if (FavourSize) {
|
||||
AddCodeLine ("\tjsr\taxulong");
|
||||
} else {
|
||||
if (CodeSizeFactor >= 200) {
|
||||
ldyconst (0);
|
||||
AddCodeLine ("\tsty\tsreg");
|
||||
AddCodeLine ("\tsty\tsreg+1");
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\taxulong");
|
||||
}
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\taxlong");
|
||||
|
@ -1451,19 +1451,19 @@ void g_scale (unsigned flags, long val)
|
|||
/* FALLTHROUGH */
|
||||
|
||||
case CF_INT:
|
||||
if (FavourSize || p2 >= 3) {
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tjsr\tshlax%d", p2);
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\taslax%d", p2);
|
||||
}
|
||||
} else {
|
||||
if (CodeSizeFactor >= (p2+1)*130U) {
|
||||
AddCodeLine ("\tstx\ttmp1");
|
||||
while (p2--) {
|
||||
AddCodeLine ("\tasl\ta");
|
||||
AddCodeLine ("\trol\ttmp1");
|
||||
}
|
||||
AddCodeLine ("\tldx\ttmp1");
|
||||
} else {
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("\tjsr\tshlax%d", p2);
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\taslax%d", p2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1513,20 +1513,18 @@ void g_scale (unsigned flags, long val)
|
|||
|
||||
case CF_INT:
|
||||
if (flags & CF_UNSIGNED) {
|
||||
if (FavourSize || p2 >= 3) {
|
||||
AddCodeLine ("\tjsr\tlsrax%d", p2);
|
||||
} else {
|
||||
if (CodeSizeFactor >= (p2+1)*130U) {
|
||||
AddCodeLine ("\tstx\ttmp1");
|
||||
while (p2--) {
|
||||
AddCodeLine ("\tlsr\ttmp1");
|
||||
AddCodeLine ("\tror\ta");
|
||||
}
|
||||
AddCodeLine ("\tldx\ttmp1");
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\tlsrax%d", p2);
|
||||
}
|
||||
} else {
|
||||
if (FavourSize || p2 >= 3) {
|
||||
AddCodeLine ("\tjsr\tasrax%d", p2);
|
||||
} else {
|
||||
if (CodeSizeFactor >= (p2+1)*150U) {
|
||||
AddCodeLine ("\tstx\ttmp1");
|
||||
while (p2--) {
|
||||
AddCodeLine ("\tcpx\t#$80");
|
||||
|
@ -1534,6 +1532,8 @@ void g_scale (unsigned flags, long val)
|
|||
AddCodeLine ("\tror\ta");
|
||||
}
|
||||
AddCodeLine ("\tldx\ttmp1");
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\tasrax%d", p2);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1902,7 +1902,7 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val)
|
|||
break;
|
||||
|
||||
case CF_INT:
|
||||
if (!FavourSize) {
|
||||
if (CodeSizeFactor >= 200) {
|
||||
/* Lots of code, use only if size is not important */
|
||||
AddCodeLine ("\tsta\tptr1");
|
||||
AddCodeLine ("\tstx\tptr1+1");
|
||||
|
@ -2137,7 +2137,7 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val)
|
|||
break;
|
||||
|
||||
case CF_INT:
|
||||
if (!FavourSize) {
|
||||
if (CodeSizeFactor >= 200) {
|
||||
/* Lots of code, use only if size is not important */
|
||||
AddCodeLine ("\tsta\tptr1");
|
||||
AddCodeLine ("\tstx\tptr1+1");
|
||||
|
@ -2419,11 +2419,11 @@ void g_push (unsigned flags, unsigned long val)
|
|||
if ((flags & CF_TYPE) == CF_CHAR && (flags & CF_FORCECHAR)) {
|
||||
|
||||
/* Handle as 8 bit value */
|
||||
if (FavourSize && val <= 2) {
|
||||
AddCodeLine ("\tjsr\tpushc%d", (int) val);
|
||||
} else {
|
||||
if (CodeSizeFactor >= 165 || val > 2) {
|
||||
ldaconst (val);
|
||||
AddCodeLine ("\tjsr\tpusha");
|
||||
} else {
|
||||
AddCodeLine ("\tjsr\tpushc%d", (int) val);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
@ -3309,7 +3309,7 @@ void g_inc (unsigned flags, unsigned long val)
|
|||
AddCodeLine ("\tinx");
|
||||
/* Tell the optimizer that the X register may be invalid */
|
||||
AddCodeHint ("x:!");
|
||||
} else if (FavourSize) {
|
||||
} else if (CodeSizeFactor < 200) {
|
||||
/* Use jsr calls */
|
||||
if (val <= 8) {
|
||||
AddCodeLine ("\tjsr\tincax%lu", val);
|
||||
|
@ -3943,7 +3943,7 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs)
|
|||
} else {
|
||||
|
||||
/* Address not constant but in primary */
|
||||
if (FavourSize) {
|
||||
if (CodeSizeFactor < 400) {
|
||||
/* This is too much code, so call strlen instead of inlining */
|
||||
AddCodeLine ("\tjsr\t_strlen");
|
||||
} else {
|
||||
|
|
|
@ -539,7 +539,7 @@ static unsigned FunctionParamList (FuncDesc* Func)
|
|||
* - we have more than one parameter to push (don't count the last param
|
||||
* for __fastcall__ functions).
|
||||
*/
|
||||
if (Optimize && !FavourSize) {
|
||||
if (CodeSizeFactor >= 200) {
|
||||
|
||||
/* Calculate the number and size of the parameters */
|
||||
FrameParams = Func->ParamCount;
|
||||
|
|
|
@ -48,6 +48,7 @@ unsigned char WriteableStrings = 0; /* Literal strings are r/w */
|
|||
unsigned char NoWarn = 0; /* Suppress warnings */
|
||||
unsigned char Optimize = 0; /* Optimize flag */
|
||||
unsigned char FavourSize = 1; /* Favour size over speed */
|
||||
unsigned CodeSizeFactor = 100; /* Size factor for generated code */
|
||||
unsigned char InlineStdFuncs = 0; /* Inline some known functions */
|
||||
unsigned char EnableRegVars = 0; /* Enable register variables */
|
||||
unsigned char AllowRegVarAddr = 0; /* Allow taking addresses of register vars */
|
||||
|
|
|
@ -49,6 +49,7 @@ extern unsigned char WriteableStrings; /* Literal strings are r/w */
|
|||
extern unsigned char NoWarn; /* Suppress warnings */
|
||||
extern unsigned char Optimize; /* Optimize flag */
|
||||
extern unsigned char FavourSize; /* Favour size over speed */
|
||||
extern unsigned CodeSizeFactor; /* Size factor for generated code */
|
||||
extern unsigned char InlineStdFuncs; /* Inline some known functions */
|
||||
extern unsigned char EnableRegVars; /* Enable register variables */
|
||||
extern unsigned char AllowRegVarAddr; /* Allow taking addresses of register vars */
|
||||
|
@ -62,6 +63,7 @@ extern unsigned char CreateDep; /* Create a dependency file */
|
|||
extern unsigned char CheckStack; /* Generate stack overflow checks */
|
||||
|
||||
|
||||
|
||||
/* End of global.h */
|
||||
|
||||
#endif
|
||||
|
|
|
@ -99,6 +99,7 @@ static void Usage (void)
|
|||
" --bss-name seg\tSet the name of the BSS segment\n"
|
||||
" --check-stack\t\tGenerate stack overflow checks\n"
|
||||
" --code-name seg\tSet the name of the CODE segment\n"
|
||||
" --codesize x\tAccept larger code by factor x\n"
|
||||
" --cpu type\t\tSet cpu type\n"
|
||||
" --data-name seg\tSet the name of the DATA segment\n"
|
||||
" --debug\t\tDebug mode\n"
|
||||
|
@ -314,6 +315,19 @@ static void OptCodeName (const char* Opt, const char* Arg)
|
|||
|
||||
|
||||
|
||||
static void OptCodeSize (const char* Opt, const char* Arg)
|
||||
/* Handle the --codesize option */
|
||||
{
|
||||
/* Numeric argument expected */
|
||||
if (sscanf (Arg, "%u", &CodeSizeFactor) != 1 ||
|
||||
CodeSizeFactor < 100 ||
|
||||
CodeSizeFactor > 1000) {
|
||||
AbEnd ("Argument for %s is invalid", Opt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void OptCreateDep (const char* Opt, const char* Arg)
|
||||
/* Handle the --create-dep option */
|
||||
{
|
||||
|
@ -444,6 +458,7 @@ int main (int argc, char* argv[])
|
|||
{ "--bss-name", 1, OptBssName },
|
||||
{ "--check-stack", 0, OptCheckStack },
|
||||
{ "--code-name", 1, OptCodeName },
|
||||
{ "--codesize", 1, OptCodeSize },
|
||||
{ "--create-dep", 0, OptCreateDep },
|
||||
{ "--cpu", 1, OptCPU },
|
||||
{ "--data-name", 1, OptDataName },
|
||||
|
@ -558,6 +573,7 @@ int main (int argc, char* argv[])
|
|||
break;
|
||||
case 'i':
|
||||
FavourSize = 0;
|
||||
CodeSizeFactor = 200;
|
||||
break;
|
||||
case 'r':
|
||||
EnableRegVars = 1;
|
||||
|
|
|
@ -568,7 +568,7 @@ static void doswitch (void)
|
|||
ConsumeLCurly ();
|
||||
|
||||
/* Now decide which sort of switch we will create: */
|
||||
if (IsTypeChar (eval.e_tptr) || (FavourSize == 0 && IsClassInt (eval.e_tptr))) {
|
||||
if (IsTypeChar (eval.e_tptr) || (CodeSizeFactor >= 200 && IsClassInt (eval.e_tptr))) {
|
||||
cascadeswitch (&eval);
|
||||
} else {
|
||||
tableswitch (&eval);
|
||||
|
|
Loading…
Add table
Reference in a new issue