-/*-----------------------------------------------------------------*
- * pic_genUMult8XLit_16 - unsigned multiplication of two 8-bit numbers.
- *
- *
- *-----------------------------------------------------------------*/
-void pic16_genUMult8XLit_16 (operand *left,
- operand *right,
- operand *result,
- pCodeOpReg *result_hi)
-
-{
-
- unsigned int lit;
- unsigned int i,have_first_bit;
- int same;
- pCodeOp *temp;
-
- if (AOP_TYPE(right) != AOP_LIT){
- fprintf(stderr,"%s %d - right operand is not a literal\n",__FILE__,__LINE__);
- exit(1);
- }
-
-
- if(!result_hi) {
- result_hi = PCOR(pic16_popGet(AOP(result),1));
- }
-
- lit = (unsigned int)floatFromVal(AOP(right)->aopu.aop_lit);
- lit &= 0xff;
- pic16_emitcode(";","Unrolled 8 X 8 multiplication");
-
- same = pic16_sameRegs(AOP(left), AOP(result));
-
- if(same) {
- switch(lit) {
- case 0:
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(left),0));
- return;
- case 2:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 3:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 4:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 5:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 5*F
- return;
- case 6:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 7:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 5*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 7*F
- return;
- case 8:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 5*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 8*F
- return;
- case 9:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 10:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 5*F
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 11:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 5*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 8*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 11*F
- return;
- case 12:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 13:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 5*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 8*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 13*F
- return;
- case 14:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 2*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 3*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 5*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 8*F
- pic16_emitpcode(POC_ADDFW, pic16_popGet(AOP(left),0)); // W = 11*F
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0)); // F = 14*F
- return;
- case 15:
- temp = pic16_popGetTempReg();
- if(!temp) {
- fprintf(stderr,"ERROR: unable to allocate register. %s:%d\n",__FUNCTION__,__LINE__);
- exit(1);
- }
- pic16_emitpcode(POC_SWAPFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVWF, temp);
- pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0xf0));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_SWAPFW, temp);
- pic16_emitpcode(POC_SUBWF, pic16_popGet(AOP(left),0));
- pic16_popReleaseTempReg(temp);
- return;
- case 16:
- pic16_emitpcode(POC_SWAPFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0xf0));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(left),0));
- return;
- case 17:
- pic16_emitpcode(POC_SWAPFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0xf0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(left),0));
- return;
- case 32:
- pic16_emitpcode(POC_SWAPF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_RLCFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0xe0));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(left),0));
- return;
- case 64:
- pic16_emitpcode(POC_SWAPF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_RLCF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_RLCFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_ANDLW, pic16_popGetLit(0xc0));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(left),0));
- return;
- case 128:
- pic16_emitpcode(POC_RRCFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(left),0));
- return;
-
- }
- } else {
-
- switch(lit) {
- case 0:
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),0));
- pic16_emitpcode(POC_CLRF, pic16_popCopyReg(result_hi));
- return;
- case 2:
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_MOVWF, pic16_popGet(AOP(result),0));
- pic16_emitpcode(POC_ADDWF, pic16_popGet(AOP(result),0));
- pic16_emitpcode(POC_CLRF, pic16_popCopyReg(result_hi));
- pic16_emitpcode(POC_RLCF, pic16_popCopyReg(result_hi));
- return;
- }
-
- }
-
- pic16_emitpcode(POC_MOVFW, pic16_popGet(AOP(left),0));
- pic16_emitpcode(POC_CLRF, pic16_popGet(AOP(result),0));
- pic16_emitpcode(POC_CLRF, pic16_popCopyReg(result_hi));
-
- have_first_bit = 0;
- for(i=0; i<8; i++) {
-
- if(lit & 1) {
- pic16_emitpcode(POC_ADDWF, pic16_popCopyReg(result_hi));
- have_first_bit = 1;
- }
-
- if(have_first_bit) {
- pic16_emitpcode(POC_RRCF, pic16_popCopyReg(result_hi));
- pic16_emitpcode(POC_RRCF, pic16_popGet(AOP(result),0));
- }
-
- lit >>= 1;
- }
-
-}
-