Bit-level operations are often desirable to be used in control hardware designs. In this lecture, 1
I will talk about the common bit-level operations available in Vivado-HLS. 2
The length() member function returns the width of the arbitrary precision data type. 3
For example, if a has 41 bits, 4
then the function returns 41. 5
This function is synthesisable and can be used both in design and test bench files. 6
The concatenation operator mergers two numbers together. 7
The width of the returned value is the sum of the widths of the operands. The concat member function 8
can perform this operation. 9
Let’s assume a 5-bit variable named b and a 7-bit variable called c. Then b.concat(c) has 10
12 bits in which c is placed on the lower bits and b is located on the higher bits. 11
The c.concat(b) also has 12 bits in which b is placed on the lower bits and c is located on 12
the higher bits. 13
The overloaded comma operator also can be used to perform the concatenation. In this case, parentheses enclose 14
the two concatenated values that are separated by an overloaded comma. 15
This slide shows the same concatenation operations as the previous slide but by using the overloaded 16
comma. 17
Selecting a specific bit position in a variable is another common operator used in hardware design. The overloaded 18
square brackets can be used to point out a specific bit in an arbitrary precision value. 19
An integer value inside the brackets denotes the index of the position. The index of the LSB bit 20
of the value is 0, and the MSB index is the value bit-width minus one. 21
The returned value by the overloaded square brackets is a reference value that can set or clear 22
the corresponding bit. 23
Let’s consider a 7-bit variable shown in this example. The bit value at index 4 is 0 24
and can be accessed by n[4]. 25
And it can be modified by assigning the value 1 to n[4]. 26
Selecting a set of consecutive bits in an arbitrary precision data type is very useful in designing hardware 27
controllers. 28
The rang member function receives two input arguments and returns the value represented by the range 29
of bits specified by the arguments. The two arguments represent the most significant bit (MSB) position of the 30
range, and the least significant bit (LSB). 31
Let’s consider the two-variable r and p. Then p.rang(3, 0) returns the four bits of the 32
p variable from index 3 to 0. 33
Overloaded parentheses also can be used to determine a range. 34
Bit-level logical operators perform another group of bit-wise operations on arbitrary precision values. 35
The goal of the next lecture is to introduce these operators. 36
This is our takeaway message. 37
There are several bit-level operations in HLS including Concatenation, Bit selection, Range selection 38
Now the quiz question. What is your suggestion for the bit-width of the r variable and what 39
would be its value after execution of this code snippet?