VHDLではこう書いてある。
type sftd_2dvec IS ARRAY (3 downto 0) of std_logic_vector(7 downto 0);
type shiftin is array (3 downto 0) of std_logic;
signal sreg_out : sftd_2dvec;
signal shtin : shiftin;
GSREG : for K in 3 downto 0 generate
process(reset, clk) begin
if reset='1' then
sreg_out(k) <= (others => '0');
elsif clk'event and clk='1' then
if sreg_ena = '1' then
if all_sreg_load='1' then -- Load
sreg_out(k) <= sreg_in(k);
else -- shift
sreg_out(k)(7 downto 1) <= sreg_out(k)(6 downto 0);
sreg_out(k)(0) <= shtin(k);
end if;
end if;
end if;
end process;
end generate GSREG;
これをVerilog-HDLでこう書いたらエラー。
reg [7:0] sreg_out [3:0];
reg [3:0] shtin;
always @(posedge clk or posedge reset) // shift register
for(i=0; i<4; i=i+1)
if(reset)
sreg_out[i] <= 8'h0;
else if(clk)
if(sreg_ena)
if(all_sreg_load)
sreg_out[i] <= sreg_in[i];
else begin
sreg_out[i][7:1] <= sreg_out[i][6:0];
sreg_out[i][0] <= shtin[1];
end
改定 入門Verilog HDL記述の61ページに”レジスタ配列ではビット選択や部分選択はおこなえない”と書いてあった。なんと不便な!!
ちょっとむっとしたが回避策を取る。
wire [7:0] temp0, temp1, temp2, temp3;を宣言して、
assign temp0 = sreg_out[0];
assign temp1 = sreg_out[1];
assign temp2 = sreg_out[2];
assign temp3 = sreg_out[3];
always @(posedge clk or posedge reset) // shift register
for(i=0; i<4; i=i+1)
if(reset)
sreg_out[i] <= 8'h0;
else if(clk)
if(sreg_ena)
if(all_sreg_load)
sreg_out[i] <= sreg_in[i];
else begin
case(i)
0: sreg_out[i] <= {temp0[6:0], shftin[1]};
1: sreg_out[i] <= {temp1[6:0], shftin[1]};
2: sreg_out[i] <= {temp2[6:0], shftin[1]};
default: sreg_out[i] <= {temp3[6:0], shftin[1]};
endcase
end
こう書いた。これでいいのだろうか?とりあえずエラーはなくなったが。。。
どうなんだろうか?あまりレジスタ配列は使わない方がいい?
レジスタ配列でのビット選択や部分選択はVerilog 2001ではOKと本には書いてあるが、XSTが対応していないのだろうか?
ぜひ対応してもらいたい。