mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	hashlib: add deprecated mkhash function to prevent plugin breakage
This commit is contained in:
		
							parent
							
								
									6d53454bf5
								
							
						
					
					
						commit
						79acc141d5
					
				
					 2 changed files with 18 additions and 4 deletions
				
			
		| 
						 | 
					@ -145,3 +145,9 @@ redirecting to ``hash_ops<T>``
 | 
				
			||||||
       Hasher h;
 | 
					       Hasher h;
 | 
				
			||||||
       return (unsigned int)hash_acc(h).yield();
 | 
					       return (unsigned int)hash_acc(h).yield();
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					To get hashes for Yosys types, you can temporarily use the templated deprecated
 | 
				
			||||||
 | 
					``mkhash`` function until the majority of your plugin's users switch to a newer
 | 
				
			||||||
 | 
					version and live with the warnings, or set up a custom ``#ifdef``-based solution
 | 
				
			||||||
 | 
					if you really need to.
 | 
				
			||||||
 | 
					Feel free to contact Yosys maintainers with related issues.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -103,19 +103,19 @@ private:
 | 
				
			||||||
	static uint32_t fudge;
 | 
						static uint32_t fudge;
 | 
				
			||||||
	// The XOR version of DJB2
 | 
						// The XOR version of DJB2
 | 
				
			||||||
	[[nodiscard]]
 | 
						[[nodiscard]]
 | 
				
			||||||
	static uint32_t mkhash(uint32_t a, uint32_t b) {
 | 
						static uint32_t djb2_xor(uint32_t a, uint32_t b) {
 | 
				
			||||||
		uint32_t hash = ((a << 5) + a) ^ b;
 | 
							uint32_t hash = ((a << 5) + a) ^ b;
 | 
				
			||||||
		return hash;
 | 
							return hash;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	public:
 | 
						public:
 | 
				
			||||||
	void hash32(uint32_t i) {
 | 
						void hash32(uint32_t i) {
 | 
				
			||||||
		state = mkhash(i, state);
 | 
							state = djb2_xor(i, state);
 | 
				
			||||||
		state = mkhash_xorshift(fudge ^ state);
 | 
							state = mkhash_xorshift(fudge ^ state);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	void hash64(uint64_t i) {
 | 
						void hash64(uint64_t i) {
 | 
				
			||||||
		state = mkhash((uint32_t)(i % (1ULL << 32ULL)), state);
 | 
							state = djb2_xor((uint32_t)(i % (1ULL << 32ULL)), state);
 | 
				
			||||||
		state = mkhash((uint32_t)(i >> 32ULL), state);
 | 
							state = djb2_xor((uint32_t)(i >> 32ULL), state);
 | 
				
			||||||
		state = mkhash_xorshift(fudge ^ state);
 | 
							state = mkhash_xorshift(fudge ^ state);
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -283,6 +283,14 @@ Hasher::hash_t run_hash(const T& obj) {
 | 
				
			||||||
	return hash_top_ops<T>::hash(obj).yield();
 | 
						return hash_top_ops<T>::hash(obj).yield();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Refer to docs/source/yosys_internals/hashing.rst */
 | 
				
			||||||
 | 
					template<typename T>
 | 
				
			||||||
 | 
					[[nodiscard]]
 | 
				
			||||||
 | 
					[[deprecated]]
 | 
				
			||||||
 | 
					inline unsigned int mkhash(const T &v) {
 | 
				
			||||||
 | 
						return (unsigned int) run_hash<T>(v);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template<> struct hash_ops<std::monostate> {
 | 
					template<> struct hash_ops<std::monostate> {
 | 
				
			||||||
	static inline bool cmp(std::monostate a, std::monostate b) {
 | 
						static inline bool cmp(std::monostate a, std::monostate b) {
 | 
				
			||||||
		return a == b;
 | 
							return a == b;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue