mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	Improvements in greenpak4 shreg mapping
This commit is contained in:
		
							parent
							
								
									c9c5192cd6
								
							
						
					
					
						commit
						096c25d29d
					
				
					 1 changed files with 35 additions and 16 deletions
				
			
		| 
						 | 
					@ -26,8 +26,8 @@ PRIVATE_NAMESPACE_BEGIN
 | 
				
			||||||
struct ShregmapTech
 | 
					struct ShregmapTech
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	virtual ~ShregmapTech() { }
 | 
						virtual ~ShregmapTech() { }
 | 
				
			||||||
	virtual bool check_taps(const dict<int, SigBit> &taps) = 0;
 | 
						virtual bool analyze(vector<int> &taps) = 0;
 | 
				
			||||||
	virtual bool fixup_shreg(Cell *cell, dict<int, SigBit> &taps) = 0;
 | 
						virtual bool fixup(Cell *cell, dict<int, SigBit> &taps) = 0;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ShregmapOptions
 | 
					struct ShregmapOptions
 | 
				
			||||||
| 
						 | 
					@ -54,18 +54,22 @@ struct ShregmapOptions
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ShregmapTechGreenpak4 : ShregmapTech
 | 
					struct ShregmapTechGreenpak4 : ShregmapTech
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	bool check_taps(const dict<int, SigBit> &taps)
 | 
						bool analyze(vector<int> &taps)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							if (GetSize(taps) > 2 && taps[0] == 0 && taps[2] < 17) {
 | 
				
			||||||
 | 
								taps.clear();
 | 
				
			||||||
 | 
								return true;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (GetSize(taps) > 2)
 | 
							if (GetSize(taps) > 2)
 | 
				
			||||||
			return false;
 | 
								return false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for (auto tap : taps)
 | 
							if (taps.back() > 16) return false;
 | 
				
			||||||
			if (tap.first > 16) return false;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool fixup_shreg(Cell *cell, dict<int, SigBit> &taps)
 | 
						bool fixup(Cell *cell, dict<int, SigBit> &taps)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		auto D = cell->getPort("\\D");
 | 
							auto D = cell->getPort("\\D");
 | 
				
			||||||
		auto C = cell->getPort("\\C");
 | 
							auto C = cell->getPort("\\C");
 | 
				
			||||||
| 
						 | 
					@ -232,31 +236,47 @@ struct ShregmapWorker
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			Cell *first_cell = chain[cursor];
 | 
								Cell *first_cell = chain[cursor];
 | 
				
			||||||
			IdString q_port = opts.ffcells.at(first_cell->type).second;
 | 
								IdString q_port = opts.ffcells.at(first_cell->type).second;
 | 
				
			||||||
			dict<int, SigBit> taps;
 | 
								dict<int, SigBit> taps_dict;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (opts.tech)
 | 
								if (opts.tech)
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 | 
									vector<SigBit> qbits;
 | 
				
			||||||
 | 
									vector<int> taps;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				for (int i = 0; i < depth; i++)
 | 
									for (int i = 0; i < depth; i++)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Cell *cell = chain[cursor+i];
 | 
										Cell *cell = chain[cursor+i];
 | 
				
			||||||
					auto qbit = sigmap(cell->getPort(q_port));
 | 
										auto qbit = sigmap(cell->getPort(q_port));
 | 
				
			||||||
 | 
										qbits.push_back(qbit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if (sigbit_with_non_chain_users.count(qbit))
 | 
										if (sigbit_with_non_chain_users.count(qbit))
 | 
				
			||||||
						taps[i] = qbit;
 | 
											taps.push_back(i);
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				while (depth > 0)
 | 
									while (depth > 0)
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					Cell *last_cell = chain[cursor+depth-1];
 | 
										if (taps.empty() || taps.back() < depth-1)
 | 
				
			||||||
					taps[depth-1] = sigmap(last_cell->getPort(q_port));
 | 
											taps.push_back(depth-1);
 | 
				
			||||||
					if (opts.tech->check_taps(taps))
 | 
					
 | 
				
			||||||
 | 
										if (opts.tech->analyze(taps))
 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					taps.erase(--depth);
 | 
					
 | 
				
			||||||
 | 
										taps.pop_back();
 | 
				
			||||||
 | 
										depth--;
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									depth = 0;
 | 
				
			||||||
 | 
									for (auto tap : taps) {
 | 
				
			||||||
 | 
										taps_dict[tap] = qbits.at(tap);
 | 
				
			||||||
 | 
										log_assert(depth < tap+1);
 | 
				
			||||||
 | 
										depth = tap+1;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (depth < 2)
 | 
								if (depth < 2) {
 | 
				
			||||||
				return;
 | 
									cursor++;
 | 
				
			||||||
 | 
									continue;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			Cell *last_cell = chain[cursor+depth-1];
 | 
								Cell *last_cell = chain[cursor+depth-1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -318,7 +338,7 @@ struct ShregmapWorker
 | 
				
			||||||
			first_cell->setPort(q_port, last_cell->getPort(q_port));
 | 
								first_cell->setPort(q_port, last_cell->getPort(q_port));
 | 
				
			||||||
			first_cell->setParam("\\DEPTH", depth);
 | 
								first_cell->setParam("\\DEPTH", depth);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (opts.tech != nullptr && !opts.tech->fixup_shreg(first_cell, taps))
 | 
								if (opts.tech != nullptr && !opts.tech->fixup(first_cell, taps_dict))
 | 
				
			||||||
				remove_cells.insert(first_cell);
 | 
									remove_cells.insert(first_cell);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for (int i = 1; i < depth; i++)
 | 
								for (int i = 1; i < depth; i++)
 | 
				
			||||||
| 
						 | 
					@ -479,7 +499,6 @@ struct ShregmapPass : public Pass {
 | 
				
			||||||
				string tech = args[++argidx];
 | 
									string tech = args[++argidx];
 | 
				
			||||||
				if (tech == "greenpak4") {
 | 
									if (tech == "greenpak4") {
 | 
				
			||||||
					clkpol = "pos";
 | 
										clkpol = "pos";
 | 
				
			||||||
					opts.maxlen = 16;
 | 
					 | 
				
			||||||
					opts.zinit = true;
 | 
										opts.zinit = true;
 | 
				
			||||||
					opts.tech = new ShregmapTechGreenpak4;
 | 
										opts.tech = new ShregmapTechGreenpak4;
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue