递归函数 - 2021.2 Chinese

Vitis 高层次综合用户指南 (UG1399)

Document ID
UG1399
Release Date
2021-12-15
Version
2021.2 Chinese

递归函数无法综合。这是适用于可形成无穷递归的函数:

unsigned foo (unsigned n) 
{  
    if (n == 0 || n == 1) return 1;  
    return (foo(n-2) + foo(n-1)); 
} 

Vitis HLS 也不支持其中包含有限数量的函数调用的尾递归。

unsigned foo (unsigned m, unsigned n)  
{  
    if (m == 0) return n;  
    if (n == 0) return m; 
    return foo(n, m%n); 
} 

在 C++ 中,模板可实现尾递归,并且后续可用于可综合的尾递归设计。

注释: 不支持虚拟函数。