Scode의 port에서는 2D array가 1차원 vector로 구현된다. 이것은 일부 verilog가 2차원 array를 port에서 지원하지 않기 때문이고, VHDL 또한 package를 사용해야 하는 번거로움이 있기 때문이다.
Scode에서는 가령 outport(“data[4][8]“)과 같이 2차원 logic으로 선언해도 1D vector로 구현하게 된다.
이러한 방식은 index를 사용하여 값을 설정하고, 얻어 올 때는 index를 1D vector의 slice로 자동 변환해 주기 때문에 별 문제가 없으나, simulation을 할 때는 값을 보기가 불편한 점이 있다.
N = 4
outport("count[N][10]")
for i in range(N):
count[i] <= i
위의 code는 count가 2차 multi logic으로 선언되었지만 실제로는 1D logic으로 변환된다.
entity mv_sim is
port (
count : out std_logic_vector(39 downto 0)
);
end entity;
architecture arch_mv_sim of mv_sim is
begin
count(9 downto 0) <= (others=>'0');
count(19 downto 10) <= ("00" & x"01");
count(29 downto 20) <= ("00" & x"02");
count(39 downto 30) <= ("00" & x"03");
end architecture;
Simulation을 하기 위해서는 mv_sim_tb.sc를 다음과 같이 작성한 후 simulation하면 count 값이 0x00c0200400같이 표현되어 알아보기가 쉽지 않게 된다.
# mv_sim_tb.sc
testbench('mv_sim.sc')
이럴때는 1D vector를 2D array로 변경하면 쉽게 값을 알 수 있다.
mv_sim_tb.sc를 아래와 같이 변경한다.
# mv_sim_tb.sc
testbench('mv_sim.sc')
array("count_arr[%s][%s]" % (len(count),count.width))
for i in range(4):
count_arr[i] <= count[i]
count_arr array를 선언하고, count 출력을 count_arr로 할당하면 count_arr는 array이기에 element 별로 값을 쉽게 볼 수 있다.
변환된 code는 다음과 같다.
entity mv_sim_tb is
end entity;
architecture arch_mv_sim_tb of mv_sim_tb is
type std_10bit_array is array (natural range <>) of std_logic_vector(9 downto 0);
component mv_sim
port (
count : out std_logic_vector(39 downto 0)
);
end component;
signal count : std_logic_vector(39 downto 0);
signal count_arr : std_10bit_array(3 downto 0);
begin
u0_mv_sim : mv_sim port map (
count => count
);
count_arr(0) <= count(9 downto 0);
count_arr(1) <= count(19 downto 10);
count_arr(2) <= count(29 downto 20);
count_arr(3) <= count(39 downto 30);
end architecture;