pass.c 11.5 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
#include <stdio.h>
#include <vudefs.h>
#include <vutable.h>
#include <math.h>

#define ROM_ADRS 9
#define ROM_DATA 16
#define ROM_DEPTH (1<<ROM_ADRS)
#define ROM_WIDTH (1<<ROM_DATA)

u16 vs[8], vt[8], vd[8], in_vco, el, out_vco, in_vcc, out_vcc;
u8  in_vce, out_vce;
i64 vacc[8], vacc_B[8],dp_res[8];
u16  out_vaccl[8], out_vaccm[8], out_vacch[8];
u16  in_vaccl[8], in_vaccm[8], in_vacch[8];

u32 div_in[8],div_out[8];
u32 dp_vs[8],dp_vt[8];
u16 vdh[8],vdl[8],vth[8],vtl[8],vsh[8],vsl[8];
int div_in_pntr;
int div_vsh[8],div_vsl[8],div_elh[8],div_ell[8];

int div_vsh_offset,div_elh_offset;

u16 rom[1024];


u16 data[2048];
int data_pntr;

int test_num;
int index, opindex, elindex, rtabindex, ridx;
char el_sf[10];

char prog_name[]="NO NAME IS ASSIGNED YET";



char    line[256],fld[12][50];

int div_op;
int dp_mul_op;

pass(fp1,fp2,fp3)
FILE *fp1,*fp2,*fp3;
{

 int ln_num,i;
 int err;
 i64 tacc;

 cleanup();

 index, opindex, elindex = 0;
 
 test_num = ln_num = data_pntr = rtabindex = ridx = 0; 
 
 div_vsh_offset = div_elh_offset = 0;

 for (i=0; i<8; i++) {vacc[i] = 0; vacc_B[i] = 0;}

 init_rom();


 while(NULL != fgets(line,255,fp1))
   {
    fprintf(fp3,"%s",line);

    for (i = 0; i<12; i++) fld[i][0] = '\0';
    sscanf(line,"%s %s %s %s %s %s %s %s %s %s %s %s",
	         fld[0],fld[1],fld[2],fld[3],fld[4],fld[5],
	         fld[6],fld[7],fld[8],fld[9],fld[10],fld[11]);

    ln_num += 1;
    err = 0;

    if (tab_lookup(fld[0], &index))
       switch (tab[index].enu_name)
	{
	case V_SRC: for (i=0;i<8;i++) vs[i] = (u16) getnum(&fld[i+1],&err); 
		    break;
	case V_TRG: for (i=0;i<8;i++) vt[i] = (u16) getnum(&fld[i+1],&err); 
		    break;
        case V_DDATA: div_in_pntr = getnum(&fld[1],&err); 
		      div_in[div_in_pntr] = (u32) getnum(&fld[2],&err); 
		      if (optab[opindex].enu_name==DP_MUL) {
			dp_vs[div_in_pntr] = div_in[div_in_pntr];
			dp_vt[div_in_pntr] = (u32) getnum(&fld[3],&err);
			}
		     break;
	case INVCO: in_vco = (u16) getnum(&fld[1],&err); 
		    break;
	case INVCE:in_vce = (u16)getnum(&fld[1],&err) & 0xff; 
		     break;
	case INVCO_H:in_vco = in_vco&0x00ff|(u16)getnum(&fld[1],&err)<<8; 
		     break;
	case INVCO_L:in_vco = in_vco&0xff00|(u16)getnum(&fld[1],&err)&0xff;
		    break;
	case INVCC: in_vcc = (u16) getnum(&fld[1],&err); 
		    break;
	case V_ELM: err = !eltab_lookup(fld[1], &elindex);
		    el = eltab[elindex].el_value;
		    strcpy(el_sf,eltab[elindex].sub_field);
		    break;

        case V_ACCL: for (i=0;i<8;i++) 
		      {
			tacc = (u32) getnum(&fld[i+1],&err);
			vacc[i] = (vacc[i] & 0xffffffffffff0000) | tacc;
		      }
		    break;
        case V_ACCM: for (i=0;i<8;i++) 
		      {
			tacc = (u32) getnum(&fld[i+1],&err);
			vacc[i] = (vacc[i] & 0xffffffff0000ffff) | (tacc<<16);
		      }
		    break;
        case V_ACCH: for (i=0;i<8;i++) 
		      {
			tacc = (i16) getnum(&fld[i+1],&err);
			vacc[i] = (vacc[i]&0x00000000ffffffff) | 
							(i64)(tacc<<32);
		      }
		    break;

	case OPER:  err = !optab_lookup(fld[1], &opindex) ;
		    break;
	case PROG_NAME:  strcpy(prog_name,fld[1]);
		    break;
	case R_ASSIGN:  err = !regtab_lookup(fld[1], &rtabindex);
			if (!err) 
			  err = !ridx_lookup(fld[2], &ridx);
			if (!err) 
			  regtab[rtabindex].rnum = reg_index[ridx].enu_name;
		        break;
	case VSH_OFF:  div_vsh_offset = getnum(&fld[1],&err);
		        break;

	case ELH_OFF:  div_elh_offset = getnum(&fld[1],&err);
		        break;

	case END:  for (i=0; i<8; i++) vacc_B[i] = vacc[i];
	           call_operations(fp2); 
		   print_results(fp3);
		   div_op = 0;
		   dp_mul_op = 0;
		    break;

	case START:/* cleanup(); */
		    test_num+=1;
		    for (i=0; i<8; i++) {
			div_in[i] = 0;
			dp_vs[i] = 0;
			dp_vt[i] = 0;
			}
		    break;
	default:    break;
	}

     else
	if (fld[0][0] != ';' && fld[0][0] != '\0')
	    {
	    err = 1;
	    printf ("**ERROR line:%d  \n", ln_num);
            printf("%s %s %s %s %s %s %s %s %s %s %s %s ", 
	         fld[0],fld[1],fld[2],fld[3],fld[4],fld[5],
	         fld[6],fld[7],fld[8],fld[9],fld[10],fld[11]);
	    }
    if (err)
       {
        printf ("**ERROR line:%d  \n", ln_num);
        printf("%s %s %s %s %s %s %s %s %s %s %s %s ", 
             fld[0],fld[1],fld[2],fld[3],fld[4],fld[5],
             fld[6],fld[7],fld[8],fld[9],fld[10],fld[11]);
       }

   if (ln_num==1) prolog(fp2);

   }/*while*/

   epilog(fp2);
   dump_data(fp2);
}

