Docsity

Unit 2: SystemVerilog for Design, Slides of Computer Architecture and Organization

Partial preview of the text

Download Unit 2: SystemVerilog for Design and more Slides Computer Architecture and Organization in PDF only on Docsity!

Unit 2: SystemVerilog for Design

Adam Waksman

Simha Sethumadhavan

Hardware Description Languages (HDLs)

  • Hardware life-cycle (8 steps)
    • Specification
      • High level specification
      • Architecture
      • Microarchitecture
    • HDL Design
    • HDL Validation
    • Synthesis
    • Layout
    • Fabrication (physical process)

Flavors of SystemVerilog

• Structural SystemVerilog

• Low level, specify logic gates

  • Guaranteed to synthesize

• Behavioral SystemVerilog

• Higher level language constructs

  • Not guaranteed to synthesize

• For this class

• Use behavioral SystemVerilog

• Be careful of synthesizability

• All code should either:

  • Be synthesizable
  • Be explicitly for validation

Language Basics Outline

• Basic Types and Style

  • SystemVerilog Primitives
  • Basic Data Types
  • Assign and Always

• Building Larger Components

  • Parameters and Instantiation
  • Conditional Statements
  • Advanced Data Types
  • Advanced Example

SystemVerilog Primitives (pg. 37)

  • Each primitive represents a signal carried by a wire
    • 0: Clear digital 0
    • 1: Clear digital 1
    • X: Means either “don’t know” or “don’t care”
      • Useful for debugging
      • Also useful for ‘don’t care’ bits in logic
    • Z: High impedance, non-driven circuit
      • Value is not clearly 0 or 1
      • Useful for testing, debugging, and tri-state logic
  • Constants/Multi-bit primitives
    • All wires carrying the same value
      • ‘1, ‘0, ‘z, ‘x
    • Specific values
      • 16’b
      • 16’d
      • 16’hcafe
    • Sets – example, odd numbers
      • 16’bxxxxxxxxxxxxxxx

Basic Data Types: Wire (pg. 43)

• Wire (4-state variable)

  • Generic wire, can carry any signal (0, 1, x, z)
  • No semantic type safety between wires
    • Any wire can connect to any wire
  • Almost anything will compile
    • Including dangling wires, fused wires

• Use “assign” keyword to store a value

  • wire x;
  • assign x = ‘1;

• Can assign one wire to another

  • Wire x;
  • Assign x = y;

Basic Data Types: Wire (pg.43)

• Splitting wires, accessing subsets

  • Wires can be arbitrarily wide
  • Subsets accessed with [x:y] (0-based)

• Can access a region or a single bit

• Example: Decoder

wire [31:0] myInt; wire [63:0] myLong; assign myLong [31:0] = myInt; assign myLong [63:32] = ‘0; wire [31:0] value; wire fifthBit; // 0-based (this is the sixth bit 1-based) assign fifthBit = value[5]; wire [31:0] instruction; wire [5:0] opcode; assign opcode = instruction[31:26];

Basic Data Types: Input, Output, Module

(pg. xxv)

  • Inputs and outputs
    • Inputs are wires that come in from the “outside world”
    • Outputs are wires that go out to the “outside world”
  • Module
    • One discrete piece of hardware
    • Can be instanced multiple times Computer Architecture Lab module adder(a, b, cin, cout, s); input a, b, cin; output cout, s; assign s = a ^ b ^ cin; assign cout = (a & b) | (a & cin); | (b & cin); endmodule input wire output module

Basic Data Types: logic (pg.43)

• Logic

  • Can be assigned values with the = operator
  • Do not synthesis actual state, only logic

• Always blocks (always_comb)

  • Allow assignment to logic variables
  • Signify an action that should happen continuously Computer Architecture Lab Declare module Declare inputs Declare outputs Declare logic Declare wires always_comb begin combinatorial logic end Declare assignments endmodule

Basic Data Types: logic (pg.43)

• Logic

  • Can be assigned values with the = operator
  • Do not synthesis actual state, only logic

• Always blocks (always_comb)

  • Allow assignment to logic variables
  • Signify an action that should happen continuously Computer Architecture Lab module adder(a_i, b_i, out_o); input a_i, b_i; output out_o; logic sum; always_comb begin sum = a_i + b_i; end assign out_o = sum; endmodule Declare module Declare inputs Declare outputs Declare logic Declare wires always_comb begin combinatorial logic end Declare assignments endmodule

Combinatorial vs. Sequential (latch) (pg. xxv)

  • Combinatorial
    • Logic/arithmetic that has no notion of time
    • Use ‘logic’
  • Sequential
    • Logic that uses state to occur over multiple timesteps
    • Use ‘reg’ Computer Architecture Lab module adder(a_i, b_i, out_o); input a_i, b_i; output out_o; logic sum; always_comb begin sum = a_i + b_i; end assign out_o = sum; endmodule module latch(clk, data_i, data_o); input data_i, clk; output data_o; reg data; always_latch begin if (clk) data <= data_i; end assign data_o = data; endmodule

Style Conventions

• Logic vs. Reg

  • Use logic for combinatorial logic
  • Use reg only for memory

• Make a separate flip-flop file

  • You usually only need to declare a reg once per project
  • In other files use always_comb module uses_ff(clk, data_i, data_o); input data_i, clk; output data_o; flip_flop(clk, data_i, data_o); endmodule

Example: Simple MUX

• In structural SystemVerilog

module mux (data0_i, data1_i, select_i, data_o); input data0_i, data1_i, select_i; output data_o; assign data_o = (select_i & data1_i) | (!select_i & data0_i); endmodule

Example: Simple MUX

• In behavioral SystemVerilog (with conditionals)

module mux (data0_i, data1_i, select_i, data_o); input data0_i, data1_i, select_i; output data_o; assign data_o = select_i? data1_i : data0_i; endmodule

• If/Else statements are C-style

– Only work inside of always blocks