How can we describe a multiplexer in HLS? In this lecture, 1
I am going to introduce three different coding techniques to describe a multiplexer. 2
Let’s consider the 2x1 mux defined in the previous lecture. 3
The input a is connected to the output 4
if s=0, otherwise b is transferred to the output. 5
Probably, the simplest way to code this mux in C/C++ is using the ternary conditional operator, in which 6
a is copied to O if s equals to 0 otherwise b is copied to O. 7
Another way of coding this 2x1 MUX is by using the if-else statement. Notice that if you 8
are going to implement a mux with a conditional if, you should clearly mention both if and else 9
parts. 10
Notice that these two conditional if statements may not be synthesised into combinational circuits as 11
they both should keep track of the previous value of the output o. 12
The left-hand side if statement does not define the else part, which means if s is not 0, the output 13
should keep its previous value which in some cases it needs a kind of memory in the hardware implementation. 14
The right-hand side if statement has defined the else part, but it says that that output should keep 15
its previous value. 16
This if statement also can be synthesised into sequential logic in some cases. 17
Therefore, to make sure that the final implementation is combinational, 18
we should explicitly define all parts in if-else statements. 19
Another way of describing a multiplexer in HLS is by using the switch-case statement. Notice that, 20
there should be an execution path in the switch-case for any possible value of the select input to represent 21
a combinational circuit. 22
In this example, all cases in the switch have been mentioned explicitly. 23
In addition, the sel variable in the code has 2 bits that can directly connect to the MUX in the 24
hardware implementation. 25
This code is another example of a combinational multiplexer described by the switch-case statement. 26
The sel variable in the code has 8-bits which means it can define 256 different cases. 27
However, the code only has 4 data inputs that are a, b, c and d. 28
Therefore multiple cases in the switch statement should send the same input to the output. So, the sel 29
cannot directly drive the MUX select input. 30
A selection logic” which is a combinational circuit” should generate the select input for the MUX. 31
Transforming data from one format to another is one of the combinational circuit task. The next lecture 32
will explain the concept of encoder and decoder, the two common combinational circuits transforming 33
data. 34
These are our takeaway messages. The software if-then-else statement can be used to implement 35
multiplexers. 36
The switch-case statement is another way of describing a multiplexer in HLS. 37
Now the quiz question. Draw the structure of a combinational circuit that can implement this HLS code.