cleanup()
   {
   int i;

    for (i=0; i<8; i++)
      {
      vs[i] = vt[i] = vd[i] = 0;
      in_vco = out_vco = el = 0;
      }
   }

int tab_lookup(in_str, index)
       char *in_str;
       int *index;
	{
	 int i,found;

          found = 0;	
	  for (i=0; i<TAB_SIZE; i++)
	    if (!strcmp(in_str,tab[i].name))
		{
		*index = i;
		found = 1;
		}
           return (found);
	}	
int optab_lookup(in_str, index)
       char *in_str;
       int *index;
	{
	 int i,found;
	
          found = 0;
	  for (i=0; i<OPTAB_SIZE; i++)
	    if (!strcmp(in_str,optab[i].name))
		{
		*index = i;
		found = 1;
		}
	  return (found);
	}	
int regtab_lookup(in_str, index)
       char *in_str;
       int *index;
	{
	 int i,found;
	
          found = 0;
	  for (i=0; i<REGTAB_SIZE; i++)
	    if (!strcmp(in_str,regtab[i].name))
		{
		*index = i;
		found = 1;
		}
	  return (found);
	}	
int ridx_lookup(in_str, index)
       char *in_str;
       int *index;
	{
	 int i,found;
	
          found = 0;
	  for (i=0; i<RIDX_SIZE; i++)
	    if (!strcmp(in_str,reg_index[i].name))
		{
		*index = i;
		found = 1;
		}
	  return (found);
	}	
int eltab_lookup(in_str, index)
       char *in_str;
       int *index;
	{
	 int i,found;
	
          found = 0;
	  for (i=0; i<ELTAB_SIZE; i++)
	    if (!strcmp(in_str,eltab[i].name))
		{
		*index = i;
		found = 1;
		}
	  return (found);
	}	

i16 get_ti(int i)
 {

  i16 ti;

       if (el==0) ti = (i16) vt[i];                    /*vector*/
  else if (el<4)  ti = (i16) vt[(i&0xe) + (el&0x1)] ;  /*sclr q*/
  else if (el<8)  ti = (i16) vt[(i&0xc) + (el&0x3)] ;  /*sclr h*/
  else if (el<16) ti = (i16) vt[(i&0x8) + (el&0x7)] ;  /*sclr w*/

  return (ti);
	

 }


call_operations(fp)
FILE *fp;
 {

    switch (optab[opindex].enu_name)   
     {
      case VADD: 
      case VSUB:
      case VSUT:
      case VABS:
      case VADDC:
      case VSUBC: vadd(fp); break;

      case VADDB: 
      case VSUBB:
      case VACCB:
      case VSUCB: vaddb(fp); break;

      case VSAD: 
      case VSAC:  vsad(fp); break;

      case VSUM:  vsum(fp); break;
      case VSAW:  vsaw(fp); break;

      case VAND:
      case VNAND:
      case VOR: 
      case VNOR:
      case VXOR:
      case VXNOR: vlog(fp); break;

      case VLT:
      case VEQ:
      case VNE:
      case VGE:
      case VMRG: vcmp(fp); break;

      case VCH:
      case VCL:
      case VCR:  vcl(fp);  break;

      case VMULF: 
      case VMACF:
      case VMULU:
      case VMACU:  vmulfu(fp); break;

      case VMULQ:
      case VMACQ:  vmulq(fp); break;

      case VRNDP:
      case VRNDN:  vrndpn(fp); break;

      case VMUDL:
      case VMADL:
      case VMUDM:
      case VMADM:
      case VMUDN:
      case VMADN:
      case VMUDH:
      case VMADH:  vmuldbl(fp); break;

      case VINS_T:
      case VINS_Q:
      case VINS_N:
      case VEXT_T:
      case VEXT_Q:
      case VEXT_N:  vins(fp); break;
      
      case SP_RECP:
      case SP_SQRT:
      case DP_RECP:
      case DP_SQRT:
      case DP_RECP_CHAIN:
      case DP_SQRT_CHAIN: div_op=1; divide(fp); break;

      case VMOV: vmov(fp); break;
      case DP_MUL: dp_mul_op=1; dp_mul(fp); break;

      case INIT_DIV: 
		    fprintf(fp,"\n\n"); 
		    fprintf(fp,optab[opindex].op_tmplt); 
		    fprintf(fp,"\n\n"); 
		    break; 

      default: break;
     } 
  }
