alu_www.c 5.49 KB
/****************************************************************
  WHAT:	RSP SCALAR UNIT TEST GENERATOR FOR ALU_WWW FORMAT
  SCCS: @(#)alu_www.c	1.1 03 Aug 1994
  FILE:	alu_www.c
   WHO:	Project Reality - Evan Y. Wang
   (C):	1994 Silicon Graphics, Inc.
 ****************************************************************/
#include <stdio.h>
#include "software.h"
#include "gen.h"
#include "suregre.h"

#define MAX_TCS	MAX_ALU_WWW_TCS

#define GenCase()						\
    fprintf(outp,Templ,CurTcNo,ip->name,rR,			\
	    HHW(Reg[rR]), LHW(Reg[rR]), rA, rB,			\
	    HHW(Res), LHW(Res), HHW(OpA), LHW(OpA),		\
	    HHW(OpB), LHW(OpB), rT);

PRIVATE	char *Templ =
    /* ChkAluWWW(  n,Op,   rR,  RValH,  RValL,   rA,   rB,   ResH,   ResL,   OpAH,   OpAL,   OpBH,   OpBL,   rT); */
    "\tChkAluWWW(%2d,%s,r%-2d,0x%4.4X,0x%4.4X,r%-2d,r%-2d,0x%4.4X,0x%4.4X,0x%4.4X,0x%4.4X,0x%4.4X,0x%4.4X,r%-2d)\n";

PRIVATE int AddWWW(outp, ip)
    FILE *outp;
    I_TABLE *ip;
{
    int i;

    /************************************************************
      Generate input patterns:  (0...010...0 Op 0...011...1)
     ************************************************************/
    for (i=0; OpA != 0x80000000; i++, CurTcNo++) {
	OpA = 1 << i;
	OpB = 0xFFFFFFFF >> (31-i);
	FILE_SPLIT {
	    Res = ip->proc(OpA,OpB);
	    GenCase();
	    UpdRegTABR();
	}
	UpdRegID();
    }

    /************************************************************
      Generate input patterns:  (1110...0111 Op 0011...1100)
     ************************************************************/
    OpA = 0x80000001;
    OpB = 0xFFFFFFFF;
    FILE_SPLIT {
	Res = ip->proc(OpA,OpB);
	GenCase();
	UpdRegTABR();
    }
    UpdRegID();
    CurTcNo++;

    for (i = 1; OpA != 0xFFFFFFFF; i++, CurTcNo++) {
	OpA |= (1<<i) | (0x80000000>>i);
	OpB = (0xFFFFFFFF >> (i+1) << (i+1) << i >> i) | 1;
	FILE_SPLIT {
	    Res = ip->proc(OpA,OpB);
	    GenCase();
	    UpdRegTABR();
	}
	UpdRegID();
    }

    /************************************************************
      Generate input patterns:  (1110...0111 Op 0010...0100)
     ************************************************************/
    for (i = 15; i >= 0; i--, CurTcNo++) {
	OpA = (0xFFFF >> (15-i)) | (0xFFFF0000 << (15-i));
	OpB = (1<<i) | (0x80000000>>i) | 1;
	FILE_SPLIT {
	    Res = ip->proc(OpA,OpB);
	    GenCase();
	    UpdRegTABR();
	}
	UpdRegID();
    }

    /************************************************************
      Generate some special patterns.
     ************************************************************/
    {
	PRIVATE u32 Aarray[] = { 0, 0x15555555, 0xAAAAAAAA, 0xFFFFFFFF };
	PRIVATE u32 Barray[] = { 0, 0x55555555, 0x2AAAAAAA, 0xFFFFFFFF };

	OpB = 0x55555555;
	for (i=0; i<4; i++, CurTcNo++) {
	    OpA = Aarray[i];
	    FILE_SPLIT {
		Res = ip->proc(OpA,OpB);
		GenCase();
		UpdRegTABR();
	    }
	    UpdRegID();
	}
    
	OpA = 0xAAAAAAAA;
	for (i=0; i<4; i++, CurTcNo++) {
	    OpB = Barray[i];
	    FILE_SPLIT {
		Res = ip->proc(OpA,OpB);
		GenCase();
		UpdRegTABR();
	    }
	    UpdRegID();
	}
    }
    return 0;
}   /* AddWWW */

