mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	Merge pull request #3959 from rmlarsen/decode_string
Speed up RTLIL::Const::decode_string by 1.7x.
This commit is contained in:
		
						commit
						b894abf8b1
					
				
					 1 changed files with 24 additions and 9 deletions
				
			
		| 
						 | 
					@ -313,18 +313,33 @@ RTLIL::Const RTLIL::Const::from_string(const std::string &str)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
std::string RTLIL::Const::decode_string() const
 | 
					std::string RTLIL::Const::decode_string() const
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	std::string string;
 | 
						const int n = GetSize(bits);
 | 
				
			||||||
	string.reserve(GetSize(bits)/8);
 | 
						const int n_over_8 = n / 8;
 | 
				
			||||||
	for (int i = 0; i < GetSize(bits); i += 8) {
 | 
						std::string s;
 | 
				
			||||||
 | 
						s.reserve(n_over_8);
 | 
				
			||||||
 | 
						int i = n_over_8 * 8;
 | 
				
			||||||
 | 
						if (i < n) {
 | 
				
			||||||
		char ch = 0;
 | 
							char ch = 0;
 | 
				
			||||||
		for (int j = 0; j < 8 && i + j < int (bits.size()); j++)
 | 
							for (int j = 0; j < (n - i); j++) {
 | 
				
			||||||
			if (bits[i + j] == RTLIL::State::S1)
 | 
								if (bits[i + j] == RTLIL::State::S1) {
 | 
				
			||||||
				ch |= 1 << j;
 | 
									ch |= 1 << j;
 | 
				
			||||||
		if (ch != 0)
 | 
					 | 
				
			||||||
			string.append({ch});
 | 
					 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
	std::reverse(string.begin(), string.end());
 | 
							}
 | 
				
			||||||
	return string;
 | 
							if (ch != 0)
 | 
				
			||||||
 | 
								s.append({ch});
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						i -= 8;
 | 
				
			||||||
 | 
						for (; i >= 0; i -= 8) {
 | 
				
			||||||
 | 
							char ch = 0;
 | 
				
			||||||
 | 
							for (int j = 0; j < 8; j++) {
 | 
				
			||||||
 | 
								if (bits[i + j] == RTLIL::State::S1) {
 | 
				
			||||||
 | 
									ch |= 1 << j;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (ch != 0)
 | 
				
			||||||
 | 
								s.append({ch});
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return s;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool RTLIL::Const::is_fully_zero() const
 | 
					bool RTLIL::Const::is_fully_zero() const
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue