Custom Functions in HDL - 2024.2 English - 2024.1 English

Vivado Design Suite User Guide: Creating and Packaging Custom IP (UG1118)

Document ID
UG1118
Release Date
2024-11-13
Version
2024.2 English

The Vivado IP packager requires that the IP ports are contained within the port description of the HDL file; therefore, the IP packager does not support custom functions defined in your HDL.

The Vivado IP packager supports standard arithmetic and logical operators to create the desired mathematical expression. To support complex mathematical expressions, the IP packager supports XPATH functions. The following list shows the supported XPATH functions.

  • number max(number, number)
  • number min(number, number)
  • number sum(number, number)
  • number log(base number, number)
  • number pow(number, exp number)
  • number floor(number)
  • number ceiling(number)
  • number round(number)
  • number abs(number)
  • boolean not(boolean)
  • boolean true()
  • boolean false()

For more information on XPATH and the supported functions, see the W3Cx website.

For example, the following Verilog code declares an output port whose width is defined from a ceil_log2 function call on the max_count parameter. The function calculates the log base 2 of the input and returns the smallest integer that is not less than the log result.

output [ceil_log2(max_count)-1:0] count;

To convert this function into an expression that the IP packager can use, replace the custom function with XPATH functions. This change does not occur in the HDL because the custom function is still used, but the IP packager uses a different mechanism for calculating the correct value. The following XPATH expression produces the same result as the custom function as described.

ceiling(log(2, $max_count))-1

The expression contains the XPATH log() function which is passed the base 2, and the value of the max_count parameter. The output of the log() function is passed to the ceiling() function to return the smallest integer not less than the log result. Finally, one is subtracted from the final ceiling result.

For more information on setting the XPATH functions on ports in your custom IP, see the Ports and Interfaces section.