temp.c 2.09 KB
#include <stdio.h>

typedef signed char     i8;             /* signed */
typedef short int       i16;
typedef long int        i32;
typedef long long int   i64;

typedef unsigned char           u8;     /* unsigned */
typedef unsigned short int      u16;
typedef unsigned long int       u32;
typedef unsigned long long int  u64;


u16 vd[8], vs[8], vt[8], in_VCO,el;


main ()
 {
 int i;

    vs[0] = 0x0001;
    vs[1] = 0x000f;
    vs[2] = 0x00ff;
    vs[3] = 0x0fff;
    vs[4] = 0x7fff;
    vs[5] = 0xffff;
    vs[6] = 0x7ff0;
    vs[7] = 0xf000;

    vt[0] = 0x0001;
    vt[1] = 0x000f;
    vt[2] = 0x00ff;
    vt[3] = 0x0fff;
    vt[4] = 0x7fff;
    vt[5] = 0xffff;
    vt[6] = 0x7ff0;
    vt[7] = 0xf000;
    
 
    in_VCO = 0x55;

    for (i=0; i<16; i++) {
       if (i != 1) {
          el = (u16) i;
          printf("---------------------------- %x \n",el);
          Eval_vadd(); 
          printf("\n\n");
          }
      }

 }

Eval_vadd()
  {
    int         i, carry,of,uf;
    i16         si, ti;
    i32         di,di_save;


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

        if (in_VCO & (0x01 << i))
            carry = 1;
        else
            carry = 0;

        
        si = (i16) vs[i];

        if (el==0) 			/* vector */
	  ti = (i16) vt[i]; 
        else if (el<4) 			/* Scaler Quarter 0,1 */
	  ti = (i16) vt[(i&0xe) + (el&0x1)]; 
        else if (el<8) 			/* Scaler half 0,1,2,3 */
	  ti = (i16) vt[(i&0xc) + (el&0x3)]; 
        else if (el<16) 		/* Scaler whole 0,1,2,3,4,5,6,7 */
	  ti = (i16) vt[(i&0x8) + (el&0x7)]; 

        di = si - ti - carry;
        of = uf = 0;
        di_save = di;

        if (di > 0x00007fff) {
	    of = 1;
            di = 0x00007fff;
	    }
        if (di < -32768) {
	    uf = 1;
            di = -32768;
	    }

	vd[i] = (u16) di;

        printf("%x, %x,, %x, %x,,, %x, %x,,, %x, %x,,%x ",
	      			i, carry, vs[i], vt[i], si, ti,di_save, di,vd[i]) ;
        if (of) printf("... overflow\n");
	else
        if (uf) printf("... underflow\n");
	else
        printf("\n");
/*
        Set128By16(&(mp->result), (u16) di, i);
        rsp_VCO = UnFlag(rsp_VCO, (0x01 << i));
*/
    }
  }