data/full_repos/permissive/130035268/src/filter.v
1: b'%Warning-WIDTH: data/full_repos/permissive/130035268/src/filter.v:247: Operator ASSIGNDLY expects 8 bits on the Assign RHS, but Assign RHS\'s VARREF \'rResult\' generates 11 bits.\n                                                                     : ... In instance filter\n      out_pixel<=rResult;\n               ^~\n                ... Use "/* verilator lint_off WIDTH */" and lint_on around source to disable this message.\n%Error: Exiting due to 1 warning(s)\n'
module filter (
	input wire 				clk,
	input wire 				rst_n,
	input wire 				fc_valid,
	input 		 	[7:0] 	working_pixel,
	input signed 	[7:0]	fc,
	input wire 				start,
	output reg 		[7:0] 	out_pixel,
	output reg 				out_valid,
	output reg 		[15:0] 	addr,
	output wire 			wen,
	output wire 	[7:0] 	d
);



	parameter 		[2:0] 	IDLE = 3'b000;		
	parameter 		[2:0] 	COEF = 3'b001;
	parameter 		[2:0] 	READ = 3'b010;
	parameter 		[2:0] 	CONV = 3'b011;
	parameter 		[2:0] 	OUT  = 3'b100;
	assign 					wen = 1;
	assign 					d = 0;



	reg				[2:0] 	rState,rState_next;
	reg 			[4:0] 	rCounter=0;
	reg			 	[4:0] 	rPixCounter=0;
	reg			 	[2:0] 	rCounter_proc=0;
	reg			 	[2:0] 	rCounter_out=0;
	reg signed 		[7:0]	rCoeff [0:24];
	reg signed 		[8:0] 	rUsingPixel [0:24];
	reg signed 		[10:0] 	rResult;
	reg 			[15:0] 	rPixProcess;
	reg						rReadPix=-1;
	reg						rSentAddr;
	reg						rOutDone;





always@(posedge clk,negedge rst_n)begin
	if(rst_n==0)begin
		rState=IDLE;
	end 
	else begin
		rState<=rState_next;
	end
end

always@(posedge clk)begin
	if(fc_valid==1)begin
		rCoeff[rCounter]<=$signed(fc);
		rCounter <= rCounter+1;	
	end
	else 
		rCounter <= 0;
end

always@(posedge rReadPix or posedge start)begin
	if(rState==IDLE)begin
		rPixProcess<=0;
	end
	else
		rPixProcess<=rPixProcess+1;
end

