수색…
소개
재귀는 서브 프로그램이 스스로를 호출하는 프로그래밍 방법입니다. 우아하고 일반적인 방법으로 문제를 해결하는 것이 매우 편리합니다. VHDL은 재귀를 지원합니다. 대부분의 로직 신디사이저도이를 지원합니다. 경우에 따라 추론 된 하드웨어는 동등한 루프 기반 설명보다 훨씬 더 (더 빠른, 동일한 크기) 있습니다.
벡터 해밍 웨이트 계산하기
-- loop-based version
function hw_loop(v: std_logic_vector) return natural is
variable h: natural;
begin
h := 0;
for i in v'range loop
if v(i) = '1' then
h := h + 1;
end if;
end loop;
return h;
end function hw_loop;
-- recursive version
function hw_tree(v: std_logic_vector) return natural is
constant size: natural := v'length;
constant vv: std_logic_vector(size - 1 downto 0) := v;
variable h: natural;
begin
h := 0;
if size = 1 and vv(0) = '1' then
h := 1;
elsif size > 1 then
h := hw_tree(vv(size - 1 downto size / 2)) + hw_tree(vv(size / 2 - 1 downto 0));
end if;
return h;
end function hw_tree;
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow