0
1
00:00:01,760 --> 00:00:07,520
After declaring an arbitrary precision variable, now the question is: What are the rules of assigning 
1

2
00:00:07,520 --> 00:00:09,000
a value to these variables?
2

3
00:00:09,530 --> 00:00:11,330
This lecture will answer this question.
3

4
00:00:13,080 --> 00:00:17,470
The arbitrary-precision variable initialisation is explained in the previous lecture. 
4

5
00:00:17,940 --> 00:00:24,150
These variables can also be assigned together using normal or compound assignment operators in C/C++ 
5

6
00:00:24,150 --> 00:00:28,470
language including =, +=, -= and others.
6

7
00:00:29,250 --> 00:00:31,140
This example shows the normal assignment. 
7

8
00:00:32,610 --> 00:00:37,740
Notice that, a variable can also be assigned to another variable upon its declaration, thanks to 
8

9
00:00:37,740 --> 00:00:41,220
the constructors provided by arbitrary precision class templates.
9

10
00:00:43,350 --> 00:00:47,520
What would happen if we assign two variables that their bit-widths are not the same?
10

11
00:00:48,680 --> 00:00:55,730
There are two general cases: wider assignment and narrower assignment. Let’s consider three arbitrary 
11

12
00:00:55,730 --> 00:01:03,680
variables a, b, and c with 10, 17 and 8 bit-widths. If we want to assign a to b, then we have a
12

13
00:01:03,680 --> 00:01:05,390
wider assignment situation. 
13

14
00:01:06,300 --> 00:01:12,330
What should we do with the extra bits in the b variable? If we want to assign b to c, then we have 
14

15
00:01:12,330 --> 00:01:14,070
a narrower assignment situation. 
15

16
00:01:14,820 --> 00:01:18,510
Now, what should we do again with the extra bits in the b variable? 
16

17
00:01:18,540 --> 00:01:20,820
The answer depends on the variables signedness.
17

18
00:01:21,960 --> 00:01:30,720
Three techniques handle these situations: Sign-extension, Zero-extension, And truncation. Through the
18

19
00:01:30,720 --> 00:01:34,160
following slides, we review these techniques in Vivado-HLS.
19

20
00:01:35,940 --> 00:01:41,760
When assigning the value of a narrower bit-width signed variable to a wider one, the value is sign-extended 
20

21
00:01:41,970 --> 00:01:45,780
to the width of the destination variable, regardless of its signedness.
21

22
00:01:47,890 --> 00:01:54,970
a is defined as a 7-bit signed variable initialised with the 0x5a number, so its value 
22

23
00:01:54,970 --> 00:01:59,130
would be -38. b is defined as a 10-bit signed variable.
23

24
00:01:59,650 --> 00:02:08,200
If we assign a to b, then the value of a is copied to b, and its sign bit fills the extra bits in b. Therefore, 
24

25
00:02:08,590 --> 00:02:11,560
the b holds the same number, which is -38.
25

26
00:02:12,190 --> 00:02:15,100
Now consider the 10-bit unsigned c variable. 
26

27
00:02:15,610 --> 00:02:22,510
If we assign a to c, then a is copied to c and then as a is signed the sign-extension mechanism extends 
27

28
00:02:22,510 --> 00:02:30,280
the a sign bit into the extra bits in c.  Notice that the sign-extension is applied even if c is unsigned.
28

29
00:02:31,160 --> 00:02:37,170
Explicit casting of the source variable might be necessary to ensure the expected behaviour on assignment.
29

30
00:02:37,850 --> 00:02:45,020
For example, if we assign a to c with ap-uint<10> typecast, then the output is as follows. 
30

31
00:02:45,560 --> 00:02:51,530
As the right-hand side of the assignment is unsigned, then the size extension won’t happen, and the 
31

32
00:02:51,530 --> 00:02:55,890
extra-bits are filled with zero, which is called zero-extension. 
32

33
00:02:59,520 --> 00:03:05,580
An unsigned source variable is zero-extended before assignment. For example, if we define variable 
33

34
00:03:05,580 --> 00:03:14,640
a as a 7-bit unsigned variable initialised with the 0x5a hex number, then its value is 90
34

35
00:03:15,250 --> 00:03:21,150
If we assign a to a 10-bit unsigned variable, then the value of the destination variable would be 90.
35

36
00:03:26,520 --> 00:03:33,050
If we assign a to a 10-bit signed variable, then the value of the destination variable would also be 90.
36

37
00:03:41,570 --> 00:03:45,160
Using a typecast during this assignment might change the result. 
37

38
00:03:58,020 --> 00:04:05,100
Assigning a wider source variable to a narrower one leads to truncation of the assigned value. All bits beyond 
38

39
00:04:05,100 --> 00:04:09,000
the most significant bit (MSB) position of the destination variable are lost.
39

40
00:04:10,360 --> 00:04:15,940
There is no special handling of the sign information during truncation, which may lead to unexpected 
40

41
00:04:15,940 --> 00:04:16,500
behavior.
41

42
00:04:21,430 --> 00:04:27,220
How can we print an arbitrary precision data type on the screen? The next lecture addresses this question.
42

43
00:04:29,920 --> 00:04:35,420
These are our takeaway messages. There are two different cases if we assign two variables that their 
43

44
00:04:35,440 --> 00:04:40,750
bit-widths are not the same: wider assignment and narrower assignment.
44

45
00:04:41,870 --> 00:04:49,220
There are three techniques are introduced to handle these situations which are: Sign-extension, Zero-extension
45

46
00:04:49,550 --> 00:04:50,740
and truncation.
46

47
00:04:53,600 --> 00:04:59,090
Now the quiz question. What are the values of all variables in this code after execution?
