SmallerC: generate smaller & faster code; bugfixes

Improvements:
- use registers more efficiently
- eliminate some register copies and stack manipulations
- promote left operands to right immediate operands
- improve simple assignments to auto/static vars
- use bltz, blez, bgtz, bgez
- change mul/divu (by powers of 2) to sll/srl/and
- use seb, seh for sign extension instead of sll/sra
- overall generate a bit tighter, faster and more readable asm code

Fixes:
- >>= should be unsigned when the left operand is unsigned int.
The right operand isn't important here.
- very subtle bug in e.g. void f(){int a; &a+1;/*wrong value of &a+1*/}

Other:
- include stdarg.c and skeleton.c in /share/example/Makefile
This commit is contained in:
alex
2014-12-29 16:28:56 -08:00
parent 00269e9387
commit b1f67fbca0
4 changed files with 926 additions and 306 deletions

View File

@@ -3,7 +3,8 @@ include $(TOPSRC)/target.mk
CFLAGS = -Os -Wall -DMIPS -DNO_ANNOTATIONS -DNO_PREPROCESSOR \
-DNO_PPACK -D_RETROBSD -D__SMALLER_C_SCHAR__ \
-D__SMALLER_C__ -D__SMALLER_C_32__ -DSTATIC
-D__SMALLER_C__ -D__SMALLER_C_32__ -DSTATIC \
-DNO_EXTRA_WARNS -DSYNTAX_STACK_MAX=2560
# For cross compile
#include $(TOPSRC)/cross.mk

File diff suppressed because it is too large Load Diff

View File

@@ -3797,7 +3797,7 @@ int exprval(int* idx, int* ExprTypeSynPtr, int* ConstExpr)
}
if (SyntaxStack[*ExprTypeSynPtr][0] == tokUnsigned && tok == tokRShift)
stack[oldIdxRight + 1 - (oldSpRight - sp)][0] = tokURShift;
stack[oldIdxRight + 1 - (oldSpRight - sp)][0] = tokURShift;
// ignore RightExprTypeSynPtr for the purpose of promotion/conversion of the result of <</>>
RightExprTypeSynPtr = SymIntSynPtr;
@@ -4215,10 +4215,12 @@ int exprval(int* idx, int* ExprTypeSynPtr, int* ConstExpr)
{
case tokAssignDiv: t = tokAssignUDiv; break;
case tokAssignMod: t = tokAssignUMod; break;
case tokAssignRSh: t = tokAssignURSh; break;
case tokAssignRSh:
if (SyntaxStack[*ExprTypeSynPtr][0] == tokUnsigned)
t = tokAssignURSh;
break;
}
if (t != tok)
stack[oldIdxRight + 1 - (oldSpRight - sp)][0] = t;
stack[oldIdxRight + 1 - (oldSpRight - sp)][0] = t;
}
*ConstExpr = 0;