freeAsmop (IC_RESULT (ic), NULL, ic);
}
+/*-----------------------------------------------------------------*/
+/* genMultChar - generates code for unsigned 8x8 multiplication */
+/*-----------------------------------------------------------------*/
+static void
+genMultOneChar (iCode * ic)
+{
+ symbol *tlbl1, *tlbl2;
+ bool savedB = FALSE;
+
+ if(IS_GB)
+ {
+ wassertl (0, "Multiplication is handled through support function calls on gbz80");
+ return;
+ }
+
+ /* Save b into a if b is in use. */
+ if (bitVectBitValue (ic->rMask, B_IDX) &&
+ !(getPairId (AOP (IC_RESULT (ic))) == PAIR_BC))
+ {
+ emit2 ("ld a, b");
+ savedB = TRUE;
+ }
+ if (isPairInUse (PAIR_DE, ic) &&
+ !(getPairId (AOP (IC_RESULT (ic))) == PAIR_DE))
+ {
+ _push (PAIR_DE);
+ _G.stack.pushedDE = TRUE;
+ }
+
+ tlbl1 = newiTempLabel (NULL);
+ tlbl2 = newiTempLabel (NULL);
+
+ emit2 ("ld e,%s", aopGet (AOP (IC_RIGHT (ic)), LSB, FALSE));
+ emit2 ("ld h,%s", aopGet (AOP (IC_LEFT (ic)), LSB, FALSE));
+ emit2 ("ld l,#0x00");
+ emit2 ("ld d,l");
+ emit2 ("ld b,#0x08");
+ emitLabel (tlbl1->key + 100);
+ emit2 ("add hl,hl");
+ emit2 ("jp NC,!tlabel", tlbl2->key + 100);
+ emit2 ("add hl,de");
+ emitLabel (tlbl2->key + 100);
+ emit2 ("djnz !tlabel", tlbl1->key + 100);
+
+ spillPair(PAIR_HL);
+
+ if (IS_Z80 && _G.stack.pushedDE)
+ {
+ _pop (PAIR_DE);
+ _G.stack.pushedDE = FALSE;
+ }
+ if (savedB)
+ {
+ emit2 ("ld b, a");
+ }
+
+ if (AOP_SIZE (IC_RESULT (ic)) == 1)
+ aopPut (AOP (IC_RESULT (ic)), "l", 0);
+ else
+ commitPair ( AOP (IC_RESULT (ic)), PAIR_HL);
+
+ freeAsmop (IC_LEFT (ic), NULL, ic);
+ freeAsmop (IC_RIGHT (ic), NULL, ic);
+ freeAsmop (IC_RESULT (ic), NULL, ic);
+}
+
/*-----------------------------------------------------------------*/
/* genMult - generates code for multiplication */
/*-----------------------------------------------------------------*/
IC_LEFT (ic) = t;
}
+ if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT)
+ {
+ genMultOneChar (ic);
+ return;
+ }
+
wassertl (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT, "Right must be a literal");
val = (int) ulFromVal ( AOP (IC_RIGHT (ic))->aopu.aop_lit);
letype = getSpec (operandType (left));
retype = getSpec (operandType (right));
sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the amsops */
+ /* assign the asmops */
aopOp (left, ic, FALSE, FALSE);
aopOp (right, ic, FALSE, FALSE);
aopOp (result, ic, TRUE, FALSE);
+ setupToPreserveCarry (ic);
+
genCmp (right, left, result, ifx, sign);
+ _G.preserveCarry = FALSE;
freeAsmop (left, NULL, ic);
freeAsmop (right, NULL, ic);
freeAsmop (result, NULL, ic);
retype = getSpec (operandType (right));
sign = !(SPEC_USIGN (letype) | SPEC_USIGN (retype));
- /* assign the amsops */
+ /* assign the asmops */
aopOp (left, ic, FALSE, FALSE);
aopOp (right, ic, FALSE, FALSE);
aopOp (result, ic, TRUE, FALSE);
+ setupToPreserveCarry (ic);
+
genCmp (left, right, result, ifx, sign);
+ _G.preserveCarry = FALSE;
freeAsmop (left, NULL, ic);
freeAsmop (right, NULL, ic);
freeAsmop (result, NULL, ic);
else
{
/* we need to extend the sign :{ */
- const char *l = aopGet (AOP (right), AOP_SIZE (right) - 1,
- FALSE);
+ const char *l = aopGet (AOP (right), AOP_SIZE (right) - 1, FALSE);
_moveA (l);
emit2 ("rla ");
emit2 ("sbc a,a");
}
}
-/* The problem is that we may have all three pairs used and they may
- be needed in a different order.
-
- Note: Have ex de,hl
-
- Combinations:
- hl = hl => unity, fine
- bc = bc
- de = de
-
- hl = hl hl = hl, swap de <=> bc
- bc = de
- de = bc
-
- hl = bc Worst case
- bc = de
- de = hl
-
- hl = bc de = de, swap bc <=> hl
- bc = hl
- de = de
-
- hl = de Worst case
- bc = hl
- de = bc
-
- hl = de bc = bc, swap hl <=> de
- bc = bc
- de = hl
-
- Break it down into:
- * Any pair = pair are done last
- * Any pair = iTemp are done last
- * Any swaps can be done any time
-
- A worst case:
- push p1
- p1 = p2
- p2 = p3
- pop p3
-
- So how do we detect the cases?
- How about a 3x3 matrix?
- source
- dest x x x x
- x x x x
- x x x x (Fourth for iTemp/other)
-
- First determin which mode to use by counting the number of unity and
- iTemp assigns.
- Three - any order
- Two - Assign the pair first, then the rest
- One - Swap the two, then the rest
- Zero - Worst case.
-*/
static void
setupForBuiltin3 (iCode *ic, int nparams, operand **pparams)
{
PAIR_ID ids[NUM_PAIRS][NUM_PAIRS];
PAIR_ID dest[3] = {
- PAIR_BC, PAIR_HL, PAIR_DE
+ PAIR_DE, PAIR_HL, PAIR_BC
};
int i, j, nunity = 0;
memset (ids, PAIR_INVALID, sizeof (ids));
/* Sanity checks */
wassert (nparams == 3);
- /* First save everything that needs to be saved. */
- _saveRegsForCall (ic, 0);
-
- /* Loading HL first means that DE is always fine. */
for (i = 0; i < nparams; i++)
{
aopOp (pparams[i], ic, FALSE, FALSE);
}
else if (nunity == 2)
{
- /* One is assigned. Pull it out and assign. */
+ /* Two are OK. Assign the other one. */
for (i = 0; i < 3; i++)
{
for (j = 0; j < NUM_PAIRS; j++)
}
else if (nunity == 1)
{
- /* Find the pairs to swap. */
+ /* One is OK. Find the other two. */
for (i = 0; i < 3; i++)
{
for (j = 0; j < NUM_PAIRS; j++)
{
if (j == PAIR_INVALID || j == dest[i])
{
- /* Keep looking. */
+ /* This one is OK. */
}
else
{
- _swap (j, dest[i]);
- goto done;
+ /* Found one. */
+ if(ids[j][dest[i]] == TRUE)
+ {
+ /* Just swap. */
+ _swap (j, dest[i]);
+ goto done;
+ }
+ else
+ {
+ fetchPair (dest[i], AOP (pparams[i]));
+ continue;
+ }
}
}
}
}
}
-static void
+/*static void
genBuiltInStrcpy (iCode *ic, int nParams, operand **pparams)
{
operand *from, *to;
deInUse = bitVectBitValue (ic->rMask, D_IDX) || bitVectBitValue(ic->rMask, E_IDX);
+ _saveRegsForCall (ic, 0);
+
setupForBuiltin3 (ic, nParams, pparams);
label = newiTempLabel(NULL);
freeAsmop (from, NULL, ic->next);
freeAsmop (to, NULL, ic);
-}
+}*/
static void
genBuiltInMemcpy (iCode *ic, int nParams, operand **pparams)
{
operand *from, *to, *count;
- bool deInUse;
- wassertl (nParams == 3, "Built-in memcpy must have two parameters");
+ wassertl (nParams == 3, "Built-in memcpy must have three parameters");
to = pparams[2];
from = pparams[1];
count = pparams[0];
- deInUse = bitVectBitValue (ic->rMask, D_IDX) || bitVectBitValue(ic->rMask, E_IDX);
+ _saveRegsForCall (ic, 0);
setupForBuiltin3 (ic, nParams, pparams);
/* which function is it */
bif = OP_SYMBOL(IC_LEFT(bi_iCode));
- if (strcmp(bif->name,"__builtin_strcpy")==0)
+ /*if (strcmp(bif->name,"__builtin_strcpy")==0)
{
genBuiltInStrcpy(bi_iCode, nbi_parms, bi_parms);
}
- else if (strcmp(bif->name,"__builtin_memcpy")==0)
+ else*/ if (strcmp(bif->name,"__builtin_memcpy")==0)
{
genBuiltInMemcpy(bi_iCode, nbi_parms, bi_parms);
}