print_results(fp)
FILE *fp;
 {
  int i;
  char buffer[20];

  fprintf(fp,"***********\n");
  fprintf(fp,"* RESULTS *\n");
  fprintf(fp,"***********\n");
  fprintf(fp,"\n");
  fprintf(fp,"test_number =  0x%2.2X \n",test_num);
  fprintf(fp,"\n");

  if (!div_op&&!dp_mul_op)
   {
    fprintf(fp,"vD   ");

    for (i=0; i<8; i++) fprintf(fp," 0x%4.4X",vd[i]);
    fprintf(fp,"\n");
    fprintf(fp,"\n");
  
    fprintf(fp,"VCC   0x%4.4X -> ",out_vcc);
    itobichst((out_vcc&0xff00)>>8,&buffer,8); fprintf(fp," %s",buffer);
    itobichst((out_vcc&0x00ff)>>0,&buffer,8); fprintf(fp,"_%s (bin) \n",buffer);
  
    fprintf(fp,"VCO   0x%4.4X -> ",out_vco);
    itobichst((out_vco&0xff00)>>8,&buffer,8); fprintf(fp," %s",buffer);
    itobichst((out_vco&0x00ff)>>0,&buffer,8); fprintf(fp,"_%s (bin) \n",buffer);
    fprintf(fp,"\n");
  
    fprintf(fp,"VCE   0x%2.2X -> ",out_vce);
    itobichst((out_vce&0xff)>>0,&buffer,8); fprintf(fp,"%s (bin) \n",buffer);
    fprintf(fp,"\n");
  
  
    for (i=0; i<8; i++) fprintf(fp,"ACC[%d]     0x%12.12llx \n",i,vacc[i]);
    fprintf(fp,"\n");
    }
  else
  if (div_op)
    {
    for (i=0; i<8; i++)
      {
       fprintf(fp,"dData[%d] = %08X, result = %08X vTH=$v%-d[%-d], vTL=$v%-d[%-d], vDH=$v%-d[%-d], vDL=$v%-d[%-d]\n",i,div_in[i],div_out[i],
         regtab[VTH].rnum,div_elh[i],regtab[VTL].rnum,div_ell[i],
         regtab[VDH].rnum,div_vsh[i],regtab[VDL].rnum,div_vsl[i]
	);
       }

    fprintf(fp,"\n");

    fprintf(fp,"vTH   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4X",vth[i]);
    fprintf(fp,"\n");
    fprintf(fp,"vTL   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4X",vtl[i]);
    fprintf(fp,"\n");

    fprintf(fp,"vDH   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4X",vdh[i]);
    fprintf(fp,"\n");
    fprintf(fp,"vDL   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4X",vdl[i]);
    fprintf(fp,"\n");

    }
  else
    {
    for (i=0; i<8; i++)
       fprintf(fp,"dData[%d] vs:0x%8.8x, vt:0x%8.8x, result=0x%16.16llx \n",i,dp_vs[i], dp_vt[i], dp_res[i]); 

    fprintf(fp,"\n");

    fprintf(fp,"vSH   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4x",vsh[i]);
    fprintf(fp,"\n");
    fprintf(fp,"vSL   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4x",vsl[i]);
    fprintf(fp,"\n");
    fprintf(fp,"vTH   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4x",vth[i]);
    fprintf(fp,"\n");
    fprintf(fp,"vTL   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4x",vtl[i]);
    fprintf(fp,"\n");

    fprintf(fp,"vDH   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4x",vdh[i]);
    fprintf(fp,"\n");
    fprintf(fp,"vDL   ");
    for (i=0; i<8; i++) fprintf(fp," 0x%4.4x",vdl[i]);
    fprintf(fp,"\n");

    }

  }

init_rom()
{

int i, j;
float F1,F2;
  /*********************************************
   * reciprocal  Input is 1 : (2-e)
   **********************************************/
  rom[0] = (2*ROM_WIDTH)-1;   /* maximum value */
  for (i=1; i<ROM_DEPTH; i++) {
           F1 = (float) ROM_DEPTH/(ROM_DEPTH+i) ;
           F2 = (float) 2.0 * ROM_WIDTH * F1;
           rom[i] = (int)(F2);
          }
  /*********************************************
   * 1/sqrt Input is 1 : (2-e)
   **********************************************/
  rom[513] = (2*ROM_WIDTH)-1;   /* maximum value */
  for (i=1; i<ROM_DEPTH/2; i++) {
           j = i*2 ;
           F1 = (float) ROM_DEPTH/(ROM_DEPTH+j) ;
           F2 = (float) 2.0 * ROM_WIDTH*sqrtf(F1);
           rom[513+j] = (int)(F2);
           }
  /*********************************************
   *1/sqrt  Input is 2 : (4-e)
   **********************************************/
  F1 = 0.5;
  F2 = (float)  2.0 * ROM_WIDTH*sqrtf(F1);
  rom[512] = (int)(F2);
  for (i=1; i<ROM_DEPTH/2; i++) {
           j = i*2 ;
           F1 = (float) ROM_DEPTH/((float) 2.0*(ROM_DEPTH+j)) ;
           F2 = (float) 2.0 * ROM_WIDTH*sqrtf(F1);
           rom[512+j] = (int)(F2);
           }

/*
 *for (i=0; i<1024; i++)
 * {
 *  float F3;
 *  F3 = (float) (rom[i] + 0x10000)/0x20000;
 *  printf("i = %x, data = %x, F3=%f \n", i , rom[i], F3);
 * }
 */

}