mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-30 19:22:31 +00:00 
			
		
		
		
	opt_expr: only sign extend shift arguments for arithmetic right shift
This commit is contained in:
		
							parent
							
								
									2d6255175e
								
							
						
					
					
						commit
						c952ab417f
					
				
					 1 changed files with 5 additions and 4 deletions
				
			
		|  | @ -1315,13 +1315,14 @@ skip_fine_alu: | ||||||
| 			RTLIL::SigSpec sig_a = assign_map(cell->getPort(ID::A)); | 			RTLIL::SigSpec sig_a = assign_map(cell->getPort(ID::A)); | ||||||
| 			RTLIL::SigSpec sig_y(cell->type == ID($shiftx) ? RTLIL::State::Sx : RTLIL::State::S0, cell->getParam(ID::Y_WIDTH).as_int()); | 			RTLIL::SigSpec sig_y(cell->type == ID($shiftx) ? RTLIL::State::Sx : RTLIL::State::S0, cell->getParam(ID::Y_WIDTH).as_int()); | ||||||
| 
 | 
 | ||||||
| 			// Limit indexing to the size of a, which is behaviourally identical (result is all 0)
 |  | ||||||
| 			// and avoids integer overflow of i + shift_bits when e.g. ID::B == INT_MAX
 |  | ||||||
| 			shift_bits = min(shift_bits, GetSize(sig_a)); |  | ||||||
| 
 |  | ||||||
| 			if (cell->type != ID($shiftx) && GetSize(sig_a) < GetSize(sig_y)) | 			if (cell->type != ID($shiftx) && GetSize(sig_a) < GetSize(sig_y)) | ||||||
| 				sig_a.extend_u0(GetSize(sig_y), cell->getParam(ID::A_SIGNED).as_bool()); | 				sig_a.extend_u0(GetSize(sig_y), cell->getParam(ID::A_SIGNED).as_bool()); | ||||||
| 
 | 
 | ||||||
|  | 			// Limit indexing to the size of a, which is behaviourally identical (result is all 0)
 | ||||||
|  | 			// and avoids integer overflow of i + shift_bits when e.g. ID::B == INT_MAX.
 | ||||||
|  | 			// We do this after sign-extending a so this accounts for the output size
 | ||||||
|  | 			shift_bits = min(shift_bits, GetSize(sig_a)); | ||||||
|  | 
 | ||||||
| 			for (int i = 0; i < GetSize(sig_y); i++) { | 			for (int i = 0; i < GetSize(sig_y); i++) { | ||||||
| 				int idx = i + shift_bits; | 				int idx = i + shift_bits; | ||||||
| 				if (0 <= idx && idx < GetSize(sig_a)) | 				if (0 <= idx && idx < GetSize(sig_a)) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue