#endif
#endif
+#define BETTER_LITERAL_SHIFT
+
char *aopLiteral (value * val, int offset);
/* this is the down and dirty file with all kinds of
{
_currentDPS = 0;
_desiredDPS = 0;
+#ifdef BETTER_LITERAL_SHIFT
+ _lazyDPS++;
+#else
_lazyDPS = 1;
+#endif
}
/*-----------------------------------------------------------------*/
static void
_endLazyDPSEvaluation (void)
{
- if (_currentDPS)
+#ifdef BETTER_LITERAL_SHIFT
+ _lazyDPS--;
+#else
+ _lazyDPS = 0;
+#endif
+ if (!_lazyDPS)
+ {
+ if (_currentDPS)
{
genSetDPTR (0);
_flushLazyDPS ();
}
- _lazyDPS = 0;
- _currentDPS = 0;
- _desiredDPS = 0;
+ _currentDPS = 0;
+ _desiredDPS = 0;
+ }
}
int size = getSize (operandType (IC_RESULT (ic)));
/* Special case for 1 or 2 byte return in far space. */
- emitcode (";", "Kevin function call abuse #1");
-
MOVA (fReturn[0]);
if (size > 1)
{
int size = (getDataSize (result) - offset);
if (size > 0)
{
+ _startLazyDPSEvaluation();
if (sign)
{
emitcode ("rlc", "a");
emitcode ("subb", "a,acc");
while (size--)
+ {
aopPut (AOP (result), "a", offset++);
+ }
}
else
+ {
while (size--)
+ {
aopPut (AOP (result), zero, offset++);
+ }
+ }
+ _endLazyDPSEvaluation();
}
}
{
symbol *lbl = newiTempLabel (NULL);
- D (emitcode (";", "genMinusBits ");
- );
+ D (emitcode (";", "genMinusBits "););
if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY)
{
}
}
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* AccSRsh - signed right shift accumulator by known count */
/*-----------------------------------------------------------------*/
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* shiftR1Left2Result - shift right one byte from left to result */
/*-----------------------------------------------------------------*/
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* shiftL1Left2Result - shift left one byte from left to result */
/*-----------------------------------------------------------------*/
shiftL1Left2Result (operand * left, int offl,
operand * result, int offr, int shCount)
{
- char *l;
- l = aopGet (AOP (left), offl, FALSE, FALSE, TRUE);
- MOVA (l);
+ MOVA(aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
/* shift left accumulator */
AccLsh (shCount);
aopPut (AOP (result), "a", offr);
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* movLeft2Result - move byte from left to result */
/*-----------------------------------------------------------------*/
{
char *l;
if (!sameRegs (AOP (left), AOP (result)) || (offl != offr))
- {
- l = aopGet (AOP (left), offl, FALSE, FALSE, FALSE);
+ {
+ l = aopGet (AOP (left), offl, FALSE, FALSE, TRUE);
if (*l == '@' && (IS_AOP_PREG (result)))
- {
+ {
emitcode ("mov", "a,%s", l);
aopPut (AOP (result), "a", offr);
- }
+ }
else
- {
+ {
if (!sign)
+ {
aopPut (AOP (result), l, offr);
+ }
else
{
/* MSB sign in acc.7 ! */
aopPut (AOP (result), "a", offr);
}
}
- }
- }
+ }
+ }
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* AccAXRrl1 - right rotate c->a:x->c by 1 */
/*-----------------------------------------------------------------*/
}
#endif
-#if 0
+#ifdef BETTER_LITERAL_SHIFT
//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* AccAXLrl1 - left rotate c<-a:x<-c by 1 */
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* AccAXLsh1 - left shift a:x<-0 by 1 */
/*-----------------------------------------------------------------*/
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* AccAXLsh - left shift a:x by known count (0..7) */
/*-----------------------------------------------------------------*/
}
#endif
-#if 0
+#ifdef BETTER_LITERAL_SHIFT
//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* AccAXRsh - right shift a:x known count (0..7) */
}
#endif
-#if 0
+#ifdef BETTER_LITERAL_SHIFT
//REMOVE ME!!!
/*-----------------------------------------------------------------*/
/* AccAXRshS - right shift signed a:x known count (0..7) */
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
+static void
+_loadLeftIntoAx(char **lsb,
+ operand *left,
+ operand *result,
+ int offl,
+ int offr)
+{
+ // Get the initial value from left into a pair of registers.
+ // MSB must be in A, LSB can be any register.
+ //
+ // If the result is held in registers, it is an optimization
+ // if the LSB can be held in the register which will hold the,
+ // result LSB since this saves us from having to copy it into
+ // the result following AccAXLsh.
+ //
+ // If the result is addressed indirectly, this is not a gain.
+ if (AOP_NEEDSACC(result))
+ {
+ char *leftByte;
+
+ _startLazyDPSEvaluation();
+ if (AOP_TYPE(left) == AOP_DPTR2)
+ {
+ // Get MSB in A.
+ MOVA(aopGet(AOP(left), offl + MSB16, FALSE, FALSE, TRUE));
+ // get LSB in DP2_RESULT_REG.
+ leftByte = aopGet(AOP(left), offl, FALSE, FALSE, FALSE);
+ assert(!strcmp(leftByte, DP2_RESULT_REG));
+ }
+ else
+ {
+ // get LSB into DP2_RESULT_REG
+ leftByte = aopGet (AOP(left), offl, FALSE, FALSE, TRUE);
+ if (strcmp(leftByte, DP2_RESULT_REG))
+ {
+ emitcode("mov","%s,%s", DP2_RESULT_REG, leftByte);
+ }
+ // And MSB in A.
+ leftByte = aopGet(AOP(left), offl + MSB16, FALSE, FALSE, TRUE);
+ assert(strcmp(leftByte, DP2_RESULT_REG));
+ MOVA(leftByte);
+ }
+ _endLazyDPSEvaluation();
+ *lsb = DP2_RESULT_REG;
+ }
+ else
+ {
+ if (sameRegs (AOP (result), AOP (left)) &&
+ ((offl + MSB16) == offr))
+ {
+ /* don't crash result[offr] */
+ MOVA(aopGet(AOP(left), offl, FALSE, FALSE, TRUE));
+ emitcode ("xch", "a,%s",
+ aopGet(AOP(left), offl + MSB16, FALSE, FALSE, FALSE));
+ }
+ else
+ {
+ movLeft2Result (left, offl, result, offr, 0);
+ MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE, TRUE));
+ }
+ *lsb = aopGet(AOP (result), offr, FALSE, FALSE, FALSE);
+ assert(strcmp(*lsb,"a"));
+ }
+}
+
+static void
+_storeAxResults(char *lsb,
+ operand *result,
+ int offr)
+{
+ _startLazyDPSEvaluation();
+ if (AOP_NEEDSACC(result))
+ {
+ /* We have to explicitly update the result LSB.
+ */
+ emitcode("xch","a,%s", lsb);
+ aopPut(AOP(result), "a", offr);
+ emitcode("mov","a,%s", lsb);
+ }
+ if (getDataSize (result) > 1)
+ {
+ aopPut (AOP (result), "a", offr + MSB16);
+ }
+ _endLazyDPSEvaluation();
+}
+
/*-----------------------------------------------------------------*/
/* shiftL2Left2Result - shift left two bytes from left to result */
/*-----------------------------------------------------------------*/
shiftL2Left2Result (operand * left, int offl,
operand * result, int offr, int shCount)
{
- if (sameRegs (AOP (result), AOP (left)) &&
- ((offl + MSB16) == offr))
- {
- /* don't crash result[offr] */
- MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
- emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE, FALSE));
- }
- else
- {
- movLeft2Result (left, offl, result, offr, 0);
- MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE, TRUE));
- }
- /* ax << shCount (x = lsb(result)) */
- AccAXLsh (aopGet (AOP (result), offr, FALSE, FALSE, FALSE), shCount);
- aopPut (AOP (result), "a", offr + MSB16);
+ char *lsb;
+
+ _loadLeftIntoAx(&lsb, left, result, offl, offr);
+
+ AccAXLsh (lsb, shCount);
+
+ _storeAxResults(lsb, result, offr);
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* shiftR2Left2Result - shift right two bytes from left to result */
/*-----------------------------------------------------------------*/
operand * result, int offr,
int shCount, int sign)
{
- if (sameRegs (AOP (result), AOP (left)) &&
- ((offl + MSB16) == offr))
- {
- /* don't crash result[offr] */
- MOVA (aopGet (AOP (left), offl, FALSE, FALSE, TRUE));
- emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE, FALSE));
- }
- else
- {
- movLeft2Result (left, offl, result, offr, 0);
- MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE, TRUE));
- }
+ char *lsb;
+
+ _loadLeftIntoAx(&lsb, left, result, offl, offr);
+
/* a:x >> shCount (x = lsb(result)) */
if (sign)
- AccAXRshS (aopGet (AOP (result), offr, FALSE, FALSE, FALSE), shCount);
+ {
+ AccAXRshS(aopGet(AOP(result), offr, FALSE, FALSE, FALSE), shCount);
+ }
else
- AccAXRsh (aopGet (AOP (result), offr, FALSE, FALSE, FALSE), shCount);
- if (getDataSize (result) > 1)
- aopPut (AOP (result), "a", offr + MSB16);
+ {
+ AccAXRsh(aopGet(AOP(result), offr, FALSE, FALSE, FALSE), shCount);
+ }
+
+ _storeAxResults(lsb, result, offr);
}
#endif
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* genlshOne - left shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
static void
genlshOne (operand * result, operand * left, int shCount)
{
- D (emitcode (";", "genlshOne ");
- );
+ D (emitcode (";", "genlshOne "););
shiftL1Left2Result (left, LSB, result, LSB, shCount);
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* genlshTwo - left shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
{
int size;
- D (emitcode (";", "genlshTwo ");
- );
+ D (emitcode (";", "genlshTwo "););
size = getDataSize (result);
/* if shCount >= 8 */
if (shCount >= 8)
- {
+ {
shCount -= 8;
+ _startLazyDPSEvaluation();
+
if (size > 1)
{
if (shCount)
+ {
+ _endLazyDPSEvaluation();
shiftL1Left2Result (left, LSB, result, MSB16, shCount);
+ aopPut (AOP (result), zero, LSB);
+ }
else
+ {
movLeft2Result (left, LSB, result, MSB16, 0);
+ aopPut (AOP (result), zero, LSB);
+ _endLazyDPSEvaluation();
+ }
}
- aopPut (AOP (result), zero, LSB);
- }
+ else
+ {
+ aopPut (AOP (result), zero, LSB);
+ _endLazyDPSEvaluation();
+ }
+ }
/* 1 <= shCount <= 7 */
else
{
if (size == 1)
+ {
shiftL1Left2Result (left, LSB, result, LSB, shCount);
+ }
else
+ {
shiftL2Left2Result (left, LSB, result, LSB, shCount);
+ }
}
}
#endif
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* genLeftShiftLiteral - left shifting by known count */
/*-----------------------------------------------------------------*/
-static void
+static bool
genLeftShiftLiteral (operand * left,
operand * right,
operand * result,
int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
int size;
- D (emitcode (";", "genLeftShiftLiteral (%d)", shCount);
- );
+ size = getSize (operandType (result));
- freeAsmop (right, NULL, ic, TRUE);
+ D(emitcode (";", "genLeftShiftLiteral (%d), size %d", shCount, size););
- aopOp (left, ic, FALSE, FALSE);
- aopOp (result, ic, FALSE, TRUE);
+ /* We only handle certain easy cases so far. */
+ if ((shCount != 0)
+ && (shCount < (size * 8))
+ && (size != 1)
+ && (size != 2))
+ {
+ D(emitcode (";", "genLeftShiftLiteral wimping out"););
+ return FALSE;
+ }
- size = getSize (operandType (result));
+ freeAsmop (right, NULL, ic, TRUE);
+
+ aopOp(left, ic, FALSE, FALSE);
+ aopOp(result, ic, FALSE, (AOP_TYPE(left) == AOP_DPTR));
+#if 1 // debug spew
+ if (IS_SYMOP(left) && OP_SYMBOL(left)->aop)
+ {
+ emitcode(";", "left (%s) is %d", OP_SYMBOL(left)->rname, AOP_TYPE(left));
+ if (!IS_TRUE_SYMOP(left) && OP_SYMBOL(left)->usl.spillLoc)
+ {
+ emitcode(";", "\taka %s", OP_SYMBOL(left)->usl.spillLoc->rname);
+ }
+ }
+ if (IS_SYMOP(result) && OP_SYMBOL(result)->aop)
+ {
+ emitcode(";", "result (%s) is %d", OP_SYMBOL(result)->rname, AOP_TYPE(result));
+ if (!IS_TRUE_SYMOP(result) && OP_SYMBOL(result)->usl.spillLoc)
+ {
+ emitcode(";", "\taka %s", OP_SYMBOL(result)->usl.spillLoc->rname);
+ }
+ }
+#endif
+
#if VIEW_SIZE
emitcode ("; shift left ", "result %d, left %d", size,
AOP_SIZE (left));
/* I suppose that the left size >= result size */
if (shCount == 0)
- {
- while (size--)
+ {
+ _startLazyDPSEvaluation();
+ while (size--)
{
movLeft2Result (left, size, result, size, 0);
}
- }
-
+ _endLazyDPSEvaluation();
+ }
else if (shCount >= (size * 8))
+ {
+ _startLazyDPSEvaluation();
while (size--)
+ {
aopPut (AOP (result), zero, size);
+ }
+ _endLazyDPSEvaluation();
+ }
else
- {
+ {
switch (size)
{
case 1:
break;
case 2:
- case 3: /* bug: this is for generic pointers, I bet. */
genlshTwo (result, left, shCount);
break;
-
+#if 0
case 4:
genlshFour (result, left, shCount);
break;
+#endif
+ default:
+ fprintf(stderr, "*** ack! mystery literal shift!\n");
+ break;
}
}
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
+ return TRUE;
}
#endif
aopOp (right, ic, FALSE, FALSE);
-#if 0
+
+#ifdef BETTER_LITERAL_SHIFT
/* if the shift count is known then do it
as efficiently as possible */
if (AOP_TYPE (right) == AOP_LIT)
{
- genLeftShiftLiteral (left, right, result, ic);
- return;
+ if (genLeftShiftLiteral (left, right, result, ic))
+ {
+ return;
+ }
}
#endif
freeAsmop (result, NULL, ic, TRUE);
}
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* genrshOne - right shift a one byte quantity by known count */
/*-----------------------------------------------------------------*/
genrshOne (operand * result, operand * left,
int shCount, int sign)
{
- D (emitcode (";", "genrshOne");
- );
+ D (emitcode (";", "genrshOne"););
shiftR1Left2Result (left, LSB, result, LSB, shCount, sign);
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* genrshTwo - right shift two bytes by known amount != 0 */
/*-----------------------------------------------------------------*/
genrshTwo (operand * result, operand * left,
int shCount, int sign)
{
- D (emitcode (";", "genrshTwo");
- );
+ D (emitcode (";", "genrshTwo"););
/* if shCount >= 8 */
if (shCount >= 8)
{
shCount -= 8;
+ _startLazyDPSEvaluation();
if (shCount)
+ {
shiftR1Left2Result (left, MSB16, result, LSB,
shCount, sign);
+ }
else
+ {
movLeft2Result (left, MSB16, result, LSB, sign);
+ }
addSign (result, MSB16, sign);
+ _endLazyDPSEvaluation();
}
/* 1 <= shCount <= 7 */
else
+ {
shiftR2Left2Result (left, LSB, result, LSB, shCount, sign);
+ }
}
#endif
}
#endif
-#if 0
-//REMOVE ME!!!
+#ifdef BETTER_LITERAL_SHIFT
/*-----------------------------------------------------------------*/
/* genRightShiftLiteral - right shifting by known count */
/*-----------------------------------------------------------------*/
-static void
+static bool
genRightShiftLiteral (operand * left,
operand * right,
operand * result,
int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit);
int size;
- D (emitcode (";", "genRightShiftLiteral");
- );
+ size = getSize (operandType (result));
+
+ D(emitcode (";", "genRightShiftLiteral (%d), size %d", shCount, size););
+
+ /* We only handle certain easy cases so far. */
+ if ((shCount != 0)
+ && (shCount < (size * 8))
+ && (size != 1)
+ && (size != 2))
+ {
+ D(emitcode (";", "genRightShiftLiteral wimping out"););
+ return FALSE;
+ }
freeAsmop (right, NULL, ic, TRUE);
AOP_SIZE (left));
#endif
- size = getDataSize (left);
/* test the LEFT size !!! */
/* I suppose that the left size >= result size */
if (shCount == 0)
- {
+ {
size = getDataSize (result);
+ _startLazyDPSEvaluation();
while (size--)
+ {
movLeft2Result (left, size, result, size, 0);
- }
-
+ }
+ _endLazyDPSEvaluation();
+ }
else if (shCount >= (size * 8))
{
if (sign)
+ {
/* get sign in acc.7 */
MOVA (aopGet (AOP (left), size - 1, FALSE, FALSE, TRUE));
+ }
addSign (result, LSB, sign);
}
else
case 2:
genrshTwo (result, left, shCount, sign);
break;
-
+#if 0
case 4:
genrshFour (result, left, shCount, sign);
break;
+#endif
default:
break;
}
freeAsmop (left, NULL, ic, TRUE);
freeAsmop (result, NULL, ic, TRUE);
}
+ return TRUE;
}
#endif
aopOp (right, ic, FALSE, FALSE);
-#if 0
+#ifdef BETTER_LITERAL_SHIFT
if (AOP_TYPE (right) == AOP_LIT)
{
- genRightShiftLiteral (left, right, result, ic, 1);
- return;
+ if (genRightShiftLiteral (left, right, result, ic, 1))
+ {
+ return;
+ }
}
#endif
/* shift count is unknown then we have to form
aopOp (right, ic, FALSE, FALSE);
-#if 0
+#ifdef BETTER_LITERAL_SHIFT
/* if the shift count is known then do it
as efficiently as possible */
if (AOP_TYPE (right) == AOP_LIT)
{
- genRightShiftLiteral (left, right, result, ic, 0);
- return;
+ if (genRightShiftLiteral (left, right, result, ic, 0))
+ {
+ return;
+ }
}
#endif
/* This is a net loss for size == 1, but a big gain
* otherwise.
*/
- D (emitcode (";", "genFarFarAssign (improved)");
- );
+// #define BETTER_FAR_FAR_ASSIGN
+#ifdef BETTER_FAR_FAR_ASSIGN
+ if ((IS_SYMOP(result) && OP_SYMBOL(result) && OP_SYMBOL(result)->rname)
+ && (IS_TRUE_SYMOP(result)
+ || (IS_ITEMP(result) && OP_SYMBOL(result)->isspilt && OP_SYMBOL(result)->usl.spillLoc->rname)))
+ {
+ D(emitcode(";","genFarFarAssign ('390 auto-toggle fun)"););
+ emitcode("mov", "dps, #21"); /* Select DPTR2 & auto-toggle. */
+ if (IS_TRUE_SYMOP(result))
+ {
+ emitcode ("mov", "dptr,#%s", OP_SYMBOL(result)->rname);
+ }
+ else
+ {
+ emitcode ("mov", "dptr,#%s", OP_SYMBOL(result)->usl.spillLoc->rname);
+ }
+ /* DP2 = result, DP1 = right, DP1 is current. */
+ while (size)
+ {
+ emitcode("movx", "a,@dptr");
+ emitcode("movx", "@dptr,a");
+ if (--size)
+ {
+ emitcode("inc", "dptr");
+ emitcode("inc", "dptr");
+ }
+ }
+ emitcode("mov", "dps, #0");
+ }
+ else
+#endif
+ {
+ D (emitcode (";", "genFarFarAssign (improved)"););
aopOp (result, ic, TRUE, TRUE);
_startLazyDPSEvaluation ();
+
while (size--)
{
aopPut (AOP (result),
}
_endLazyDPSEvaluation ();
freeAsmop (result, NULL, ic, FALSE);
+ }
freeAsmop (right, NULL, ic, FALSE);
}
else
{
- D (emitcode (";", "genFarFarAssign ");
- );
+ D (emitcode (";", "genFarFarAssign "););
/* first push the right side on to the stack */
_startLazyDPSEvaluation ();
(AOP_TYPE (right) == AOP_LIT) &&
!IS_FLOAT (operandType (right)))
{
- D (emitcode (";", "Kevin's better literal load code");
- );
_startLazyDPSEvaluation ();
while (size && ((unsigned int) (lit >> (offset * 8)) != 0))
{