mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 13:29:12 +00:00 
			
		
		
		
	Merge pull request #2027 from YosysHQ/eddie/verilog_neg_upto
ast: swap range regardless of range_left >= 0
This commit is contained in:
		
						commit
						ee0beb481d
					
				
					 4 changed files with 35 additions and 8 deletions
				
			
		| 
						 | 
					@ -1080,7 +1080,7 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (old_range_valid != range_valid)
 | 
							if (old_range_valid != range_valid)
 | 
				
			||||||
			did_something = true;
 | 
								did_something = true;
 | 
				
			||||||
		if (range_valid && range_left >= 0 && range_right > range_left) {
 | 
							if (range_valid && range_right > range_left) {
 | 
				
			||||||
			int tmp = range_right;
 | 
								int tmp = range_right;
 | 
				
			||||||
			range_right = range_left;
 | 
								range_right = range_left;
 | 
				
			||||||
			range_left = tmp;
 | 
								range_left = tmp;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -108,8 +108,12 @@ generate
 | 
				
			||||||
                // Generate if any comparisons call for it
 | 
					                // Generate if any comparisons call for it
 | 
				
			||||||
                wire [LCU_WIDTH-1:0] G_ = {G[LCU_WIDTH-1:1], G[0] | GG};
 | 
					                wire [LCU_WIDTH-1:0] G_ = {G[LCU_WIDTH-1:1], G[0] | GG};
 | 
				
			||||||
            end
 | 
					            end
 | 
				
			||||||
            $__CMP2LCU #(.AB_WIDTH(AB_WIDTH-1), .AB_SIGNED(1'b0), .LCU_WIDTH(LCU_WIDTH), .BUDGET(BUDGET-COST), .CI(CI))
 | 
					            if (AB_WIDTH == 1)
 | 
				
			||||||
                _TECHMAP_REPLACE_ (.A(A[AB_WIDTH-2:0]), .B(B[AB_WIDTH-2:0]), .P(P_), .G(G_), .Y(Y));
 | 
					               $__CMP2LCU #(.AB_WIDTH(AB_WIDTH-1), .AB_SIGNED(1'b0), .LCU_WIDTH(LCU_WIDTH), .BUDGET(BUDGET-COST), .CI(CI))
 | 
				
			||||||
 | 
					                    _TECHMAP_REPLACE_ (.A(), .B(), .P(P_), .G(G_), .Y(Y));
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					               $__CMP2LCU #(.AB_WIDTH(AB_WIDTH-1), .AB_SIGNED(1'b0), .LCU_WIDTH(LCU_WIDTH), .BUDGET(BUDGET-COST), .CI(CI))
 | 
				
			||||||
 | 
					                    _TECHMAP_REPLACE_ (.A(A[AB_WIDTH-2:0]), .B(B[AB_WIDTH-2:0]), .P(P_), .G(G_), .Y(Y));
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
endgenerate
 | 
					endgenerate
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -285,13 +285,32 @@ module _90_alu (A, B, CI, BI, X, Y, CO);
 | 
				
			||||||
	input CI, BI;
 | 
						input CI, BI;
 | 
				
			||||||
	output [Y_WIDTH-1:0] CO;
 | 
						output [Y_WIDTH-1:0] CO;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	wire [Y_WIDTH-1:0] A_buf, B_buf;
 | 
						wire [Y_WIDTH-1:0] AA, BB;
 | 
				
			||||||
	\$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
 | 
					 | 
				
			||||||
	\$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	wire [Y_WIDTH-1:0] AA = A_buf;
 | 
					 | 
				
			||||||
	wire [Y_WIDTH-1:0] BB = BI ? ~B_buf : B_buf;
 | 
						wire [Y_WIDTH-1:0] BB = BI ? ~B_buf : B_buf;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (A_WIDTH == 0) begin
 | 
				
			||||||
 | 
							wire [Y_WIDTH-1:0] B_buf;
 | 
				
			||||||
 | 
							\$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assign AA = {Y_WIDTH{1'b0}};
 | 
				
			||||||
 | 
							assign BB = BI ? ~B_buf : B_buf;
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						else if (B_WIDTH == 0) begin
 | 
				
			||||||
 | 
							wire [Y_WIDTH-1:0] A_buf;
 | 
				
			||||||
 | 
							\$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assign AA = A_buf;
 | 
				
			||||||
 | 
							assign BB = {Y_WIDTH{BI ? 1'b0 : 1'b1}};
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						else begin
 | 
				
			||||||
 | 
							wire [Y_WIDTH-1:0] A_buf, B_buf;
 | 
				
			||||||
 | 
							\$pos #(.A_SIGNED(A_SIGNED), .A_WIDTH(A_WIDTH), .Y_WIDTH(Y_WIDTH)) A_conv (.A(A), .Y(A_buf));
 | 
				
			||||||
 | 
							\$pos #(.A_SIGNED(B_SIGNED), .A_WIDTH(B_WIDTH), .Y_WIDTH(Y_WIDTH)) B_conv (.A(B), .Y(B_buf));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							assign AA = A_buf;
 | 
				
			||||||
 | 
							assign BB = BI ? ~B_buf : B_buf;
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	\$lcu #(.WIDTH(Y_WIDTH)) lcu (.P(X), .G(AA & BB), .CI(CI), .CO(CO));
 | 
						\$lcu #(.WIDTH(Y_WIDTH)) lcu (.P(X), .G(AA & BB), .CI(CI), .CO(CO));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	assign X = AA ^ BB;
 | 
						assign X = AA ^ BB;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										4
									
								
								tests/verilog/upto.ys
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/verilog/upto.ys
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					read_verilog <<EOT
 | 
				
			||||||
 | 
					module top(input [-128:-65] a);
 | 
				
			||||||
 | 
					endmodule
 | 
				
			||||||
 | 
					EOT
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue