aboutsummaryrefslogtreecommitdiffstats
path: root/techlibs/anlogic/anlogic_determine_init.cc
blob: 34b1d4f8a4323b8500bc316906c02e403801d52f (plain)
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
/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2018 Icenowy Zheng <icenowy@aosc.io>
 *
 *  Permission to use, copy, modify, and/or distribute this software for any
 *  purpose with or without fee is hereby granted, provided that the above
 *  copyright notice and this permission notice appear in all copies.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 *  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 *  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 *  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 *  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 *  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 *  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

#include "kernel/yosys.h"
#include "kernel/sigtools.h"

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN

struct AnlogicDetermineInitPass : public Pass {
	AnlogicDetermineInitPass() : Pass("anlogic_determine_init", "Anlogic: Determine the init value of cells") { }
	void help() YS_OVERRIDE
	{
		log("\n");
		log("    anlogic_determine_init [selection]\n");
		log("\n");
		log("Determine the init value of cells that doesn't allow unknown init value.\n");
		log("\n");
	}

	Const determine_init(Const init)
	{
		for (int i = 0; i < GetSize(init); i++) {
			if (init[i] != State::S0 && init[i] != State::S1)
				init[i] = State::S0;
		}

		return init;
	}

	void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
	{
		log_header(design, "Executing ANLOGIC_DETERMINE_INIT pass (determine init value for cells).\n");

		extra_args(args, args.size(), design);

		size_t cnt = 0;
		for (auto module : design->selected_modules())
		{
			for (auto cell : module->selected_cells())
			{
				if (cell->type == "\\EG_LOGIC_DRAM16X4")
				{
					cell->setParam("\\INIT_D0", determine_init(cell->getParam("\\INIT_D0")));
					cell->setParam("\\INIT_D1", determine_init(cell->getParam("\\INIT_D1")));
					cell->setParam("\\INIT_D2", determine_init(cell->getParam("\\INIT_D2")));
					cell->setParam("\\INIT_D3", determine_init(cell->getParam("\\INIT_D3")));
					cnt++;
				}
			}
		}
		log_header(design, "Updated %lu cells with determined init value.\n", cnt);
	}
} AnlogicDetermineInitPass;

PRIVATE_NAMESPACE_END
lass="o">&mutex) == 0); nThreadsRunning--; assert(pthread_mutex_unlock(&mutex) == 0); // quit this thread //printf("...Finishing %s\n", (char *)Command); free( Command ); pthread_exit( NULL ); assert(0); return NULL; } /**Function************************************************************* Synopsis [Takes file with commands to be executed and the number of CPUs.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int main( int argc, char * argv[] ) { FILE * pFile, * pOutput = stdout; pthread_t ThreadIds[MAX_COMM_NUM]; char * pBufferCopy, Buffer[MAX_COMM_NUM]; int i, nCPUs = 0, nLines = 0, Counter; clock_t clk = clock(); // check command line arguments if ( argc != 3 ) { fprintf( stderr, "Wrong number of command line arguments.\n" ); goto usage; } // get the number of CPUs nCPUs = atoi( argv[1] ); if ( nCPUs <= 0 ) { fprintf( pOutput, "Cannot read an integer represting the number of CPUs.\n" ); goto usage; } // open the file and make sure it is available pFile = fopen( argv[2], "r" ); if ( pFile == NULL ) { fprintf( pOutput, "Input file \"%s\" cannot be opened.\n", argv[2] ); goto usage; } // read commands and execute at most <num> of them at a time // assert(mutex == PTHREAD_MUTEX_INITIALIZER); while ( fgets( Buffer, MAX_COMM_NUM, pFile ) != NULL ) { // get the command from the file if ( Buffer[0] == '\n' || Buffer[0] == '\r' || Buffer[0] == '\t' || Buffer[0] == ' ' || Buffer[0] == '#') { continue; } if ( Buffer[strlen(Buffer)-1] == '\n' ) Buffer[strlen(Buffer)-1] = 0; if ( Buffer[strlen(Buffer)-1] == '\r' ) Buffer[strlen(Buffer)-1] = 0; // wait till there is an empty thread while ( 1 ) { assert(pthread_mutex_lock(&mutex) == 0); Counter = nThreadsRunning; assert(pthread_mutex_unlock(&mutex) == 0); if ( Counter < nCPUs - 1 ) break; // Sleep( 100 ); } // increament the number of threads running assert(pthread_mutex_lock(&mutex) == 0); nThreadsRunning++; printf( "Calling: %s\n", (char *)Buffer ); fflush( stdout ); assert(pthread_mutex_unlock(&mutex) == 0); // create thread to execute this command pBufferCopy = Abc_UtilStrsav( Buffer ); assert(pthread_create( &ThreadIds[nLines], NULL, Abc_RunThread, (void *)pBufferCopy ) == 0); if ( ++nLines == MAX_COMM_NUM ) { fprintf( pOutput, "Cannot execute more than %d commands from file \"%s\".\n", nLines, argv[2] ); break; } } // wait for all the threads to finish while ( 1 ) { assert(pthread_mutex_lock(&mutex) == 0); Counter = nThreadsRunning; assert(pthread_mutex_unlock(&mutex) == 0); if ( Counter == 0 ) break; } // cleanup assert(pthread_mutex_destroy(&mutex) == 0); // assert(mutex == NULL); fclose( pFile ); printf( "Finished processing commands in file \"%s\". ", argv[2] ); ABC_PRT( "Total time", clock() - clk ); return 0; usage: // skip the path name till the binary name for ( i = strlen(argv[0]) - 1; i > 0; i-- ) if ( argv[0][i-1] == '\\' || argv[0][i-1] == '/' ) break; // print usage message fprintf( pOutput, "usage: %s <num> <file>\n", argv[0]+i ); fprintf( pOutput, " executes command listed in <file> in parallel on <num> CPUs\n" ); fprintf( pOutput, "\n" ); return 1; }