0:13 know [Music]
0:25 everybody Welcome to the course vlsi
0:29 design flow RTL to GDs this is the 12th
0:32 lecture in this lecture we will be going
0:40 in the earlier lectures we had seen that
0:44 the logic synthesis consists of various
0:48 smaller tasks for example the RTL
0:51 synthesis then logic optimization then
0:54 technology mapping and then technology
0:57 dependent optimization
1:01 so the first part of logic synthesis is
1:04 RTL synthesis and in RTL synthesis what
1:08 do we do so we basically translate we
1:12 translate the given verilog code or the
1:16 RTL model into a net list consisting of
1:20 generic logic gates so this is the this
1:23 is the the responsibility of RTL synthesis
1:25 synthesis
1:27 so the RTL synthesis is also a
1:30 complicated task and we further break it
1:34 down into smaller tasks so the smaller
1:37 tasks are parsing elaboration and then
1:40 translation of various very low
1:43 constructs in the code to the uh to the
1:46 logic gates and also some optimizations
1:50 which are RTL construct specific
1:53 so in in this lecture we will be looking
1:58 into the parsing and elaboration and the
2:00 translation of some of the important
2:03 very lock constructs and in the next
2:07 lecture will be uh going through uh the
2:09 translation of more very low construct
2:12 and also look into the optimization
2:24 so the given an RTL code or an art very
2:25 log model
2:29 um representing an RTL the first task
2:32 that is done by the by the RTL synthesis
2:36 tool is to read the given RTL file files
2:39 and populate a data structure for
2:41 further process
2:46 so ah in the earlier lectures we had
2:49 seen that the verilog code consists of
2:53 various uh it consists of uh characters
2:55 and characters can be grouped together
2:58 into tokens and we have various types of
3:01 tokens for example identifiers keywords
3:04 operators and so on right so the given
3:08 an RTL file and a very low code so the
3:11 first task that is done by the by the
3:12 tool is
3:17 known as lexical analysis so the lexical
3:20 analysis basically ah breaks down the
3:23 given RTL code into tokens various kinds
3:25 of tokens for example keywords
3:27 identifiers and so on
3:31 and after this lexical analysis it
3:33 checks for the grammar of the of the of
3:37 the of the given code whether it it is
3:40 following the ah the prescribed
3:44 syntax and syntax of the verilog
3:47 language and if there are say errors
3:51 then the the in the in that case the uh
3:54 the tool will report report syntax error
3:56 in the code
4:00 if the given code doesn't doesn't follow
4:03 the the the grammar of the verilog language
4:04 language
4:08 ah but if the if if the given RTL code
4:12 is uh is a syntax error free meaning
4:14 that it is following the grammar
4:16 correctly then what the tool will do is
4:19 that it will build and build an uh data
4:21 structure which is uh typically a kind
4:25 of syntax tree or a parse tree and this
4:27 is a kind of hierarchical data structure
4:29 so by hierarchical data structure we
4:33 mean that ah the if some object RTL
4:37 construct is contains some other RTL
4:40 construct then the apparent child
4:42 relationship is maintained and so on so
4:45 that makes a kind of an a hierarchical
4:48 data structure or that based on the
4:52 parent child relationship a hierarchical
4:55 data structure is built for the given uh
4:58 very lock code so let us take an example
5:01 that how it is done so suppose we we are
5:05 given uh or the tool is the RTL
5:08 synthesis tool is given a verilog file
5:10 in which there is a module say top okay
5:13 and for Simplicity we are not showing
5:15 the internals of this top module and
5:18 there is another module say made
5:20 and it contains an always block and so
5:24 on now for this code what will be the
5:27 the the syntax tree or how will that
5:29 syntax tree look like
5:31 so it will be something like this so
5:33 there will be at the top there is a root right
5:34 right
5:39 and so so verilog is in very long the
5:42 module is the top most comp entity of a
5:46 design so there will be if the root will
5:49 have as children various modules so in
5:51 this case there are two modules top and
5:53 mid so those will become the children of
5:57 the root and then the in in mid we have
6:01 the in the in the given code uh we have
6:04 an always block so always block is
6:07 contained within mid so the always block
6:11 will be a child of the module mid right
6:14 and then within ah always block there
6:16 are three statements right we have three
6:19 statements so each statement will form
6:21 one child right so there are two
6:24 non-blocking statements non blocking
6:26 statements right these two are non
6:28 blocking statements and those will
6:31 become a non-blocking state
6:35 so two child will be created uh
6:37 corresponding to those non blocking
6:39 statement and one child will be created
6:41 uh corresponding to the blocking
6:44 statement right now each statement has
6:48 an LHS and rhs right so the the this
6:51 non-blocking statement will contain LHS
6:54 part and the r just part and so on so
6:58 this is how the the the the the given uh
7:01 verilog code will be will be passed and
7:02 a data structure will be built a
7:05 hierarchical data structure and then
7:07 once this hierarchical data structure or
7:11 pass 3 is built then the the RTL
7:14 synthesis goes synthesis tool goes to
7:16 the next step and what is the next step
7:20 the next step is called elaboration so
7:22 what is done in elaboration so in
7:25 elaboration the RTL synthesis tool
7:28 checks whether the connection among the
7:31 RTL specific components are legitimate
7:33 right so
7:35 um we will understand what do we mean by legitimate
7:37 legitimate
7:40 connections OK and if it is legitimate
7:44 legitimate then the then the during
7:48 elaboration the connections are made in
7:51 the internal model that is the the that
7:54 is used to represent the given very log
7:57 code okay so let's take an example
8:00 Suppose there was a that there was a
8:03 design in which we have say one module
8:05 Leaf right we had this is a leaf level
8:08 module and then there is another module
8:10 middle right there is a module medal
8:15 which contains an instance of leaf right
8:17 so this is an instance instantiation of
8:21 leaf so the leaf we say that for this
8:23 instance F1 F1 is the name of the
8:27 instance the master module is
8:30 is a leaf because the name here is
8:33 referring to this other module so the
8:35 master module of this instance F1 is
8:38 leaf and then there is another module
8:42 say top and inside top we have three
8:45 instances two instances of leaf right so
8:50 i1 and I2 are the is are the instances
8:55 with master module as leaf and I3 is an
8:58 instance whose master module is mid this
9:01 one right so this is this is the given
9:04 RTL code if we give this code to the RTL
9:07 synthesis Tool uh then during
9:10 elaboration the linkages between the
9:12 leaf level module sorry the the
9:16 instances and the master modules are
9:19 made and in this instantiation if there
9:21 are some problems of connections then
9:25 those connect problems are reported and
9:27 as elaboration error for example if we
9:31 say that the master module is leaf and
9:34 in leaf we have three ports D clock and
9:37 Q right and here we have written D clock
9:39 and Q so here that there is no problem
9:42 but suppose we made an error and instead
9:46 of writing D here we wrote here D1 right
9:49 so the this kind of error will be create
9:51 there will be
9:54 reported by the RTL synthesis tool
9:57 during elaboration so when the when the
10:00 when the initially the RTL code is read
10:05 at that time there is no no linkage is
10:09 created between the instances and their
10:12 master module right so those in during
10:14 the initial stages the code is read
10:17 module by module so at that time the
10:19 tool doesn't know that what is the
10:22 direction of the input this pen D clock
10:26 and Q and so on right so the tool can
10:29 actually make uh may make some
10:32 simplistic assumption initially so for
10:34 the for the leaf level module Leaf level
10:37 level module Leaf the tool can
10:39 understand that the direction of input
10:41 pin is d
10:44 input pin D A or sorry the the direction
10:47 of Port D is input it will be creating
10:50 for the clock it is input for Q it is
10:54 output right but when it will create the
10:55 module middle
10:59 it will take an is it will uh it will
11:02 process the instance F1 right so it will
11:05 create an instance F1 but while
11:08 processing this module while processing
11:12 this module the the tool will before
11:14 establishing the linkages between the
11:16 instance and the master module it
11:18 doesn't know that what is the direction
11:22 of this pin D this pin clock and this
11:24 pin Q so the tool can make some
11:27 simplistic assumption like treating all
11:31 of them as input pair right so
11:34 um similarly in the module top there are
11:37 three instances Lee or two of leaf and
11:40 one of mid right so in at when the Tool
11:44 is is analyzing this particular module
11:47 top at that time it doesn't know that
11:49 what are the directions of these pins
11:53 pins D clock q and so on and it can make
11:55 and simplestic assumption that all all
12:00 pins are input pins right and after
12:02 elaboration what will it will do is that
12:04 it will create linkages between this
12:08 this instance and the master module this
12:10 instance and the master module and this
12:13 instance in the master module and then a
12:16 design hierarchy will be built and the
12:19 connections will be also be created
12:21 so let us understand that after
12:23 elaboration What will what will happen
12:26 so this was the the the the the view of
12:29 the design when when no elaboration was
12:31 done so in this case what we see that
12:34 the modules are separate so the modules
12:36 and instances are totally separate but
12:39 after elaboration those will be linked
12:42 together so now at the top level so this
12:44 is the top level module in this top
12:47 level module we have two instances
12:51 of leaf with name i1 and I2 and now the
12:53 directions of the
12:57 pins are inferred from looking into this
13:00 ah master module of leaf and D will the
13:01 direction of
13:05 pin D will be taken as input for pin
13:07 clock it will be taken as input and for
13:09 the PIN
13:12 Q it will be taken as output similarly
13:14 the the correct direction will be
13:18 inferred and then and are linked a
13:21 design hierarchy will be built and also
13:24 the connections will be made right now
13:28 during this stage there can be errors or
13:30 elaboration errors that the tool can
13:32 report now when can the error be so
13:35 there are some common situations suppose
13:39 while we are while we are running the
13:41 logic synthesis tool or RTL synthesis
13:44 tool and we we get and these three
13:47 modules these three modules were in
13:51 separate verilog five and by mistake we
13:54 gave only these two files and forgot to
13:58 give this 5 right in that case the tool
14:02 will not be able to establish that what
14:05 does this module Leaf is right because
14:07 the master module of the the master
14:11 module of the instance F1 is leaf and we
14:14 have not given the module corresponding
14:17 to leave by mistake right so if we make
14:19 such kind of mistake then the tool will
14:21 not be able to establish the linkages
14:24 between the instances and the master
14:27 module and as a result what it will
14:30 happen is that it will the tool May
14:33 report an error it will report an error
14:36 that there is no reference of module
14:39 Leaf in the RTL files and therefore it
14:41 is assuming leave to be a black box
14:44 right now this is a situation which is
14:48 which which we encounter commonly in in
14:51 in in our in logic synthesis and it
14:53 means that probably the we have not
14:55 given the reference of or we have not
14:59 given the the given the module which
15:01 contains the description of the module
15:04 leave right so that is one mistake that
15:07 can be made or that can be reported
15:10 during elaboration that the black boxes
15:13 in our ah in in our design right so
15:14 typically there shouldn't be a black box
15:17 in our design otherwise even the
15:19 direction of the of those pins will not
15:22 cannot be inferred for its their
15:25 instantiation and then the the tool can
15:28 behave uh unexpectedly so we should look
15:32 into the the the the warnings or errors
15:34 corresponding to Black Box in our design
15:38 carefully then other kind of Errors can
15:41 be with respect to the port names for
15:44 example if we make error in the name of
15:47 the ports while instantiating then in
15:49 that case the that problem will be
15:51 reported during elaboration or there is a
15:52 a
15:55 mismatch in the width of the of the
15:58 buses and the pins in the instantiation
16:02 then the tool can report error okay
16:06 another responsibility of elaboration is
16:10 that it it processes parameterized
16:13 module so in earlier lectures we we
16:15 discussed that verilog supports
16:18 parameterized modules meaning that we
16:21 can have parameters in our module and
16:24 based on the value of the parameter the
16:26 module can have different interfaces for
16:29 example the the width of a bus or a port
16:33 can change based on the parameter and
16:36 the parameters value can be different in
16:39 different instances so in that case what
16:42 the tool enter will do the RTL synthesis
16:44 tool will typically do the it will
16:48 create separate modules with different
16:50 interfaces for each distinct set of
16:54 parameters okay now what it means let us
16:55 look into an example and then we'll understand
16:57 understand
16:59 so Suppose there was a parameterized
17:02 module counter with a parameter width
17:06 with a default value of 4 right and the
17:08 there are in there is an output Port
17:12 output port with the name count and its
17:15 uh its size depends on the value of this
17:18 parameter width right so the the the
17:22 if the value is default value then the
17:26 out the the output Port count will be
17:33 three down to zero right it will be 4
17:37 bit wide right now during instantiation
17:40 we can change the value of the of the
17:43 parameters for example in in this
17:46 instance C1 we are not changing so in
17:49 this case the default value of 4 will be
17:53 used for count 3 right first the
17:55 instance C1 for the another instance C
17:59 two we are saying that instead of 4 use
18:03 a value of width as eight so in this
18:06 case the value the width of the bus so
18:09 width of the port count will be 8
18:13 instead of 4 right and similarly in the
18:16 third instance in the for the c three we
18:19 have want the width to be 60 right now
18:22 in this case what the tool will do it
18:25 will internally create three different
18:28 modules one for with four another for
18:32 width a eight and third one for weight
18:35 sixty so how will the our design look
18:37 like it will look like something like
18:41 this so for the for the instance C1 with
18:43 the the count will take a value of 3 2 3
18:47 down to 0 or it will take a width of 4
18:50 for C two eight and for c three it will
18:53 be taking sixteen right now what will be
18:56 the name of this this new modules that
18:59 will be created during elaboration so it
19:02 is tool specific typically it will use a
19:04 combination of the name of the parameter
19:07 and its value so it may be say count the
19:09 master module name initially was a
19:12 counter so in this case after during
19:14 elaboration the new module will be
19:17 created and its name can be counter
19:20 underscore width underscore 4 for the
19:22 for the for this module for the other it
19:23 can be counter underscore width
19:26 underscore 8 tools denote that the value
19:31 of the width is 8 and so but note that
19:34 this name is ah the the name of the um
19:36 the master module that will be created
19:39 by the tool it is tool specific the tool
19:43 is free to choose any name
19:46 before going through ah various RTL
19:48 constructs and understanding how they
19:51 are synthesized to logic gates first let
19:55 us understand that which RTL constructs
19:57 are or verilog constructs are
20:00 synthesizable and which all are not
20:03 synthesis synthesizable why because some
20:06 verilog constructs are there which
20:10 support other other design tasks such as
20:13 functional verification and those are
20:17 not meant to be synthesized right so a
20:19 given RTL synthesis tool may not support
20:22 all synthesizable verilog constructs
20:24 right this is also a point that should
20:27 be noted that there is no the the
20:29 language as such doesn't say that what
20:31 is synthesizable and what is not
20:35 synthesizable right so the tool tool it
20:38 it is very much tool specific that which
20:42 which RTL construct uh uh is supported
20:44 by that tool for synthesis and which is
20:46 which are which which is which
20:49 constructs are not supported by the tool
20:51 and therefore as a designer we should be
20:54 aware of the verilog constructs which
20:57 are supported by the synthesis tool that
21:01 we are using and then and then write out
21:05 verilog code and so on in in taking that
21:08 into account so there are some RTL
21:10 constructs which are typically not ah
21:14 not uh not supported by RTL synthesis
21:16 tool so let us understand strand or take
21:19 a look at them so the first thing we
21:21 should note is that the delay specification
21:22 specification
21:25 for example if we write a statement out one
21:26 one
21:29 which is assigned to a after delay of
21:31 say 12 time units
21:36 so this kind of delay specifications are
21:40 not supported by synthesis so these
21:42 delay specifications are typically
21:46 useful for simulations right in the
21:49 simulations we want to understand that
21:52 we the very low code or we want to
21:56 um verify that whether our RTL model uh
21:58 behaves correctly
22:01 when there is a delay of say 12 time
22:05 units right so the hash has delay kind
22:08 of constructs if it exists in the RTL
22:11 code it should be interpreted as that
22:15 this means this this delay is meant to
22:18 simulate and see that what happens to
22:21 our RTL model if this much delay happens
22:25 right but it is not meant to uh say to
22:28 the synthesis tool that insert a delay
22:30 element which has a value of 12 time
22:34 units right so the delay is typically
22:36 what the the synthesis tool will do is
22:39 that in these cases the delays delay
22:42 delay specification for example uh the
22:45 has 12 in this case will be totally
22:48 ignored so the RTL synthesis tool will
22:51 treat the statement as out one is
22:54 assigned to a in a non-blocking manner
22:57 that's it right so the hash 12 will be
22:59 totally ignored
23:02 okay so ah there are other RTL
23:05 constructs which are are not supported
23:07 in synthesis for example initial blocks
23:09 or initial blocks are useful in writing
23:11 test benches that we have seen earlier
23:14 right and then there are four Joint
23:19 Force release and uh data types real and
23:21 time these are not supported for
23:25 synthesis and there are system tasks for
23:27 example dollar display dollar Monitor
23:29 and others those are not supported by
23:32 the synth RTL synthesis too so these are
23:35 these these system tasks are useful in
23:38 verifying our design or or doing
23:42 functional verification or simulation
23:45 now let us look into the RTL constructs
23:48 which which are synthesizable and how
23:51 they will be synthesized so first let us
23:54 look into the assign statement right so
23:57 the continuous assignment statement so
24:00 how how is a continuous assigned ah
24:02 continuous assignment or assign
24:05 statement synthesized if it exists in
24:08 the RTL code so corresponding to the
24:10 assigned statement a combinational
24:12 circuit will be inferred and what
24:14 combinational circuit will be inferred
24:17 it will depend on what is on the rhs of
24:20 the assigned statement so let us take an
24:22 example and understand this suppose we
24:25 are there is a module top and in which
24:28 we have say three assigned statements so
24:31 the first assigned statement says out 1
24:35 is equal to a and b or c right so this
24:38 is the rhs of of the assigned statement
24:42 and the logic will the or the or the the
24:44 synth RTL synthesis tool will
24:47 instantiate logic gates corresponding to
24:51 the ah rhs so it will be something like
24:54 this so for the output Port out one
24:56 right it will be us
24:59 an and and an or gate will be
25:02 instantiated corresponding to these
25:04 operators these logical operators
25:08 similarly for out two since out 2 is of
25:12 a size 4 right it is a it is a bus of
25:16 size 4 so in this case and X and Y are
25:19 also of size 4 so when we assign out 2 2
25:22 is equal to X and Y there will be there
25:25 will be four ah and Gates that will be
25:28 instantiated right so x 0 y 0 will be
25:32 added and out to 0 will be driven by
25:35 that and so on and for the third one out
25:38 three we have a ternary operator so when
25:43 s is true then Q the Out 3 takes the
25:46 value Q otherwise it takes a value of P
25:48 so this is a description corresponding
25:51 to a multiplexer so the tool will ah
25:53 will instantiate a multiplexer in which
25:56 s is s is appearing on the condition
25:59 right so the S will be on the select
26:02 line and P and Q will be on the data line
26:07 now let us look into how the statement
26:11 if else will be synthesized by the RTL
26:14 synthesis 2. now if else is a kind of a
26:16 multiplexer kind of thing meaning that
26:19 if something happens then the then one
26:22 line will be selected otherwise some
26:23 other line will be selected so
26:27 corresponding to if else statement uh uh uh
26:28 uh
26:31 multiplexer will be instantiated in our
26:33 design and the select line of the
26:35 multiplexer will be there will be
26:38 corresponding to the condition that
26:41 appears in the if if condition right so
26:43 let us take an example and understand so
26:47 let us say let's let's look into this
26:50 always block right in this always always
26:53 block there is an if else statement now
26:57 if s is equal to 0 right s is equal to
27:00 one tick P0 that is s is equal to 0 then
27:02 out 1 is equal to
27:06 a right if s is 0 then out 1 is equal to
27:09 a else out 1 is equal to B so
27:11 corresponding to this a multiplexer will
27:13 be created right so out one will be
27:16 driven by this multiplexer on the select
27:18 line will have s y will have S because
27:21 it is coming in the if condition right
27:24 so here we have the select line and when
27:28 a select line takes a value of 0 then a
27:31 is driven to the out one port right and
27:34 as described as as represented in this
27:39 RTL code and if out one if if s takes a
27:43 value of 1 then B will be driven through
27:46 the or to the output Port right so this
27:50 is with the how the how the an if else
27:52 kind of RTL construct will be
27:57 synthesized by the RTL synthesis 2.
27:59 now how will the case statement be
28:02 synthesized so the case statement will
28:05 also be synthesized into a multiplexer
28:08 or a select logic select logic is
28:11 inferred so the size of this multiplexer
28:14 will depend on what is the what is the
28:17 complexity of the case or the or the or
28:20 the signal appearing in the in the case
28:23 statement which is selecting various
28:27 values right for example in the suppose
28:30 we have a state case statement like this
28:33 case statement is like this so in this
28:36 case statement we have the ah the
28:39 selection is based on the signal s and
28:41 what is the size of s the size of s is
28:44 of two bits so in the multiplexer that
28:47 will have will have two lines on the two
28:51 bits on the select line right so this
28:53 kind of case statement will basically ah
28:57 translate into into a four to one
28:59 multiplexer because there are two select
29:03 lines as 0 and S1 right
29:06 and if if these two take a value of 0 0
29:10 right then line a will be selected right
29:14 if they take value of 0 and
29:18 sorry this one is one and this one is 0
29:22 then B will be selected and so on right
29:25 so this is how the case statement will
29:28 be selected right now in a case
29:30 statement verilog supports that there
29:34 can be multiple matches right so if if
29:36 we write say question mark or don't care
29:39 conditions in that case there can be
29:42 multiple matches and in that case what
29:44 will the behavior of the verilog code it
29:48 will be that whatever matches first that
29:50 will be selected by the case statement
29:51 right that is what is defined by the
29:54 language and therefore if there are
29:56 multiple matches in the case statement
30:00 then the tool will uh will infer or
30:02 instantiate a kind of priority logic
30:05 right so let us take an example and and
30:09 understand it now suppose this we the
30:11 code is like this the case statement is
30:15 like this right now s is again of 2 bit
30:19 means it is a two bit line right now how
30:21 many possibilities are there for this
30:23 this signal to take right so it can take
30:28 zero zero zero one one zero and one
30:32 so what we are saying is that if in or
30:35 what this description says that if one
30:37 question mark means that this can take
30:41 any value 0 or 1 out 1 takes a value of
30:47 a right meaning that if it is 1 1 or 1 0
30:51 in both these cases a value of a will be
30:54 driven to the output right and then
30:56 what's the what the second line says
31:04 that if if it matches either with 0 1 or
31:08 1 1 it should it should out one should
31:12 be driven to B but note that the case 1
31:14 1 is already covered in the first case
31:16 right so it cannot match in the second
31:20 case right so only zero zero one case
31:24 will take take a value of B and then
31:28 default is d 0 0 and in the 0 0 case out
31:30 one will get a value of C
31:33 right so now we have to instantiate
31:36 logic gates such that this kind of
31:39 priority is maintained in the logic
31:41 structure or the or the or in the
31:43 implementation of the circuit so let us
31:45 look into how the instantiation will be
31:47 done so it will be something like this
31:51 so if what we have we have here is that
31:56 if S1 takes a value of 1 right if k s 1
31:59 takes a value of 1 then out 1 gets a
32:03 value of a right it will get the value
32:05 of a this line will be totally ignored
32:09 right so what it means is that if the Y
32:14 if the the value of s is 1 0 or 1 1 in
32:18 both cases out one will get a value of a
32:20 so this is what we wanted our priority
32:23 to be right now if it it does not match
32:26 the the it it does not get the first or
32:29 it does not match the first statement or
32:32 first condition one question mark then
32:34 it goes to the next statement and in
32:36 that next statement what it does is that
32:42 it looks for S 1 in the S 0 or the lower
32:46 bit right so if s 0 bit is one then B
32:49 will be selected and it will be going to
32:54 out one and if s 0 is 0 then C will be
32:57 selected and to the output so the
32:59 required priority that we wanted to have
33:03 in in as described in this RTL code that
33:06 is maintained by this circuit right
33:09 so this kind of priority can also be
33:12 enforced by if else if kind of construct
33:16 in that case case also the ah a priority
33:20 based logic gate structure will be
33:23 implemented in the ah in the in the in
33:25 the net list generated by the RTL
33:28 synthesis 2.
33:32 now let let us take a few examples of
33:34 the often always block and then
33:37 understand that how always block will be
33:40 synthesized so first let us take a next
33:43 a few examples for the case when the
33:47 always block is Edge sensitive right so
33:50 ah let us consider this module D flip
33:53 flop so in this module we have an always
33:56 Block in which which is sensitive to the
33:58 clock signal clock and whenever a
34:01 positive Edge to the clock signal
34:04 appears then whatever in there on the D
34:07 that appears on the Queue or that is
34:10 assigned to Q otherwise Q retains its
34:13 old value so this is a description of a
34:16 d type flip flop and for this in this
34:19 module will the RTL synthesis tool will
34:23 basically instantiate a d flip flop as
34:27 as shown here right so whenever a clock
34:29 positive Edge appears set the clock
34:31 whatever is in the data that will be
34:35 propagated to the to the Q pin and it
34:38 will appear at the Port queue
34:42 now let us take another example in which
34:45 the always block is sensitive to both
34:48 clock signal and the reset signal right
34:50 and it is sensitive to possessed clock
34:56 and negative reset so when reset takes a
35:00 value of 0 then Q is assigned a value of
35:04 0 otherwise Q is assigned a value of d
35:06 right so note in this case that this
35:10 clock and reset these two signals can
35:13 appear or ah independent of each other
35:16 right and therefore this is this is a
35:18 kind of this reset signal is a kind of
35:20 an asynchronous reset meaning that it
35:24 can come anywhere during any time or of
35:27 the clock period and the it can reset
35:30 the reset the ah the the flip flop right
35:33 so corresponding to this description uh
35:36 flip flop will be instantiated in which
35:39 there will be an asynchronous reset pen
35:42 asynchronous reset pin and there it is
35:46 it will be it is sensitive to or reset
35:49 is active when it takes a value 0 and
35:51 therefore will have a bubble here
35:53 meaning that when reset is equal to 0
35:58 then Q will take a value of 0 right
36:01 now let us take another example of an
36:05 always block which is sensitive just to
36:08 the clock signal so the Val this always
36:12 block will be triggered only when poses
36:16 clock appears right now but when it
36:18 enters it looks for first the signal
36:22 reset and if reset is equal to 0 then Q
36:25 becomes 0 right otherwise Q takes a
36:27 value of T right so once the clock Edge
36:31 comes then it looks whether that deep in
36:34 sorry the what is the value of reset if
36:37 reset is equal to 0 then Q becomes 0
36:39 right so it is a kind of a synchronous
36:42 reset kind of thing right so we can all
36:46 look under look into this part and
36:49 consider it as a multiplexer right and
36:52 therefore circuits like this will can be
36:55 can be inferred by the two right so
36:58 there is a flip flop right this flip
37:00 flop and the D input that is coming to
37:03 the flip flop it is either 0 or D
37:06 because this if struct if if else
37:09 statement corresponds to a multiplexer
37:12 that we have seen earlier right so if
37:15 reset is equal to 0 reset is equal to 0
37:17 then this line will be selected on one
37:21 and in the on this line will have a
37:24 zero constant value assigned to this
37:27 multiplexer and then if the reset value
37:29 is 1
37:32 then whatever is D that appears on the
37:34 or the D Port that appears at the D pin
37:38 of the flip flop right so now this is
37:43 how this ah how this module or this RTL
37:46 construct will be synthesized right now
37:49 the tool RTL synthesis tool can further
37:52 optimize it for example instead of using
37:54 a multiplexer it can use an and gate or
37:57 so on right so whatever we are
38:01 discussing in this lecture the tool May
38:04 instantiate some other logic gates also
38:06 right so you you should note this point
38:08 that what we are showing in this Slide
38:12 the tool May instantiate some other
38:15 logic gates also but whatever the tool
38:17 will instantiate it will be functionally
38:20 equivalent to what we are discussing in
38:23 this or showing in this slide so instead
38:26 of say multiplexer the tool can always
38:29 instantiate and add an or gate and then
38:32 and so the exact implementation of the
38:35 RTL construct is dependent on the tool
38:38 right so for a given Boolean function
38:41 tool can implement it in many different
38:45 kind of ways but the uh the the meaning
38:47 of based on the meaning of the of the
38:49 verilog construct
38:52 some the tool will always generates ah
38:56 generate a circuit which is functionally
38:58 equivalent to what we are discussing in
39:06 now the always block can be synthesized
39:08 in different ways depending on whether
39:11 we are assigning a signal in a blocking
39:14 manner or non-blocking manner okay so
39:16 let us take an example and understand it
39:20 so the another important point that
39:22 should be noted is that the verilog
39:26 language as such was invented for the
39:28 primary purpose of simulation or
39:31 verification right so very log you might
39:33 remember that verification a very long
39:37 language or the word verilog was derived
39:40 from verification and logic right so the
39:42 initial purpose why verilog was invented
39:46 was for verification using simulation so
39:49 the syntax and semantics of simulation
39:53 was very well defined initially and then
39:56 later on the verilog language was used
39:58 for the synthesis for logic synthesis
40:01 RTL synthesis purpose so later on when
40:04 RTL synthesis tools were developed
40:09 they use the same sim syntax and Sim or
40:14 ah they followed the semantics of the of
40:17 the simulation that was being followed
40:21 in the synthesis also right so the
40:23 handling of blocking and non-blocking
40:25 assignment in always block is done
40:29 differently how it is done it is done in
40:32 the manner such that it is consistent
40:35 with the simulation right that is what
40:37 the what is an important point to note
40:40 so once we understand that what is the
40:43 how things will be simulated then the
40:45 synthesis tries to mimic that thing
40:48 right so let us take an example and
40:50 understand it
40:52 so suppose this there is a all there is
40:54 there is an always Block in which there
40:56 is a clock signal it is so this always
41:00 block is triggered by uh whenever pauses
41:03 appears at the clock signal so whenever
41:07 now in this always block all the all the
41:09 assignments are in a blocking manner
41:12 right so it is similar to a programming
41:13 language the first statement will be
41:17 executed then the second then third and
41:20 fourth in sequence and the all the
41:22 statements will be execute when one
41:26 statement is executed the other I others
41:30 are blocked and so on right so in this
41:32 case whenever the clock signal poses
41:37 clock appears then whatever is it at N1
41:41 that will be assigned to region and then
41:44 whatever is in at Ridge one
41:47 that assigns get assigned to rest 2 and
41:50 then whatever is at rest to that assign
41:53 2 gets assigned to rest 3 and whatever
41:56 is at rest 3 that gets assigned to out
42:00 one right so all this assignment happen
42:03 at a single clock Edge right so in
42:06 effect whenever the clock Edge poses
42:10 clock as appears whatever was at N1 that
42:14 appears at outward right so in effect
42:17 this res 1 rest 2 rest 3 these are
42:20 redundant right these are not nor so in
42:22 effect what is what this always block is
42:26 doing whatever is at N1 that is passed
42:29 to out one in whenever the clock Edge
42:32 appears right because the all these
42:34 statements are executed in sequence and
42:37 as a result finally what happens that
42:40 out one gets a value of N1 so in this
42:43 case the tool will instantiate only one
42:46 flip flop and the the D pin will be
42:50 connected to in one and the Q pin will
42:52 be connected to Output right so this is
42:55 how the tool will synthesize this always block
42:56 block
42:59 now let us take another example now in
43:01 this example the everything is same only
43:04 thing difference is that we are using
43:07 non-blocking assignment right now
43:10 remember from earlier discussion that
43:13 the non-blocking assignment is executed
43:17 in a in two steps in the first step
43:22 whatever is the a is on the rhs that is
43:25 evaluated and scheduled to be assigned
43:28 to the LHS later on at the end of the
43:31 simulation right so what happens in this
43:33 case whenever clock Edge appears
43:36 positive a clock Edge appears so
43:38 whatever was that value of current value
43:43 of N1 that is assigned to reg1 right is
43:46 sorry that means not assigned to Regis 1
43:48 but that is scheduled to be assigned to
43:50 Regional right that is an important
43:54 point the value of reg1 is still the old
43:57 value but the what the regiment value
44:00 will be assigned later on it is the
44:04 value of in one right and then in the
44:07 what happens to the rest to the current
44:10 value of Regis 1 it is not yet updated
44:12 to in one right so whatever is the
44:14 current value of Rich one that is
44:18 scheduled to be assigned to rest 2 but
44:20 rest to value is still not updated right
44:23 and in The Next Step whatever is the
44:25 current value of raised to that is
44:27 assigned to raise three and the rest 3
44:30 value is not yet updated and the in the
44:34 third case whatever is the value of of
44:36 current value of rest 3 that will be
44:40 assigned to out one but is ah but out
44:44 one is not yet updated now when at the
44:46 end of the simulation all these updates
44:49 happen so in effect what happens is that
44:52 the the the the the current value of
44:56 region so the it will the this this kind
44:58 of structure will be synthesized to us
45:01 shift register kind of thing so this
45:04 will be this register will correspond to region
45:05 region
45:09 this register will correspond to
45:13 reg 2 this one will correspond to rest 3
45:16 and this one will cause for 2 out 1
45:19 right so four registers will be ah will
45:22 be will be ah will be created in this
45:26 case and the and the whatever the value
45:30 of N1 is that will be assigned to Reg 1
45:33 right but it will be assigned when the
45:35 clock Edge comes right and what was the
45:37 current value of region that will be
45:41 assigned to raise two and so on right so
45:44 this is how it will be synthesized now
45:47 let us look at the when an always block
45:49 is level sensitive then how it is synthesized
45:51 synthesized
45:53 so when always block does not contain
45:55 edges in the sensitivity list then
45:58 either combinational circuit elements or
46:02 latches will be inferred and when the
46:05 value of the variable is updated in
46:09 every com possible paths in the
46:11 conditional branches within an always
46:13 block then combinational circuit
46:16 elements will be ah will be will be
46:20 inferred and if there is some path if
46:23 the variable is in there is some path in
46:25 the conditional branches where the
46:29 variable retains its old value then a
46:32 latch will be inverted right so let us
46:34 take an example and understand what it means
46:35 means
46:38 so let's consider this module top in
46:40 which there are two always block
46:43 in the first always block we see that
46:46 out one variable is assigned a value of
46:49 a when s takes a value 0 and assigned a
46:53 value B when s takes a value 1. so s can
46:56 take either 0 value or one value and in
47:00 both cases either 0 or 1 sorry either A
47:03 or B is being assigned to out one so out
47:06 one is assigned in all conditional
47:09 branches within the out within the
47:11 always block and therefore in this case
47:13 combinational circuit element and
47:16 specifically a multiplexer will be
47:19 inferred now let us look into the other
47:21 always block now in the other always
47:23 block if
47:26 the enable signal is taking a value of 1
47:31 then out 2 takes the value of C right
47:34 and if it is 0 then what happens
47:37 it is not specified right so in that
47:40 case if enable takes a value of 0 then
47:42 out 2 retains its old value because then
47:46 it is not not ah or the value of out 2
47:48 is not being refreshed or being written
47:50 in that case when enable is equal to
47:53 zero so it means that whenever in this
47:57 block this always block is is triggered
48:01 and the value of the enable signal is 1
48:05 then out 2 will re sorry whenever the
48:08 value of the enable signal is 1 then out
48:12 2 will get a value of C otherwise it
48:15 will retain its old value right so we
48:19 can consider this always block and the
48:22 one shown here as equivalent right so
48:24 when we write if enable is equal to one
48:28 tick B1 then out 2 takes a value of C
48:31 else out 2 is equal to out 2 it is
48:33 retaining its value right and if we
48:37 write a if we draw a circuit for this
48:39 again it is an if else kind of structure
48:41 and therefore a multiplex plexor will be
48:44 inferred it will the multiplexer will
48:46 look like something like this right so
48:48 whenever enable is 1
48:51 right whatever is at the deep end sorry
48:54 at the C line that will go to out
48:57 otherwise it will take the old value and
48:59 therefore we have made a connection of
49:02 feedback right now this lag sorry the
49:05 multiplexer with the feedback is similar
49:07 to a latch right so this structure this
49:09 complete structure is nothing but a
49:12 latch right a delatch remember that what
49:13 is a d latch
49:16 so if a deal if you a d latch just to
49:19 recap what is a d latch in D latch has a
49:24 pin as D and enable and a third penis
49:26 queue so whenever enable is high
49:30 whatever is the value at D that goes to
49:34 q and whenever the enable is zero then
49:37 it holds the previous value right so in
49:41 this and this this the description that
49:44 shows shown in this figure is the same
49:46 if enable is equal to
49:49 ah is equal to one then whatever is C
49:53 that appears at out two otherwise it
49:55 retains the old value there is a
49:58 feedback right so corresponding to this
50:02 module top the two two ah instances will
50:04 be created first for with resp for the
50:08 all always Block in which out one is
50:10 being written in all conditional
50:12 branches and therefore a multiplexer or
50:15 a or a or a combinational circuit
50:17 element will be in purely combinational
50:20 circuit element will be ah inferred and
50:23 for the second always block a d latch
50:31 so ah sometimes we actually want the
50:34 latch to be or latch to be inferred
50:36 because of the always block but many a
50:39 times at what happens is that latches
50:43 get inferred because of wrong coding RTL
50:44 code coding
50:47 what happens is that lot latches often
50:49 get inferred due to incurrent incorrect
50:52 modeling of the combinational block and
50:55 what what mistake we can make we can
50:59 inadvertently Miss updating values in
51:01 one of the branches of the case
51:04 statement suppose we are writing a code
51:07 for an FSM or a stay or or some RTL code
51:09 in which there is a complicated case
51:12 statement right so a case statement in
51:13 which the select line is say of eight
51:17 bits and based on the value of of the
51:20 select line various operations are being
51:24 done right and in we wanted this case
51:27 statement or case block to be inferred
51:28 to a purely combinational circuit
51:31 element but because we missed some of
51:34 the case statement a latch will be
51:36 inferred because whenever for the cases
51:38 where we have missed the assigning value
51:41 to the uh to a variable it implies that
51:43 it will retain the old value and
51:46 therefore a latch will be a infer right
51:48 for example consider this code in this
51:51 code we have in one is the is on the
51:53 select line for the for the case
51:56 statement now it has got two bits right
51:58 so there are four possibilities zero
52:01 zero zero one one zero and one one for
52:04 the signal in one right now for 0 0 we
52:06 are writing the value of out one for
52:09 zero one we are writing the value of out
52:11 one and for one zero we are writing a
52:15 value of out one but for the case one
52:18 one we have missed writing a value right
52:22 that may be a mistake and an inadvertent
52:25 mistake while writing the RTL code and
52:27 therefore in this case a latch will get
52:30 inverted So to avoid such problems what
52:33 we can do is that we use default
52:34 statement so whenever there are
52:38 complicated cases at the end we also a
52:40 case statement at the end of the case
52:43 statement we also write default and for
52:45 example and then we write write out 1 is
52:49 equal to say one take B zero so if we
52:53 use a default statement then
52:56 for the case nothing matches in the
52:59 earlier branches it will fall back to
53:02 default and the variable will be updated
53:04 or refreshed and therefore a
53:06 combinational circuit element will be
53:09 inferred rather than the the rather than
53:12 a latch other other thing we can do is
53:14 that at the beginning of always block we
53:18 assign the value of the signals to a
53:20 default value for example we can write
53:24 out one is equal to one tick B 0 before
53:27 the case statement so the whenever the
53:30 always block is triggered out one will
53:34 be assign one value right of course it
53:36 will be a reassigned later on down the
53:40 down the code but it will in all in the
53:42 all conditional branches if it the in
53:45 sorry in in the conditional branches we
53:48 are missing the writing value to the uh
53:52 signal out one then this out the value
53:54 of out one that we have written at the
53:57 top of the always block that will be in
54:01 will be will be coming to action and a
54:03 combinational circuit element will be
54:08 so um
54:09 um
54:12 to know more into what we have discussed
54:15 in this lecture you can refer to this
54:18 book and just to summarize what we have
54:20 done in this lecture so in this lecture
54:24 we have looked into the RTL synthesis so
54:27 we saw that RTL synthesis consists of
54:30 various tasks for example first the the
54:33 parsing of the RTL code is done then the
54:37 elaboration is done then we then we
54:40 translate the very low construct to the
54:43 corresponding logic gates and then add
54:48 some optimizations that so the in the
54:50 next lecture we will be looking at the
54:53 translation of some more verilog
54:56 constructs and we we will also look into
55:00 ah the optimizations that are RTL