|
楼主 |
发表于 2011-2-14 18:18:02
|
显示全部楼层
各位:
把代码改了一下,请帮忙看看哪儿还有问题。先谢谢了。
comp.v
`timescale 1ns/1ns
module comp(
in1,//previous bigger(smaller) number
in1_index,
in2,//current data input
in2_index,
tc,
min_max,
data_out,
data_index
);
parameter WIDTH = 4; // element WIDTH
parameter NUM_INPUTS = 8; // number of elements in input array
parameter INDEX_WIDTH = 3; // size of index pointer = ceil(log2(NUM_INPUTS))
input [WIDTH-1:0] in1;
input [WIDTH-1:0] in2;
input [INDEX_WIDTH-1:0] in1_index;
input [INDEX_WIDTH-1:0] in2_index;
input tc;
input min_max;
output [WIDTH-1:0] data_out;
output [INDEX_WIDTH-1:0] data_index;
wire [WIDTH-1:0] comp1;
wire [WIDTH-1:0] comp2;
wire comp_out;
wire comp_tmp;
assign comp1=tc?{~in1[WIDTH-1],in1[WIDTH-2:0]}:in1;
assign comp2=tc?{~in2[WIDTH-1],in2[WIDTH-2:0]}:in2;
//which one is even bigger
assign comp_tmp=(comp1>=comp2)?1'b1:1'b0;
assign comp_out=min_max?(~comp_tmp):comp_tmp;//when min_max=1, we need bigger number
//when min_max=0, we need the small one
assign data_out=comp_out?in2:in1;
assign data_index=comp_out?in2_index:in1_index;
endmodule
DW_minmax.v
`timescale 1ns/1ns
module DW_minmax_tmp(
a,
tc,
min_max,
value,
index
);
parameter WIDTH = 4; // element WIDTH
parameter NUM_INPUTS = 8; // number of elements in input array
parameter INDEX_WIDTH = 3; // size of index pointer = ceil(log2(NUM_INPUTS))
input [ WIDTH* NUM_INPUTS-1:0] a; //Concatenated input vector
input tc; //0=unsigned,1=signed
input min_max; //0=find min,1=find max
output [ WIDTH-1:0] value; //min or max value found
output [ INDEX_WIDTH-1:0] index; //index to value found
reg [ WIDTH-1:0]b[ NUM_INPUTS-1:0];
reg [ WIDTH* NUM_INPUTS-1:0] a_tmp;
reg [ INDEX_WIDTH-1:0] pi;
//wire [ INDEX_WIDTH-1:0] j;
wire [ WIDTH-1:0] value;
wire [ INDEX_WIDTH-1:0] index;
wire [WIDTH-1:0]in1[NUM_INPUTS-1:0];
wire [INDEX_WIDTH-1:0] index_in1[NUM_INPUTS-1:0];
always @(a)
begin: takeout
a_tmp=a;
for (pi=0;pi< NUM_INPUTS-1;pi=pi+1)
begin
b[pi] = a_tmp[ WIDTH-1:0];
a_tmp = a_tmp>> WIDTH;
end
b[pi] = a_tmp[ WIDTH-1:0];
a_tmp = a_tmp>> WIDTH;
end
assign in1[0]=b[0];
assign index_in1[0]=0;
generate
genvar i;
for(i=1;i<NUM_INPUTS;i=i+1)
begin:int_comp
comp #(WIDTH,NUM_INPUTS,INDEX_WIDTH) compare(
. in1 ( in1[i-1] ),
. in1_index ( index_in1[i-1] ),
. in2 ( b[i] ),
. in2_index ( i ),
. tc ( tc ),
. min_max ( min_max ),
. data_out ( in1[i] ),
. data_index( index_in1[i] )
);
end
assign value=in1[NUM_INPUTS-1];
assign index=index_in1[NUM_INPUTS-1];
endgenerate
endmodule |
|