mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	Added $eq/$neq -> $logic_not/$reduce_bool optimization
This commit is contained in:
		
							parent
							
								
									9d067fecea
								
							
						
					
					
						commit
						f483dce7c2
					
				
					 4 changed files with 38 additions and 1 deletions
				
			
		| 
						 | 
					@ -3000,6 +3000,21 @@ bool RTLIL::SigSpec::is_fully_const() const
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool RTLIL::SigSpec::is_fully_zero() const
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						cover("kernel.rtlil.sigspec.is_fully_zero");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pack();
 | 
				
			||||||
 | 
						for (auto it = chunks_.begin(); it != chunks_.end(); it++) {
 | 
				
			||||||
 | 
							if (it->width > 0 && it->wire != NULL)
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							for (size_t i = 0; i < it->data.size(); i++)
 | 
				
			||||||
 | 
								if (it->data[i] != RTLIL::State::S0)
 | 
				
			||||||
 | 
									return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool RTLIL::SigSpec::is_fully_def() const
 | 
					bool RTLIL::SigSpec::is_fully_def() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	cover("kernel.rtlil.sigspec.is_fully_def");
 | 
						cover("kernel.rtlil.sigspec.is_fully_def");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -692,6 +692,7 @@ public:
 | 
				
			||||||
	bool is_chunk() const;
 | 
						bool is_chunk() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool is_fully_const() const;
 | 
						bool is_fully_const() const;
 | 
				
			||||||
 | 
						bool is_fully_zero() const;
 | 
				
			||||||
	bool is_fully_def() const;
 | 
						bool is_fully_def() const;
 | 
				
			||||||
	bool is_fully_undef() const;
 | 
						bool is_fully_undef() const;
 | 
				
			||||||
	bool has_const() const;
 | 
						bool has_const() const;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -305,7 +305,9 @@ static void extract_fsm(RTLIL::Wire *wire)
 | 
				
			||||||
	for (auto &cellport : cellport_list) {
 | 
						for (auto &cellport : cellport_list) {
 | 
				
			||||||
		RTLIL::Cell *cell = module->cells_.at(cellport.first);
 | 
							RTLIL::Cell *cell = module->cells_.at(cellport.first);
 | 
				
			||||||
		RTLIL::SigSpec sig_a = assign_map(cell->getPort("\\A"));
 | 
							RTLIL::SigSpec sig_a = assign_map(cell->getPort("\\A"));
 | 
				
			||||||
		RTLIL::SigSpec sig_b = assign_map(cell->getPort("\\B"));
 | 
							RTLIL::SigSpec sig_b;
 | 
				
			||||||
 | 
							if (cell->hasPort("\\B"))
 | 
				
			||||||
 | 
								sig_b = assign_map(cell->getPort("\\B"));
 | 
				
			||||||
		RTLIL::SigSpec sig_y = assign_map(cell->getPort("\\Y"));
 | 
							RTLIL::SigSpec sig_y = assign_map(cell->getPort("\\Y"));
 | 
				
			||||||
		if (cellport.second == "\\A" && !sig_b.is_fully_const())
 | 
							if (cellport.second == "\\A" && !sig_b.is_fully_const())
 | 
				
			||||||
			continue;
 | 
								continue;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -548,6 +548,25 @@ void replace_const_cells(RTLIL::Design *design, RTLIL::Module *module, bool cons
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if ((cell->type == "$eq" || cell->type == "$ne") &&
 | 
				
			||||||
 | 
									(assign_map(cell->getPort("\\A")).is_fully_zero() || assign_map(cell->getPort("\\B")).is_fully_zero()))
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								cover_list("opt.opt_const.eqneq.cmpzero", "$eq", "$ne", cell->type.str());
 | 
				
			||||||
 | 
								log("Replacing %s cell `%s' in module `%s' with %s.\n", log_id(cell->type), log_id(cell),
 | 
				
			||||||
 | 
										log_id(module), "$eq" ? "$logic_not" : "$reduce_bool");
 | 
				
			||||||
 | 
								cell->type = cell->type == "$eq" ? "$logic_not" : "$reduce_bool";
 | 
				
			||||||
 | 
								if (assign_map(cell->getPort("\\A")).is_fully_zero()) {
 | 
				
			||||||
 | 
									cell->setPort("\\A", cell->getPort("\\B"));
 | 
				
			||||||
 | 
									cell->setParam("\\A_SIGNED", cell->getParam("\\B_SIGNED"));
 | 
				
			||||||
 | 
									cell->setParam("\\A_WIDTH", cell->getParam("\\B_WIDTH"));
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								cell->unsetPort("\\B");
 | 
				
			||||||
 | 
								cell->unsetParam("\\B_SIGNED");
 | 
				
			||||||
 | 
								cell->unsetParam("\\B_WIDTH");
 | 
				
			||||||
 | 
								did_something = true;
 | 
				
			||||||
 | 
								goto next_cell;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (cell->type.in("$shl", "$shr", "$sshl", "$sshr", "$shift", "$shiftx") && assign_map(cell->getPort("\\B")).is_fully_const())
 | 
							if (cell->type.in("$shl", "$shr", "$sshl", "$sshr", "$shift", "$shiftx") && assign_map(cell->getPort("\\B")).is_fully_const())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			bool sign_ext = cell->type == "$sshr" && cell->getParam("\\A_SIGNED").as_bool();
 | 
								bool sign_ext = cell->type == "$sshr" && cell->getParam("\\A_SIGNED").as_bool();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue