|
reg [23:0]mix1,mix2,mix3;
always @(posedge clk or negedge rst_n)
if(~rst_n)
mix1<=24'd0;
else if(sft_en)
mix1<={mix1[15:0],pre_sft[31:24]};
always @(posedge clk or negedge rst_n)
if(~rst_n)
mix2<=24'd0;
else if(sft_en)
mix2<={mix2[15:0],cur_sft[31:24]};
always @(posedge clk or negedge rst_n)
if(~rst_n)
mix3<=24'd0;
else if(sft_en)
mix3<={mix3[15:0],nex_sft[31:24]};
//计算dx,dy
reg signed[10:0]dx,dy;
wire [7:0]p00,p01,p02,p10,p12,p20,p21,p22;
assign p02=mix1[23:16];
assign p01=mix1[15:8];
assign p00=mix1[7:0];
assign p12=mix2[23:16];
//assign p11=mix2[15:8];
assign p10=mix2[7:0];
assign p22=mix2[23:16];
assign p21=mix2[15:8];
assign p20=mix2[7:0];
always @(posedge clk or negedge rst_n)
if(~rst_n)
dx<=11'd0;
else if(sft_en)//
dx<= (-{3'b000,mix1[7:0]}) + (+{3'b000,p02 }) +
(-{3'b000,(p10[7:0]<<1)}) + (+{3'b000,(p12<<1) }) +
(-{3'b000,p20[7:0]}) + (+{3'b000,p22 }) ;
always @(posedge clk or negedge rst_n)
if(~rst_n)
dy<=11'd0;
else if(sft_en)//
dy= (-{3'b000,p00[7:0]}) + (-{3'b000,(p01[7:0]<<1)}) + (-{3'b000,p02[7:0]}) +
(+{3'b000,p20[7:0]}) + (+{3'b000,(p21[7:0]<<1)}) + (+{3'b000,p22[7:0]}) ;
//计算d
reg [10:0] d;
wire [10:0]dx_abs,dy_abs;
assign dx_abs=dx[10]?~dx+1'b1:dx;
assign dy_abs=dy[10]?~dy+1'b1:dy;
always @(posedge clk or negedge rst_n)
if(~rst_n)
d<=11'd0;
else if(sft_en)//
d<=dx_abs+dy_abs; |
|