PRIVATE int LogWWW(outp, ip)
    FILE *outp;
    I_TABLE *ip;
{
    /************************************************************
      Generate input patterns:  (0..010..010 Op 0xZZZZZZZZ)
      where Z = { 0, 1, ... 15 }
     ************************************************************/
    OpA = 0;
    for (CntA = 0; CntA < 4; CntA++) {
	for (CntB=0; CntB<6; CntB++, CurTcNo++) {
	    OpB = 0x41041041 << CntB;
	    FILE_SPLIT {
		Res = ip->proc(OpA,OpB);
		GenCase();
		UpdRegTABR();
	    }
	    UpdRegID();
	}
	OpA |= 0x11111111 << CntA;
    }

    for (CntA = 0; CntA < 4; CntA++) {
	for (CntB=0; CntB<6; CntB++, CurTcNo++) {
	    OpB = 0x41041041 << CntB;
	    FILE_SPLIT {
		Res = ip->proc(OpA,OpB);
		GenCase();
		UpdRegTABR();
	    }
	    UpdRegID();
	}
	OpA &= ~(0x11111111 << CntA);
    }

    return 0;
}   /* LogWWW */

PRIVATE int ShfWWW(outp, ip)
    FILE *outp;
    I_TABLE *ip;
{
    PRIVATE u32 patterns[] = { 0x01800180, 0x02400240, 0x04200420, 0x08100810,
			       0x10081008, 0x20042004, 0x40024002, 0x80018001 };

    OpB = 0;
    for (CntA=0; CntA<50; CntA++, CurTcNo++) {
	OpA = patterns[CntA&7];
	FILE_SPLIT {
	    Res = ip->proc(OpA,OpB);
	    GenCase();
	    UpdRegTABR();
	}
	UpdRegID();
	OpB++;
    }

    return 0;
}   /* ShfWWW */

PRIVATE int SetWWW(outp, ip)
    FILE *outp;
    I_TABLE *ip;
{
    int i = 0;

    OpA = OpB = 1;
    do {
	FILE_SPLIT {
	    Res = ip->proc(OpA,OpB);
	    GenCase();
	    UpdRegTABR();
	}
	UpdRegID();
	OpB <<= 1;
	OpB |= 1;
	OpA  = OpB ^ (i<32 ? 1<<i : 0);
    } while (i++, CurTcNo++, OpA != 0xFFFFFFFF || OpB != 0xFFFFFFFF);

    i = 0;
    OpA = OpB = 0x80000000;
    do {
	FILE_SPLIT {
	    Res = ip->proc(OpA,OpB);
	    GenCase();
	    UpdRegTABR();
	}
	UpdRegID();
	OpA <<= 1;
	OpA |= 0x80000001;
	OpB  = OpA ^ (i<32 ? 1<<i : 0);
    } while (i++, CurTcNo++, OpA != 0xFFFFFFFF || OpB != 0xFFFFFFFF);

    FILE_SPLIT {
	Res = ip->proc(OpA,OpB);
	GenCase();
    }
    return 0;

}   /* SetWWW */

int AluWWWGen(outp, ip)
    FILE *outp;			/* output file handle		*/
    I_TABLE *ip;		/* instruction table entry ptr	*/
{
    /* Generate default case - both operands zero */
    FILE_SPLIT {
	Res = ip->proc(OpA,OpB);
	GenCase();
	UpdRegTABR();
    }
    CurTcNo++;
    UpdRegID();

    switch (ip->vec) {
      case ADD_VEC:	return AddWWW(outp, ip);	break;
      case LOG_VEC:	return LogWWW(outp, ip);	break;
      case SHF_VEC:	return ShfWWW(outp, ip);	break;
      case SET_VEC:	return SetWWW(outp, ip);	break;
      default:		return 0;			break;
    }

}   /* AluWWWGen */