Esempio n. 1
0
void randomizePatterns_HOPE(level test_store[][MAXPI + 1], level test_store1[][MAXPI + 1], level test_vectors[][MAXPI + 1],
					  level test_vectors1[][MAXPI + 1], int iPacket, int iBit, int iNoPI)
{
	int array[40 * BITSIZE];
	int array1[40 * BITSIZE];
	int i, j, x, iGlobalBit, k, B, iBit_Local = 0, iPacket_Local = 0;
	int iMaxBitSize = BITSIZE;

	iGlobalBit = 32 * iPacket + iBit;
	for (i = 0; i < iGlobalBit; i++)
		array[i] = i;

	j = 0;
	for (i = iGlobalBit - 1; i >= 0; i--)
	{
		x = random() % (i + 1);
		array1[j] = array[x];
		array[x] = array[i];
		j++;
	}
	for (i = 0; i < iGlobalBit; i++)
	{
		x = array1[i];
		k = x / 32;
		B = x % 32;
		for (j = 0; j < iNoPI; j++)
		{
			if ((test_store[k][j] & BITMASK[B]) != ALL0)
			{
				setbit(test_vectors[iPacket_Local][j], iBit_Local);
			}
			else
			{
				resetbit(test_vectors[iPacket_Local][j], iBit_Local);
			}
			if ((test_store1[k][j] & BITMASK[B]) != ALL0)
			{
				setbit(test_vectors1[iPacket_Local][j], iBit_Local);
			}
			else
			{
				resetbit(test_vectors1[iPacket_Local][j], iBit_Local);
			}
		}
		if (++iBit_Local == iMaxBitSize)
		{
			iBit_Local = 0;
			iPacket_Local++;
		}
	}
}
Esempio n. 2
0
File: lgc.c Progetto: charleeli/srpc
static GCObject *udata2finalize (global_State *g) {
  GCObject *o = g->tobefnz;  /* get first element */
  lua_assert(tofinalize(o));
  g->tobefnz = o->next;  /* remove it from 'tobefnz' list */
  o->next = g->allgc;  /* return it to 'allgc' list */
  g->allgc = o;
  resetbit(o->marked, FINALIZEDBIT);  /* object is "normal" again */
  if (issweepphase(g))
    makewhite(g, o);  /* "sweep" object */
  return o;
}
Esempio n. 3
0
static GCObject *udata2finalize (global_State *g) {
	GCObject *o = g->tobefnz;  /* get first element */
	lua_assert(isfinalized(o));
	g->tobefnz = gch(o)->next;  /* remove it from 'tobefnz' list */
	gch(o)->next = g->allgc;  /* return it to 'allgc' list */
	g->allgc = o;
	resetbit(gch(o)->marked, SEPARATED);  /* mark that it is not in 'tobefnz' */
	lua_assert(!isold(o));  /* see MOVE OLD rule */
	if (!keepinvariantout(g))  /* not keeping invariant? */
	makewhite(g, o);  /* "sweep" object */
	return o;
}
Esempio n. 4
0
//random_test_fsim
void randomizePatterns_FSIM(level test_store[][MAXPI + 1], level test_vectors[][MAXPI + 1], int ipacket, int iBit,
	int iNoPI)
{
	//INPUT:  test_store, ipacket, iBit
	//OUTPUT:  test_vectors
	int array[MAXTEST *BITSIZE];
	int array1[MAXTEST *BITSIZE];
	int i, j, x, iGlobalBit, k, B, iBit_Local = 0, iPacket_Local = 0;
	int iMaxBitSize = BITSIZE;
	//FILE *fp;
	fprintf(stderr, "%d ", iNoPI);
	iNoPI = 3357; //what the hell is this??

	iGlobalBit = 32 * ipacket + iBit; //ipacket <= MAXTEST - 1, include ipacket, NOT include iBit !!!
	for (i = 0; i < iGlobalBit; i++)
		array[i] = i;

	j = 0;
	for (i = iGlobalBit - 1; i >= 0; i--)
	{
		x = random() % (i + 1);
		array1[j] = array[x];
		array[x] = array[i];
		j++;
	}
	for (i = 0; i < iGlobalBit; i++)
	{
		x = array1[i];
		k = x / 32;
		B = x % 32;
		for (j = 0; j < iNoPI; j++)
		{
			//fp=fopen("b18.trace","w");
			//fprintf(fp,"%d,%d\n",k,j);
			if ((test_store[k][j] & BITMASK[B]) != ALL0) //test_store[k][j].BITMASK[B] == 1!!
			{
				setbit(test_vectors[iPacket_Local][j], iBit_Local);
			}
			else
			{
				resetbit(test_vectors[iPacket_Local][j], iBit_Local);
			}
			//test_store -> test_vectors, totally number: iPacket_Local * 32 + iBit_Local
		}
		if (++iBit_Local == iMaxBitSize) //iMaxBitSize == 32 !!!
		{
			iBit_Local = 0;
			iPacket_Local++;
		}
	}
}
Esempio n. 5
0
int resetbitmap(int bit)
{
	int hang, lie;
	
	if(bit >= SIZEOFBITMAP)
		return -1;
		
	hang = bit / 8;
	lie = bit % 8;
	
	//bitmap[hang] &= (~(0x01<<lie));
	resetbit(bitmap[hang], lie);
	
	return 0;
}
Esempio n. 6
0
int shuffle_fsim(int iNoGate, int iNoPI, int iNoPO, int iMaxLevelAdd2, int iStem, GATEPTR *pStem, int iNoFault,
				 int *piShuffle, int *piDetected, int iPacket, int iBit, int iMaxBitSize, FILE *fpTestFile)
{
	int i, j, iPacketIndex, iNoDetectedOnce;
	int iNoRestoredFault;
	int iNoDetected = 0;
	int iNoPatterns = 0;
	int iCompactCnt = INFINITY, iStop = ONE; //Why iCompactCnt = INFINITY, NO Use at all !!
	int iBit_Local = 0, iPacket_Local = 0;
	int iArrNoDetected[BITSIZE];
	int iArrArray[MAXTEST], iStore = 0;
	int bDone, bRunShuffle;

	/***********/
	FILE *fpVecFile;
	if ((fpVecFile = fopen(g_strVecFileName, "w")) != NULL)
	{
	}
	/**************/

	for (i = 0; i <= g_iMaxCompact; i++) //g_iMaxCompact == 2 by default
	{
		iArrArray[i] = 0; //allocate 10000, only use 3 by default
	}
	reset(bDone);
	bRunShuffle = FALSE;
	*piShuffle = 0;

	/* shuffle fault simulation */
	while ((!bDone)) //One shuffle
	{
		(*piShuffle)++;
		for (i = 0; i < iNoGate; i++)
		{
			g_net[i]->nfault = 0;
			g_net[i]->pfault = NULL; //Just desert the pfault!!
		}
		if ((iNoRestoredFault = restoreUndetectedState_FSIM(iNoFault)) < 0) //IMPOSSIBLE !!
		{
			//STOP*********************************STOP
			printf("error occurred in restoration of fault list\n");
			exit(0);
		}

		initGateStackAndFreach(iNoGate, iMaxLevelAdd2, iNoPI);

		reset(g_iUpdateFlag);
		if (bRunShuffle == TRUE)
		{
			iBit = iBit_Local;   
			iPacket = iPacket_Local;
			/*shuffles the fpTestFile patterns and stores it back in the random fashion*/
			randomizePatterns_FSIM(g_test_store, g_test_vectors, iPacket_Local, iBit_Local, iNoPI);
			//g_test_store -----------> g_test_vectors
			iBit_Local = iPacket_Local = 0;
			for (iCompactCnt = 0; iCompactCnt <= g_iMaxCompact - 1; iCompactCnt++) //iCompactCnt = 0, 1
			{
				iStop = STOP;
				if (iArrArray[iCompactCnt] != iArrArray[iCompactCnt + 1])
				{
					iStop = TWO;
					break;
				}
			}
		}

		iNoPatterns = 0;
		iNoDetected = 0;

		if (iBit == 0)
		{
			--iPacket;
			iBit = iMaxBitSize;
		}
		iPacketIndex = iPacket + 1;
		
		while (--iPacketIndex >= 0)
		{
			if (iNoDetected >= iNoRestoredFault) //End condition!!!
			{
				break;
			}
			if (iPacketIndex < iPacket)
			{
				iBit = iMaxBitSize;
			}
			//
			//Finish Initializing iPacketIndex & iBit !!!
			//
			if (iBit == BITSIZE) //g_iAllOne has iBit's "1" in the right!!!
			{
				g_iAllOne = ALL1;
			}
			else
			{
				g_iAllOne = ~(ALL1 << iBit);
			}

			for (j = 0; j < iNoPI; j++)
			{
			 	//LOAD INPUTS!!!
				//g_test_vectors -----> g_net
				g_net[j]->output1 = g_net[j]->output = g_test_vectors[iPacketIndex][j];
			}
				
			evalGatesFromFreeStack(); //Free gates simulates first !!

			for (i = 0; i < iBit; i++)
			{
				iArrNoDetected[i] = 0;
			}
			
			if ((iNoDetectedOnce = Fault1_Simulation(iNoGate, iMaxLevelAdd2, iNoPI, iNoPO, iStem, pStem, iBit, iArrNoDetected)) > 0)
			{
				iNoDetected += iNoDetectedOnce;  //Multiple faults !!

				/* print out fpTestFile files */
				for (i = iBit - 1; i >= 0; i--)
				{
					if (iArrNoDetected[i] > 0) //Effective pattern found!!!
					{
						iNoPatterns++; //iBit's patterns !!
						if (iStop == STOP) //Always: iStop == STOP, Only one time to execute.
						{
							printio(fpTestFile, iNoPI, iNoPO, i, iNoPatterns); //Print compacted patterns!!!

							printinputs(fpVecFile, iNoPI, i); //Print compacted patterns!!!
							fprintf(fpVecFile, "\n");

							if (logmode == 'y')
							{
								fprintf(g_fpLogFile, "fpTestFile %4d: ", iNoPatterns);
								printinputs(g_fpLogFile, iNoPI, i);
								fprintf(g_fpLogFile, " ");
								printoutputs(g_fpLogFile, iNoPO, i);
								fprintf(g_fpLogFile, " %4d faults detected\n", iArrNoDetected[i]);
							}
							set(bDone); //OK!!!!
						}
						bRunShuffle = TRUE;
						for (j = 0; j < iNoPI; j++)
						{
							//Export the modified inputs !!
							if ((g_net[j]->output1 & BITMASK[i]) != ALL0) //g_net -------> g_test_store
							{
								setbit(g_test_store[iPacket_Local][j], iBit_Local);
							}
							else
							{
								resetbit(g_test_store[iPacket_Local][j], iBit_Local);
							}
						}
						if (++iBit_Local == iMaxBitSize)
						{
							iBit_Local = 0; iPacket_Local++;
						}
					}
				}
			}


			for (i = 0; i <= g_iSStack; i++)
			{
				g_dynamicStack[i]->cobserve = ALL0;
			}
			
			if (g_iUpdateFlag)
			{
				//Clear All Freach !!
				updateFaultyAndDynamicStack(iNoPI); //g_faultyGatesStack ----> freach & g_faultyGatesStack & g_dynamicStack
				reset(g_iUpdateFlag);
			}
			else
			{
				//Clear Only pDominator's Freach !!
				for (i = g_iDStack; i > g_iSStack; i--)
				{
					g_dynamicStack[i]->freach = 0;
				}
			}
			g_iDStack = g_iSStack;
		}

		if (iStore == g_iMaxCompact + 1) //iStore == 0, 1, 2
		{
			iStore = 0;
		}
		iArrArray[iStore] = iNoPatterns;
		iStore++;
	}
	/************/
	fprintf(fpVecFile, "END\n");
	fclose(fpVecFile);
	*piDetected = iNoDetected;
	return(iNoPatterns);
}
Esempio n. 7
0
void fill_patterns_fsim(char cMode, int iPacket, int iBit, int iNoPI)
{
	int j, iRandom0or1;

	switch (cMode)
	{
	case '0':
		for (j = 0; j < iNoPI; j++)
			switch (g_net[j]->output)
			{
			case ONE:
				setbit(g_test_vectors[iPacket][j], iBit);
				g_net[j]->output1 = ALL1; //ALL1 is useless, 1 is OK !!
				break;
			default: //ZERO & X
				resetbit(g_test_vectors[iPacket][j], iBit);
				g_net[j]->output1 = ALL0;
				break;
			}
		break;
	case '1':
		for (j = 0; j < iNoPI; j++)
			switch (g_net[j]->output)
			{
			case ZERO:
				resetbit(g_test_vectors[iPacket][j], iBit);
				g_net[j]->output1 = ALL0;
				break;
			default: //ONE & X
				setbit(g_test_vectors[iPacket][j], iBit);
				g_net[j]->output1 = ALL1;
				break;
			}
		break;
	case 'r':
	case 'x': //'x' is handled as 'r' because we CANNOT have actual X in FSIM !!
		for (j = 0; j < iNoPI; j++)
			switch (g_net[j]->output)
			{
			case ZERO:
				resetbit(g_test_vectors[iPacket][j], iBit);
				g_net[j]->output1 = ALL0;
				break;
			case ONE:
				setbit(g_test_vectors[iPacket][j], iBit);
				g_net[j]->output1 = ALL1;
				break;
			default: //X
				iRandom0or1 = (int) random() & 01;
				if (iRandom0or1 != 0)
				{
					setbit(g_test_vectors[iPacket][j], iBit);
				}
				else
				{
					resetbit(g_test_vectors[iPacket][j], iBit);
				}
				g_net[j]->output1 = iRandom0or1;
			}
		break;
	}
}
Esempio n. 8
0
/*------random_sim-----------------------------------------------------
TASK	Performs random similation until n consecutive packets of
	random patterns do not detect any new fault.
----------------------------------------------------------------------*/
int random_fsim(int iNoGate, int iNoPI, int iNoPO, int iMaxLevelAdd2, int iStem, GATEPTR *pStem, level *LFSR,
				int limit, int maxbit, int maxdetect, int *ntest, int *npacket, int *nbit, FILE *test)
{
	int iteration = 0;
	int i, j;
	int profile[BITSIZE];
	int ndetect = 0;

	while (iteration < limit)
	{
		GetPRandompattern(iNoPI, LFSR);
		for (i = 0; i < iNoPI; i++)
		{
			g_net[i]->output1 = g_net[i]->output = LFSR[i];
		}
		evalGatesFromFreeStack();
		for (i = 0; i < maxbit; i++)
			profile[i] = 0;
		if (Fault1_Simulation(iNoGate, iMaxLevelAdd2, iNoPI, iNoPO, iStem, pStem, maxbit, profile) > 0)
		{
			iteration = 0;
			for (i = maxbit - 1; i >= 0; i--)
				if (profile[i] > 0)
				{
					(*ntest)++;
					ndetect += profile[i];
					for (j = 0; j < iNoPI; j++)
						if ((g_net[j]->output1 & BITMASK[i]) != ALL0)
						{
							setbit(g_test_vectors[*npacket][j], *nbit);
						}
						else
						{
							resetbit(g_test_vectors[*npacket][j], *nbit);
						}
					if (++(*nbit) == maxbit)
					{
						*nbit = 0; (*npacket)++;
					}
					if (compact == 'n')
					{
						printio(test, iNoPI, iNoPO, i, *ntest);
						if (logmode == 'y')
						{
							fprintf(g_fpLogFile, "test %4d: ", *ntest);
							printinputs(g_fpLogFile, iNoPI, i);
							fprintf(g_fpLogFile, " ");
							printoutputs(g_fpLogFile, iNoPO, i);
							fprintf(g_fpLogFile, " %4d faults detected\n", profile[i]);
						}
					}
				}
			if (ndetect >= maxdetect)
			{
				break;
			}
		}
		else
		{
			iteration++;
		}

		for (i = 0; i <= g_iSStack; i++)
			g_dynamicStack[i]->cobserve = ALL0;
		if (g_iUpdateFlag)
		{
			updateFaultyAndDynamicStack(iNoPI);
			reset(g_iUpdateFlag);
		}
		else
		{
			for (i = g_iDStack; i > g_iSStack; i--)
				g_dynamicStack[i]->freach = 0;
		}
		g_iDStack = g_iSStack;
	}

	return(ndetect);
}