DOC PREVIEW
MIT 6 375 - Lecture Notes

This preview shows page 1-2-16-17-18-34-35 out of 35 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 35 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

February 27, 2006 http://csg.csail.mit.edu/6.375/ L08-1Bluespec-2: TypesArvind Computer Science & Artificial Intelligence LabMassachusetts Institute of TechnologyFebruary 27, 2006 L08-2http://csg.csail.mit.edu/6.375/Example: ShifterGoal: implement: y = shift (x,s)where y is x shifted by s positions.Suppose s is a 3-bit value.Strategy: Shift by s =shift by 4 (=22) if s[2] is set,and by 2 (=21 ) if s[1] is set,and by 1 (=20 ) if s[0] is set A shift by 2jis trivial: it’s just a “lane change” made purely with wires00sh2February 27, 2006 L08-3http://csg.csail.mit.edu/6.375/Cascaded Combinational Shiftersh2sxmuxmuxmuxsh1sh4s0s1s2nnx0x1x23ffunction int shifter (int s,int x);Pair sx0, sx1, sx2;sx0 = step_0(Pair{s:s, x:x});sx1 = step_1(sx0);sx2 = step_2(sx1);return (sx2.x);endfunctionfunction Pair step_j (Pair sx);return ((sx.s[j]==0) ? sx : Pair{s: sx.s,x:sh_k(sx.x)});endfunctionwhere k=2jA family of functionstypedef struct{int x; int s;} Pair;February 27, 2006 L08-4http://csg.csail.mit.edu/6.375/Asynchronous pipelinewith FIFOs (regs with interlocks)sh2sxmuxmuxmuxsh1sh4s0s1s2nn3rule stage_0 (True);Pair sx0 = fifo0.first(); fifo0.deq(); fifo1.enq(step_0(sx0));endrulefifo0fifo1fifo2fifo3rule stage_1 (True);Pair sx1 = fifo1.first(); fifo1.deq(); fifo2.enq(step_1(sx1));endrulerule stage_2 (True);Pair sx2 = fifo2.first(); fifo2.deq(); fifo3.enq(step_2(sx2));endruleFebruary 27, 2006 L08-5http://csg.csail.mit.edu/6.375/Required simultaneityIf it is necessary for several actions to happen together,(i.e., indivisibly, atomically)Put them in the same rule!February 27, 2006 L08-6http://csg.csail.mit.edu/6.375/Synchronous pipeline(with registers)sh2sxmuxmuxmuxsh1sh4[0] [1] [2]nn3sx1 sx2 sx3sx0rule sync-shifter (True);sx1 <= step_0(sx0);sx2 <= step_1(sx1);sx3 <= step_2(sx2);endrulestep_0step_1step_2sx1, sx2 and sx3 are registers defined outside of the rulesReg#(Pair) sxi <- mkRegU();Will it start properly?Will it leave some values in the pipe?February 27, 2006 L08-7http://csg.csail.mit.edu/6.375/DiscussionIn the synchronous pipeline, we compose actions in parallel All stages move data simultaneously, in lockstep (atomic!)In the asynchronous pipeline, we compose rules in parallel Stages can move independently (each stage can move when its input fifo has data and its output fifohas room) If we had used parallel action composition instead, all stages would have to move in lockstep, and could only move when all stages were able to moveYour design goals will suggest which kind of composition is appropriate in each situationFebruary 27, 2006 L08-8http://csg.csail.mit.edu/6.375/Expressions vs. FunctionsA function is just an abstraction of a combinational expressionArguments are inputs to the circuitThe result is the output of the circuitxx-const 4xbacdiscrfunction int discr (int a, int b, int c);w return b*b – 4*a*c;endfunctionexpressionFebruary 27, 2006 L08-9http://csg.csail.mit.edu/6.375/Function ApplicationInstantiates combinational hardware of the function bodyConnects the body to argument expressionsxx-const 4xbacdiscrfunction intdiscr (int a, int b, int c);return b*b – 4*a*c;endfunctiond = discr (10, p, q);const 10pqNo runtime allocation of stack frames or passing of arguments; only meaningful for static elaborationFebruary 27, 2006 L08-10http://csg.csail.mit.edu/6.375/Types and type-checkingBSV is strongly-typed Every variable and expression has a type The Bluespec compiler performs strong type checking to guarantee that values are used only in places that make sense, according to their typeThis catches a huge class of design errors and typos at compile time, i.e., before simulationFebruary 27, 2006 L08-11http://csg.csail.mit.edu/6.375/What is a Type?A type describes a set of valuesTypes are orthogonal (independent) of entities that may carry values (such as wires, registers, …) No inherent connection with storage, or updatingThis is true even of complex types  E.g., struct { int …, Bool …} This just represents a set of pairs of values, where the first member of each pair is an int value, and the second member of each pair is a Bool valueFebruary 27, 2006 L08-12http://csg.csail.mit.edu/6.375/SV notation for typesSome types just have a nameMore complex types can have parameters which are themselves typesType names begin with uppercase letter Exceptions: ‘int’ and ‘bit’, for compatibility with Verilogint, Bool, Action, …FIFO#(Bool) // fifo containing BooleansTuple2#(int,Bool) // pair of int and BooleanFIFO#(Tuple2#(int,Bool)) // fifo of pairs of int// and Booleanbit[15:0] is the same as Bit#(16)February 27, 2006 L08-13http://csg.csail.mit.edu/6.375/Numeric type parametersBSV types also allows numericparametersThese numeric types should not be confused with numeric values, even though they use the same number syntax The distinction is always clear from context, i.e., type expressions and ordinary expressions are always distinct parts of the program textBit#(16) // 16-bit wide bit-vectorInt#(29) // 29-bit wide signed integersVector#(16,Int#(29)) // vector of 16 whose elements // are of type Int#(29)February 27, 2006 L08-14http://csg.csail.mit.edu/6.375/Common scalar typesBool BooleansBit#(n) Bit vectors, with a width n bitsInt#(n) Signed integers of n bitsUInt#(n) Unsigned integers of n bitsInteger Unbound integers; has meaning only during static elaborationFebruary 27, 2006 L08-15http://csg.csail.mit.edu/6.375/Some Composite TypesEnumerations Sets of symbolic namesStructs Records with fieldsTagged Unions unions, made “type-safe” with tagsFebruary 27, 2006 L08-16http://csg.csail.mit.edu/6.375/Types of variablesEvery variable has a data type:BSV will enforce proper usage of values according to their types You can't apply “+” to a struct You can’t assign a boolean value to a variable declared as a struct typebit[3:0] vec; // or Bit#(4) vec;vec = 4’b1010;Bool cond = True;typedef struct {Bool b; bit[31:0] v;} Val;Val x = Val {b: True, v: 17};February 27, 2006 L08-17http://csg.csail.mit.edu/6.375/“let” and type-inferenceNormally, every variable is introduced in a declaration (with its type)The “let” notation introduces a variable with an assignment, with the compiler inferring its correct typeThis is typically used only for very “local” temporary values, where the type is obvious from contextlet vec = 4’b1010; // bit[3:0] vec = …let cond


View Full Document

MIT 6 375 - Lecture Notes

Documents in this Course
IP Lookup

IP Lookup

15 pages

Verilog 1

Verilog 1

19 pages

Verilog 2

Verilog 2

23 pages

Encoding

Encoding

21 pages

Quiz

Quiz

10 pages

IP Lookup

IP Lookup

30 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?