mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	cxxrtl: Fix ctlz implementation
				
					
				
			This commit is contained in:
		
							parent
							
								
									cca12d9d9b
								
							
						
					
					
						commit
						bcf5e92389
					
				
					 1 changed files with 6 additions and 5 deletions
				
			
		|  | @ -508,12 +508,13 @@ struct value : public expr_base<value<Bits>> { | |||
| 		size_t count = 0; | ||||
| 		for (size_t n = 0; n < chunks; n++) { | ||||
| 			chunk::type x = data[chunks - 1 - n]; | ||||
| 			if (x == 0) { | ||||
| 				count += (n == 0 ? Bits % chunk::bits : chunk::bits); | ||||
| 			} else { | ||||
| 				// This loop implements the find first set idiom as recognized by LLVM.
 | ||||
| 				for (; x != 0; count++) | ||||
| 			// First add to `count` as if the chunk is zero
 | ||||
| 			count += (n == 0 ? Bits % chunk::bits : chunk::bits); | ||||
| 			// If the chunk isn't zero, correct the `count` value and return
 | ||||
| 			if (x != 0) { | ||||
| 				for (; x != 0; count--) | ||||
| 					x >>= 1; | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		return count; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue