﻿1
00:00:06,580 --> 00:00:12,300
‫Welcome to the barrel shifter explained lecture in this lecture I'll explain what Abair software is

2
00:00:12,390 --> 00:00:20,400
‫and how we can implement one in VHDL barrel shift register Bearse a regular shift register a regular

3
00:00:20,400 --> 00:00:27,690
‫shift register only shifts one bit per clock cycle and a center shift register will only shift left

4
00:00:27,780 --> 00:00:28,760
‫or right.

5
00:00:28,800 --> 00:00:35,700
‫You can also make a universal shift register where you can shift left or right based upon the input

6
00:00:35,760 --> 00:00:41,090
‫and you can also have like a parallel load shift register where you can load all the bits at once or

7
00:00:41,100 --> 00:00:44,960
‫a serial load shift register where you shift all the bits in.

8
00:00:45,180 --> 00:00:50,940
‫The main thing to note with a standard shift register is that you can only every clock cycle you'll

9
00:00:50,940 --> 00:00:54,400
‫make one shift whether it's left or right.

10
00:00:54,480 --> 00:01:01,140
‫Now if we compare that to a barrel shifter Barish after allows you to shift an number of bits on a single

11
00:01:01,140 --> 00:01:06,870
‫clock cycle and this end means that it's a configurable input on one clock cycle.

12
00:01:06,870 --> 00:01:08,300
‫I can shift one bit.

13
00:01:08,340 --> 00:01:15,130
‫I can shift two I can shift three for any arbitrary number of bits as long as However wide my register

14
00:01:15,120 --> 00:01:15,790
‫is.

15
00:01:15,990 --> 00:01:21,840
‫And this will happen on one clock cycle and you can also like to shift to the left or right just the

16
00:01:21,840 --> 00:01:22,950
‫same.

17
00:01:22,980 --> 00:01:29,160
‫Now the downside of the barrel shifter versus the regular shift register is that it will require slightly

18
00:01:29,160 --> 00:01:36,600
‫more resources that moment however what you will gain is a speed factor if you want to shift say 8 bits

19
00:01:36,600 --> 00:01:38,990
‫to the right with a center shift register.

20
00:01:39,060 --> 00:01:43,800
‫It's going to take you eight clock cycles to get there with the barrel shift or you can do it in a single

21
00:01:43,800 --> 00:01:44,990
‫clock cycle.

22
00:01:45,000 --> 00:01:49,410
‫So in theory here and in reality are eight times faster.

23
00:01:49,410 --> 00:01:54,930
‫And so that's where the advantage of the barrel shifter is a standard shift register comes in.

24
00:01:54,930 --> 00:01:56,870
‫Now eight minutes you probably might not notice that.

25
00:01:56,880 --> 00:02:03,900
‫But if you have a really large register a 64 bit 128 that registers even larger and you can perform

26
00:02:04,190 --> 00:02:07,420
‫a 128 bit shift on one single clock cycle.

27
00:02:07,470 --> 00:02:14,980
‫And so that's greatly useful and this is very powerful Let's take a look at an example of we have an

28
00:02:14,980 --> 00:02:17,540
‫8 bit barrel shifter.

29
00:02:17,890 --> 00:02:24,040
‫You'll see that we have our input which is seven down is zero meaning that it's eight minutes wide.

30
00:02:24,040 --> 00:02:27,750
‫We have our select one down to zero two bits wide.

31
00:02:28,120 --> 00:02:34,540
‫And then we have our shift to down to zero reset and clock line and then we have output.

32
00:02:34,660 --> 00:02:37,660
‫So we look at a table we have the different time steps.

33
00:02:37,660 --> 00:02:41,920
‫So if we want to go our time zero we have our input.

34
00:02:41,980 --> 00:02:43,070
‫A certain bit.

35
00:02:43,180 --> 00:02:49,920
‫8 bits wide and our select is equal to 3 which means that we want to do a load operation.

36
00:02:49,930 --> 00:02:54,260
‫So we're going to take the bits that are on our input and put them in the register.

37
00:02:54,430 --> 00:02:59,400
‫And these are register is what we're going to see on the output of our shift register.

38
00:02:59,720 --> 00:03:05,740
‫And if we keep A.M.A. the time steps you can see that will do different operations on our on our select

39
00:03:05,920 --> 00:03:06,600
‫input.

40
00:03:06,700 --> 00:03:08,210
‫So our select is a zero.

41
00:03:08,290 --> 00:03:09,660
‫That is a hold.

42
00:03:09,790 --> 00:03:14,050
‫So on the whole we're not going to do anything we're just going to keep the same same there so you can

43
00:03:14,040 --> 00:03:19,420
‫say a register doesn't change it just now has a value that was on our template and then our select becomes

44
00:03:19,420 --> 00:03:20,400
‫a 2.

45
00:03:20,440 --> 00:03:27,740
‫Now our register is shifted left to the value whatever shift value is which is the value of three minute

46
00:03:27,940 --> 00:03:33,630
‫shift left three three bits and if you just follow through you'll see our next one we're going to shift

47
00:03:33,650 --> 00:03:34,600
‫right.

48
00:03:34,750 --> 00:03:37,860
‫The amount that is on our shift input which is a 4.

49
00:03:37,900 --> 00:03:44,590
‫So we're going to shift right for bits and you'll see that the register on the next step has that implementation

50
00:03:44,590 --> 00:03:50,830
‫has been shifted right for bits and if he falls the time steps are we have a shift right by one bit

51
00:03:51,070 --> 00:03:54,730
‫shift left by two bits and then our select is a zero.

52
00:03:54,820 --> 00:03:58,250
‫And our shift is zero which is once a zero we know the hold.

53
00:03:58,300 --> 00:03:59,930
‫So now we're just holding that output.

54
00:04:00,120 --> 00:04:04,960
‫And that's kind of the huge thing with the barrel shifter is that if I wanted to do any one of these

55
00:04:04,960 --> 00:04:12,070
‫other operations where on time to I have a shift of three it's going to take three clock cycles to do

56
00:04:12,070 --> 00:04:12,570
‫that.

57
00:04:12,610 --> 00:04:14,850
‫We're on the barrel shifter one clock cycle.

58
00:04:14,860 --> 00:04:16,330
‫I now have that output.

59
00:04:16,360 --> 00:04:21,910
‫And so you gain a lot of speed but the con is that it takes a few more resources to implement but you

60
00:04:21,910 --> 00:04:23,820
‫do gain a lot more in speed.

61
00:04:24,520 --> 00:04:28,090
‫So let's take a look at how would you design the barrel shifter.

62
00:04:28,090 --> 00:04:34,210
‫If we take a block diagram just to show kind of how the barrel shifter could be design you would have

63
00:04:34,210 --> 00:04:39,390
‫a process we would call a shift left and a process will of course shift right.

64
00:04:39,580 --> 00:04:41,830
‫And then our process would point output.

65
00:04:41,830 --> 00:04:48,190
‫So every time the shift amount changes you are going to shift left and shift right that amount and that

66
00:04:48,190 --> 00:04:52,900
‫process is going to continue to be happening so soon that changed my shift about my shift left and my

67
00:04:52,900 --> 00:04:53,460
‫shift right.

68
00:04:53,470 --> 00:04:54,660
‫We're going to change.

69
00:04:55,180 --> 00:05:02,290
‫And then my output when I see a clock based on my select if I'm selecting my shift right or shift left

70
00:05:02,380 --> 00:05:08,100
‫I'm just going to select the output that s r red or s l Reg value.

71
00:05:08,110 --> 00:05:13,070
‫And so in theory what we're doing every single clock cycle before that clock cycle occurs.

72
00:05:13,150 --> 00:05:19,660
‫We're shifting left and shifting right at the same exact time based upon the shift amount input and

73
00:05:19,660 --> 00:05:20,800
‫then the clock cycle occurs.

74
00:05:20,800 --> 00:05:26,680
‫We're going to make the decision with the mux inside of our process or out the process and decide am

75
00:05:26,690 --> 00:05:32,170
‫my -- the shift left register or the shift right register and that's how we can make it happen

76
00:05:32,200 --> 00:05:35,350
‫on a single clock cycle before that clock cycle occurs.

77
00:05:35,350 --> 00:05:41,800
‫We're already doing the left shifting and the right shifting and based on the input we're giving it

78
00:05:41,920 --> 00:05:46,630
‫we're going to say OK we're selecting a shift left or shift right because both those outputs have already

79
00:05:46,630 --> 00:05:52,600
‫been shifted left or right the number of bits that we have selected.

80
00:05:52,620 --> 00:05:57,090
‫Now the understanding of how the barracks filter works let's get started implementing one on your development

81
00:05:57,090 --> 00:05:57,750
‫board.

