Pointer as the essence of C language, better understanding for software designers, but in the design of xilinx vivado HLS high-level language synthesis, because the corresponding hardware elements are difficult to explain with the concept of software, often used by programmers and VHLS tools A headache. This paper uses a simple and easy-to-understand description method, combined with specific c code examples, describes in detail the design types of commonly used three pointers, and when using them as top-level function parameters, different coding styles and HLS constraint strategies are used to satisfy the designer's pointer. As a requirement for the RTL interface.
Basic pointer typeThe basic pointer type refers to the pointer has no operation or multiple accesses (read and write). When the pointer is used as a parameter of the top function, the pointer is integrated into a wire type or a handshake protocol type interface. Example 1-1 below:
Void pointer_basic (dio_t *d) {
staTIc dio_t acc = 0;
Acc += *d;
*d = acc;
}
Example 1-1 Basic Type Pointer as Top Level Function Parameter
In this example, the value of the variable pointed to by the pointer is simply read and written, and there is no offset or pointer (address) operation on the pointer. The interface is integrated into a linear RTL interface.
2. The type of pointer operation.When the pointer is used as a function of the top layer function and there is a pointer operation in the function, we call it the pointer operation type. Pointer operations often limit the types of interfaces that the pointer may synthesize. In the following example, the pointer performs an offset operation for accumulating data, reads the accumulation from the second value, and writes each accumulated result to the previous address.
Void pointer_arith (dio_t *d) {
staTIc int acc = 0;
Int i;
For (i=0;i"4;i++) {
Acc += *(d+i+1);
*(d+i) = acc;
}
}
Example 1-2 pointer operation type as top-level function parameter
The following code examples 1-3 are testbench for this pointer operation type simulation. Because the for loop inside the function pointer_arith accumulates data, the testbench allocates the address space through the array d[5] and assigns an value to the array.
Int main () {
Dio_t d[5], ref[5];
Int i, retval=0;
FILE *fp;
// Create input data
For (i=0;i"5;i++) {
d[i] = i;
Ref[i] = i;
}
// Call the funcTIon to operate on the data
Pointer_arith(d);
// Save the results to a file
Fp=fopen("result.dat","w");
Printf(" Din Dout", i, d);
For (i=0;i"4;i++) {
Fprintf(fp, “%d â€, d[i]);
Printf(" %d %d", ref[i], d[i]);
}
Fclose(fp);
// Compare the results file with the golden results
Retval = system("diff --brief -w result.dat result.golden.dat");
If (retval != 0) {
Printf("Test failed!!!");
Retval=1;
} else {
Printf("Test passed!");
}
// Return 0 if the test
Return retval;
}
Example 1-3 pointer operation type testbench as a top-level function parameter
Simulate the code of the above example 1-3 in the C compiler environment, the results are as follows:
Din Dout
0 1
1 3
2 6
3 10
Test passed!
The problem with pointer arithmetic is that, in general, pointer offsets are irregular and pointer data cannot be accessed in order. Wire, handshake type or Fifo interface type has no way to access data out of order.
For the wire type interface, the data can be read in when the design itself is ready to receive data, or when the data is ready to be ready. For handshake and Fifo type interfaces, data is read in or written out when the control signal allows the operation to proceed.
In the case of the wire, handshake or FIFO type interface above, data starts at 0 elements and must arrive (write) in order. In the example 1-2 of the pointer operation, the first data is read from index 1 (i starts at 0, 0+1=1), corresponding to the second element of the data d[5] in the testbench.
When this situation is applied in hardware, a data index of some format is required. This case is not supported for the wire type, or the handshake type or the Fifo type. The code like the above example 1-2 pointer operation can only be integrated into the ap_bus interface, because this interface has an address, and when the data is accessed (read and write), it is used for the corresponding data index indication.
There is also a way, the code must be modified to the style of the following examples 1-4, using the data array as an interface instead of the pointer. This method applies the principle of integrating the RAM into the RAM interface (ap_memory) when the array is used as the top layer parameter. The memory interface can use the address as the index of the data and can be executed out of order without sequential access operations.
Void array_arith (dio_t d[5]) {
staTIc int acc = 0;
Int i;
For (i=0;i"4;i++) {
Acc += d[i+1];
d[i] = acc;
}
}
Example 1-4. The pointer operation type is changed to the array as the top-level function parameter.
Wire types, handshake types, or Fifo type interfaces are only available in data flow mode, so they cannot be used in relation to pointer operations (unless data starts at index 0 and is processed sequentially). Also note that if you want to integrate into a FIFO interface, the Fifo interface type must be read-only or write-only, and there must be no read or write operations.
3. Multiple read/write (access) pointer typesMultiple read and write pointer types are generally used as an interface to describe a data flow pattern.
When the top layer function parameter uses a pointer, the function body must carefully consider the pointer when it performs multiple access operations. When a pointer is read or written multiple times in the same function, multiple pointer accesses occur, causing the following problems:
1. Use the volatile qualifier for multiple accesses to any function pointer argument.
cheap usb flash drive,wholesale usb sticks,wholesale usb drives cheap, Modern cheap usb flash drives,bulk usb flash drives
Shenzhen Konchang Electronic Technology Co.,Ltd , https://www.konchang.com