always@(posedge clk)begin
	if(rState==READ)begin
		if(rPixProcess<256&&rPixCounter<10)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess<512&&rPixCounter<5)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess>65023&&rPixCounter>19)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess>65279&&rPixCounter>14)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess%256==0&&rPixCounter%5<2)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
			else if(rPixProcess%256==1&&rPixCounter%5==0)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess%256==254&&rPixCounter%5==4)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess%256==255&&rPixCounter%5>2)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else begin
			if(rCounter_proc>2)begin

				rUsingPixel[rPixCounter]<={1'b0,working_pixel[7:0]};
				rPixCounter <= rPixCounter+1;
				rCounter_proc<=0;
				rSentAddr<=0;
			end
			else begin

				rSentAddr<=1;
				rCounter_proc<=rCounter_proc+1;
			end
			rSentAddr<=0;
		end
	end
	else 
		rPixCounter <= 0;
end

always@(posedge rSentAddr or posedge start)begin
	if(rState==IDLE)begin
		addr<=0;
	end
	else begin
		case(rPixCounter)
				0:addr<=rPixProcess-512-2;
				1:addr<=rPixProcess-512-1;
				2:addr<=rPixProcess-512;
				3:addr<=rPixProcess-512+1;
				4:addr<=rPixProcess-512+2;
				5:addr<=rPixProcess-256-2;
				6:addr<=rPixProcess-256-1;
				7:addr<=rPixProcess-256;
				8:addr<=rPixProcess-256+1;
				9:addr<=rPixProcess-256+2;
				10:addr<=rPixProcess-2;
				11:addr<=rPixProcess-1;
				12:addr<=rPixProcess;
				13:addr<=rPixProcess+1;
				14:addr<=rPixProcess+2;
				15:addr<=rPixProcess+256-2;
				16:addr<=rPixProcess+256-1;
				17:addr<=rPixProcess+256;
				18:addr<=rPixProcess+256+1;
				19:addr<=rPixProcess+256+2;
				20:addr<=rPixProcess+512-2;
				21:addr<=rPixProcess+512-1;
				22:addr<=rPixProcess+512;
				23:addr<=rPixProcess+512+1;
				24:addr<=rPixProcess+512+2;
		endcase
	end
end



 always@*begin
	case(rState)
		IDLE:begin
			if(start==1)
				rState_next=COEF;
			else
				rState_next=IDLE;
		 end
		COEF:begin
			if(rCounter==25)begin
				$display ("SHOW COEF BELOW :");
				$display ("%d,%d,%d,%d,%d",rCoeff[0],rCoeff[1],rCoeff[2],rCoeff[3],rCoeff[4]);
				$display ("%d,%d,%d,%d,%d",rCoeff[5],rCoeff[6],rCoeff[7],rCoeff[8],rCoeff[9]);
				$display ("%d,%d,%d,%d,%d",rCoeff[10],rCoeff[11],rCoeff[12],rCoeff[13],rCoeff[14]);
				$display ("%d,%d,%d,%d,%d",rCoeff[15],rCoeff[16],rCoeff[17],rCoeff[18],rCoeff[19]);
				$display ("%d,%d,%d,%d,%d",rCoeff[20],rCoeff[21],rCoeff[22],rCoeff[23],rCoeff[24]);	
				rState_next=READ;
			end
			else 
				rState_next=COEF;
		end	
		READ:begin
			if(rPixCounter==25)begin






				rState_next<=CONV;
				rReadPix=0;
			end
			else begin
				rReadPix=1;
				rState_next<=READ;
			end
		end
		CONV:begin
			if(rPixProcess<=65535)begin
				rResult<=rCoeff[0]*rUsingPixel[0]+rCoeff[1]*rUsingPixel[1]+rCoeff[2]*rUsingPixel[2]+rCoeff[3]*rUsingPixel[3]+rCoeff[4]*rUsingPixel[4]+
						rCoeff[5]*rUsingPixel[5]+rCoeff[6]*rUsingPixel[6]+rCoeff[7]*rUsingPixel[7]+rCoeff[8]*rUsingPixel[8]+rCoeff[9]*rUsingPixel[9]+
						rCoeff[10]*rUsingPixel[10]+rCoeff[11]*rUsingPixel[11]+rCoeff[12]*rUsingPixel[12]+rCoeff[13]*rUsingPixel[13]+rCoeff[14]*rUsingPixel[14]+
						rCoeff[15]*rUsingPixel[15]+rCoeff[16]*rUsingPixel[16]+rCoeff[17]*rUsingPixel[17]+rCoeff[18]*rUsingPixel[18]+rCoeff[19]*rUsingPixel[19]+
						rCoeff[20]*rUsingPixel[20]+rCoeff[21]*rUsingPixel[21]+rCoeff[22]*rUsingPixel[22]+rCoeff[23]*rUsingPixel[23]+rCoeff[24]*rUsingPixel[24];
				if(!rOutDone)begin
					if(rResult<0)begin

						out_pixel<=0;
						rOutDone<=1;
					end
					else if(rResult>255)begin

						out_pixel<=255;
						rOutDone<=1;
					end
					else begin

						out_pixel<=rResult;
						rOutDone<=1;
					end
				end
				else begin
					rState_next=OUT;
					rOutDone=0;
				end
			end	
			else 
				rState_next<=CONV;
		end
		OUT:begin
			if(!out_valid)begin
				out_valid=1;
				rState_next=READ;
			end
			else begin
				out_valid<=0;
				rState_next<=OUT;
			end
		end
	endcase
end
endmodule
module filter (
	input wire 				clk,
	input wire 				rst_n,
	input wire 				fc_valid,
	input 		 	[7:0] 	working_pixel,
	input signed 	[7:0]	fc,
	input wire 				start,
	output reg 		[7:0] 	out_pixel,
	output reg 				out_valid,
	output reg 		[15:0] 	addr,
	output wire 			wen,
	output wire 	[7:0] 	d
);




	parameter 		[2:0] 	IDLE = 3'b000;		
	parameter 		[2:0] 	COEF = 3'b001;
	parameter 		[2:0] 	READ = 3'b010;
	parameter 		[2:0] 	CONV = 3'b011;
	parameter 		[2:0] 	OUT  = 3'b100;
	assign 					wen = 1;
	assign 					d = 0;



	reg				[2:0] 	rState,rState_next;
	reg 			[4:0] 	rCounter=0;
	reg			 	[4:0] 	rPixCounter=0;
	reg			 	[2:0] 	rCounter_proc=0;
	reg			 	[2:0] 	rCounter_out=0;
	reg signed 		[7:0]	rCoeff [0:24];
	reg signed 		[8:0] 	rUsingPixel [0:24];
	reg signed 		[10:0] 	rResult;
	reg 			[15:0] 	rPixProcess;
	reg						rReadPix=-1;
	reg						rSentAddr;
	reg						rOutDone;





always@(posedge clk,negedge rst_n)begin
	if(rst_n==0)begin
		rState=IDLE;
	end 
	else begin
		rState<=rState_next;
	end
end

always@(posedge clk)begin
	if(fc_valid==1)begin
		rCoeff[rCounter]<=$signed(fc);
		rCounter <= rCounter+1;	
	end
	else 
		rCounter <= 0;
end

always@(posedge rReadPix or posedge start)begin
	if(rState==IDLE)begin
		rPixProcess<=0;
	end
	else
		rPixProcess<=rPixProcess+1;
end

always@(posedge clk)begin
	if(rState==READ)begin
		if(rPixProcess<256&&rPixCounter<10)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess<512&&rPixCounter<5)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess>65023&&rPixCounter>19)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess>65279&&rPixCounter>14)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess%256==0&&rPixCounter%5<2)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
			else if(rPixProcess%256==1&&rPixCounter%5==0)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess%256==254&&rPixCounter%5==4)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else if(rPixProcess%256==255&&rPixCounter%5>2)begin

			rUsingPixel[rPixCounter]<=0;
			rPixCounter <= rPixCounter+1;
			rCounter_proc<=0;
		end
		else begin
			if(rCounter_proc>2)begin

				rUsingPixel[rPixCounter]<={1'b0,working_pixel[7:0]};
				rPixCounter <= rPixCounter+1;
				rCounter_proc<=0;
				rSentAddr<=0;
			end
			else begin

				rSentAddr<=1;
				rCounter_proc<=rCounter_proc+1;
			end
			rSentAddr<=0;
		end
	end
	else 
		rPixCounter <= 0;
end

always@(posedge rSentAddr or posedge start)begin
	if(rState==IDLE)begin
		addr<=0;
	end
	else begin
		case(rPixCounter)
				0:addr<=rPixProcess-512-2;
				1:addr<=rPixProcess-512-1;
				2:addr<=rPixProcess-512;
				3:addr<=rPixProcess-512+1;
				4:addr<=rPixProcess-512+2;
				5:addr<=rPixProcess-256-2;
				6:addr<=rPixProcess-256-1;
				7:addr<=rPixProcess-256;
				8:addr<=rPixProcess-256+1;
				9:addr<=rPixProcess-256+2;
				10:addr<=rPixProcess-2;
				11:addr<=rPixProcess-1;
				12:addr<=rPixProcess;
				13:addr<=rPixProcess+1;
				14:addr<=rPixProcess+2;
				15:addr<=rPixProcess+256-2;
				16:addr<=rPixProcess+256-1;
				17:addr<=rPixProcess+256;
				18:addr<=rPixProcess+256+1;
				19:addr<=rPixProcess+256+2;
				20:addr<=rPixProcess+512-2;
				21:addr<=rPixProcess+512-1;
				22:addr<=rPixProcess+512;
				23:addr<=rPixProcess+512+1;
				24:addr<=rPixProcess+512+2;
		endcase
	end
end



 always@*begin
	case(rState)
		IDLE:begin
			if(start==1)
				rState_next=COEF;
			else
				rState_next=IDLE;
		 end
		COEF:begin
			if(rCounter==25)begin
				$display ("SHOW COEF BELOW :");
				$display ("%d,%d,%d,%d,%d",rCoeff[0],rCoeff[1],rCoeff[2],rCoeff[3],rCoeff[4]);
				$display ("%d,%d,%d,%d,%d",rCoeff[5],rCoeff[6],rCoeff[7],rCoeff[8],rCoeff[9]);
				$display ("%d,%d,%d,%d,%d",rCoeff[10],rCoeff[11],rCoeff[12],rCoeff[13],rCoeff[14]);
				$display ("%d,%d,%d,%d,%d",rCoeff[15],rCoeff[16],rCoeff[17],rCoeff[18],rCoeff[19]);
				$display ("%d,%d,%d,%d,%d",rCoeff[20],rCoeff[21],rCoeff[22],rCoeff[23],rCoeff[24]);	
				rState_next=READ;
			end
			else 
				rState_next=COEF;
		end	
		READ:begin
			if(rPixCounter==25)begin






				rState_next<=CONV;
				rReadPix=0;
			end
			else begin
				rReadPix=1;
				rState_next<=READ;
			end
		end
		CONV:begin
			if(rPixProcess<=65535)begin
				rResult<=rCoeff[0]*rUsingPixel[0]+rCoeff[1]*rUsingPixel[1]+rCoeff[2]*rUsingPixel[2]+rCoeff[3]*rUsingPixel[3]+rCoeff[4]*rUsingPixel[4]+
						rCoeff[5]*rUsingPixel[5]+rCoeff[6]*rUsingPixel[6]+rCoeff[7]*rUsingPixel[7]+rCoeff[8]*rUsingPixel[8]+rCoeff[9]*rUsingPixel[9]+
						rCoeff[10]*rUsingPixel[10]+rCoeff[11]*rUsingPixel[11]+rCoeff[12]*rUsingPixel[12]+rCoeff[13]*rUsingPixel[13]+rCoeff[14]*rUsingPixel[14]+
						rCoeff[15]*rUsingPixel[15]+rCoeff[16]*rUsingPixel[16]+rCoeff[17]*rUsingPixel[17]+rCoeff[18]*rUsingPixel[18]+rCoeff[19]*rUsingPixel[19]+
						rCoeff[20]*rUsingPixel[20]+rCoeff[21]*rUsingPixel[21]+rCoeff[22]*rUsingPixel[22]+rCoeff[23]*rUsingPixel[23]+rCoeff[24]*rUsingPixel[24];
				if(!rOutDone)begin
					if(rResult<0)begin

						out_pixel<=0;
						rOutDone<=1;
					end
					else if(rResult>255)begin

						out_pixel<=255;
						rOutDone<=1;
					end
					else begin

						out_pixel<=rResult;
						rOutDone<=1;
					end
				end
				else begin
					rState_next=OUT;
					rOutDone=0;
				end
			end	
			else 
				rState_next<=CONV;
		end
		OUT:begin
			if(!out_valid)begin
				out_valid=1;
				rState_next=READ;
			end
			else begin
				out_valid<=0;
				rState_next<=OUT;
			end
		end
	endcase
end
endmodule