vadd.c 10.2 KB
#include <stdio.h>
#include <vudefs.h>
/**************************************************************************
 * Used for vadd, vsub, vsut, vabs, vaddc, vsubc
 *          =====================================
 *
 * Check_Vadd  (tno, Op,  rMp, vS, vT, vT_El, vD, vDexp, vTemp,inVCO, outVCO)
 *
 **************************************************************************/

char *Templ_vadd_frmt = "( %2d, %s, $26, $v%-d, $v%-d, $v%-d%-s, $v%-d, $v%-d, $v%-d, 0x%4.4X, 0x%4.4X)\n";

vadd(fp)
FILE *fp;
  {
    int         i,j, carry, clamping;
    i16         si, ti;
    i32         di;
    
    clamping = optab[opindex].enu_name==VADD || 
               optab[opindex].enu_name==VSUB || 
               optab[opindex].enu_name==VSUT || 
               optab[opindex].enu_name==VABS ;

    for (i=0; i<8; i++) {

        carry =  (in_vco & (0x0001 << i)) ? 1 : 0;

        si = (i16) vs[i];

	ti = get_ti(i);

	     if (optab[opindex].enu_name==VADD) di = si + ti + carry;
	else if (optab[opindex].enu_name==VSUB) di = si - ti - carry;
	else if (optab[opindex].enu_name==VSUT) di = ti - si - carry;
	else if (optab[opindex].enu_name==VABS) {      if (si < 0)  di = -ti;
            					  else if (si == 0) di = si;
            				          else              di = ti;
	    					}
	else if (optab[opindex].enu_name==VADDC) {di = (si&0xffff) + (ti&0xffff); clamping = 0;}
	else  /*VSUBC*/			         {di = (si&0xffff) - (ti&0xffff); clamping = 0;}


        if (clamping) { if (di > 0x00007fff) di = 0x00007fff;
          		if (di < -32768)     di = -32768;
	  	      }

        vd[i] = (u16) di;

	if (optab[opindex].enu_name==VADDC) 
	   {out_vco &= ~(0x0101 << i);  
            out_vco |= 0x0000<<i;       /* set not-equal bits*/
            out_vco |= (di > 65535)<<i; /* set carry out bits*/
	   }
	else
	if (optab[opindex].enu_name==VSUBC)
	   {out_vco &= ~(0x0101 << i);  
                 if (di<0) out_vco |= (0x0101<<i);  /*(vs<vt)  set !Equal,  BorrowIn */
            else if (di>0) out_vco |= (0x0100<<i);  /*(vs>vt)  set !Equal, !BorrowIn */
            else           out_vco |= (0x0000<<i);  /*(vs==vt) set  Equal,  BorrowIn */
	   }
	else  
	if (optab[opindex].enu_name==VABS)
	   out_vco = in_vco;
	else  
	   out_vco = 0;

       } /*for*/
       
       if (data_pntr < (2048 - 100)) 
         {
           /* initidLize data segment starting at data_pntr */
           /* SRC, TRGT, RES, RES_ACCH, RES_ACCM, RES_ACCL */
           for (i=0;i<8;i++) {data[data_pntr++] = vs[i];}
           for (i=0;i<8;i++) {data[data_pntr++] = vt[i];}
           for (i=0;i<8;i++) {data[data_pntr++] = vd[i];}
	 }
       
	 fprintf(fp,optab[opindex].op_tmplt); 
         fprintf(fp,Templ_vadd_frmt,
		      	test_num, 
		      	optab[opindex].name,
		      	regtab[SRC].rnum,
		      	regtab[TRG].rnum,
		      	regtab[TRG].rnum,el_sf,
		      	regtab[DST].rnum,
		      	regtab[DST_EXP].rnum,
		      	regtab[TEMP].rnum,
		      	in_vco,
			out_vco);  


}/*vadd*/

/**************************************************************************
 * used by vaddb, vsubb, vaccb, vsucb
 *         ===========================
 *
 * Check_Vaddb(tno, Op, rMp,vS,vT,vT_El,vD,vDexp,vTemp,vAccl,vAccm,vAcch,
 *	                         vAcclExp,vAccmExp,vAcchExp,v4000,v0001)
 **************************************************************************/

char *Templ_vaddb_frmt = "( %2d, %s, $26, $v%-d, $v%-d, $v%-d%-s, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d)\n";

vaddb(fp)
FILE *fp;
{

    int         i,j, round;
    i32         si, ti, dLi, dHi, aHi, aLi;

    el = el & 0x7;
    round = (el==0) ? 0 : (1 << (el -1));    


    for (i=0; i<8; i++) {

        aLi = vacc[i]  & 0xffff;
        aLi <<= 16;
        aLi >>= 16;
	si = (i32) (vs[i] & 0xff);
	ti = (i32) (vt[i] & 0xff);
	dLi = (optab[opindex].enu_name==VADDB) ? si + ti + round :
	      (optab[opindex].enu_name==VSUBB) ? si - ti + round :
	      (optab[opindex].enu_name==VACCB) ? si + ti + aLi   :
	       					 si - ti + aLi;

        aHi = vacc[i]>>16;
        aHi <<= 16;
        aHi >>= 16;
	si = (i32) ((vs[i]>>8) & 0xff);
	ti = (i32) ((vt[i]>>8) & 0xff);
	dHi = (optab[opindex].enu_name==VADDB) ? si + ti + round :
	      (optab[opindex].enu_name==VSUBB) ? si - ti + round :
	      (optab[opindex].enu_name==VACCB) ? si + ti + aHi   :
	       					 si - ti + aHi;

	out_vaccl[i] = (u16) dLi;
	out_vaccm[i] = (u16) dHi;
	out_vacch[i] = 0;
	vacc[i] = (u32) ((out_vaccm[i]<<16) | out_vaccl[i]); 

	dLi = dLi >> el;
	dHi = dHi >> el;

	dLi = (dLi > 255) ? 255 : (dLi < 0)   ? 0   : dLi ;
	dHi = (dHi > 255) ? 255 : (dHi < 0)   ? 0   : dHi ;

        vd[i] = (u16) (((dHi<<8)&0xff00) | (dLi&0xff));

       } /*for*/
      
       if (data_pntr < (2048 - 100)) 
         {
           /* initidLize data segment starting at data_pntr */
           /* SRC, TRGT, RES, RES_ACCH, RES_ACCM, RES_ACCL */
           for (i=0;i<8;i++) data[data_pntr++] = vs[i];
           for (i=0;i<8;i++) data[data_pntr++] = vt[i];
           for (i=0;i<8;i++) data[data_pntr++] = vd[i];
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]    )&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]>>16)&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]>>32)&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = out_vaccl[i];
           for (i=0;i<8;i++) data[data_pntr++] = out_vaccm[i];
           for (i=0;i<8;i++) data[data_pntr++] = out_vacch[i];
	 }
       
	 fprintf(fp,optab[opindex].op_tmplt); 
         fprintf(fp,Templ_vaddb_frmt,
		      	test_num, 
		      	optab[opindex].name,
		      	regtab[SRC].rnum,
		      	regtab[TRG].rnum,
		      	regtab[TRG].rnum,el_sf,
		      	regtab[DST].rnum,
		      	regtab[DST_EXP].rnum,
		      	regtab[TEMP].rnum,
		      	regtab[ACCL].rnum,
		      	regtab[ACCM].rnum,
		      	regtab[ACCH].rnum,
		      	regtab[ACCL_EXP].rnum,
		      	regtab[ACCM_EXP].rnum,
		      	regtab[ACCH_EXP].rnum,
		      	regtab[V4000].rnum,
		      	regtab[V0001].rnum
		);  

}/*vaddb*/


/**************************************************************************
 * used by vsad, vsac
 *         ==========
 *
 * Check_Vsad(tno,Op,rMp,vS,vT,vD,vDexp,vTemp,vAccl,vAcclExp,v0001)
 **************************************************************************/
char *Templ_vsad_frmt = "( %2d, %s, $26, $v%-d, $v%-d, $v%-d%, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d)\n";

vsad(fp)
FILE *fp;
{
    int         i,j;
    i32         si, ti, diffL, diffH; 

    for (i=0; i<8; i++) {

	si = (i32) (vs[i] & 0xff);
	ti = (i32) (vt[i] & 0xff);
	diffL = si - ti;
	if (diffL < 0) diffL = (0 - diffL);

	si = (i32) ((vs[i]>>8) & 0xff);
	ti = (i32) ((vt[i]>>8) & 0xff);
	diffH = si - ti;
	if (diffH < 0) diffH = (0 - diffH);

	out_vaccl[i] = (optab[opindex].enu_name==VSAD) ? 
				(u16)(diffL + diffH) :
	       	        	(u16)(diffL + diffH + (u16)(vacc[i]&0xffff));

	vacc[i] = (u16) out_vaccl[i]; 

	vd[i] = vs[i];

       } /*for*/
       
       if (data_pntr < (2048 - 100)) 
         {
           /* initidLize data segment starting at data_pntr */
           /* SRC, TRGT, RES, RES_ACCH, RES_ACCM, RES_ACCL */
           for (i=0;i<8;i++) {data[data_pntr++] = vs[i];}
           for (i=0;i<8;i++) {data[data_pntr++] = vt[i];}
           for (i=0;i<8;i++) {data[data_pntr++] = vd[i];}
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]    )&0xffff;
           for (i=0;i<8;i++) {data[data_pntr++] = out_vaccl[i];}
	 }
       
	 fprintf(fp,optab[opindex].op_tmplt); 
         fprintf(fp,Templ_vsad_frmt,
		      	test_num, 
		      	optab[opindex].name,
		      	regtab[SRC].rnum,
		      	regtab[TRG].rnum,
		      	regtab[DST].rnum,
		      	regtab[DST_EXP].rnum,
		      	regtab[TEMP].rnum,
		      	regtab[ACCL].rnum,
		      	regtab[ACCL_EXP].rnum,
		      	regtab[V0001].rnum
		);  
}/*vsad*/

/**************************************************************************
 * used by vsum
 *         ====
 *
 * Check_Vsum(tno,rMp,vS,vT,vD,vDexp,vTemp,vAccl,vAccm,vAcch,v4000, v0001)
 **************************************************************************/
char *Templ_vsum_frmt = "( %2d,$26, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d)\n";


vsum(fp)
FILE *fp;
{

    int         i,j;
    i16         di;

       for (i=0; i<8; i++) vd[i] = 0x4000; /* Init the vd */

       di = 0; 
       for (i=0; i<8; i++) 
	    di = (i16) ((i16) di + (i16) (vacc[i] & 0xffff)); 
       vd[0] = di;
       
       if (data_pntr < (2048 - 100)) 
         {
           /* initidLize data segment starting at data_pntr */
           /* RES*/
           for (i=0;i<8;i++) {data[data_pntr++] = vd[i];}
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]    )&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]>>16)&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]>>32)&0xffff;
	 }
       
	 fprintf(fp,optab[opindex].op_tmplt); 
         fprintf(fp,Templ_vsum_frmt,
		      	test_num, 
		      	regtab[SRC].rnum,
		      	regtab[TRG].rnum,
		      	regtab[DST].rnum,
		      	regtab[DST_EXP].rnum,
		      	regtab[TEMP].rnum,
		      	regtab[ACCL].rnum,
		      	regtab[ACCM].rnum,
		      	regtab[ACCH].rnum,
		      	regtab[V4000].rnum,
		      	regtab[V0001].rnum
		);  

}/*vsaw*/
/**************************************************************************
 * used by vsaw
 *         ====
 *
 * Check_Vsaw(tno,rMp,vS,vT, vD,vTemp,vAccl,vAccm,vAcch,v4000, v0001);
 **************************************************************************/
char *Templ_vsaw_frmt = "( %2d,$26, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d, $v%-d)\n";


vsaw(fp)
FILE *fp;
{
    int         i;
       if (data_pntr < (2048 - 100)) 
         {
           /* initidLize data segment starting at data_pntr */
           /* RES*/
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]    )&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]>>16)&0xffff;
           for (i=0;i<8;i++) data[data_pntr++] = (u16)(vacc_B[i]>>32)&0xffff;
	 }
       
	 fprintf(fp,optab[opindex].op_tmplt); 
         fprintf(fp,Templ_vsaw_frmt,
		      	test_num, 
		      	regtab[SRC].rnum,
		      	regtab[TRG].rnum,
		      	regtab[DST].rnum,
		      	regtab[TEMP].rnum,
		      	regtab[ACCL].rnum,
		      	regtab[ACCM].rnum,
		      	regtab[ACCH].rnum,
		      	regtab[V4000].rnum,
		      	regtab[V0001].rnum
		);  

}/*vsaw*/