Arithmetic Operators There are two types of operators: binary and unary Binary operators:

Similar documents
ECEN 468 Advanced Logic Design

Introduction to Digital VLSI Design מבוא לתכנון VLSI ספרתי

Chap 6 - Introduction to HDL (b)

Verilog Dataflow Modeling

ECE Digital System Design & Synthesis Exercise 1 - Logic Values, Data Types & Operators - With Answers

Course Topics - Outline

Chapter 3: Dataflow Modeling

14:332:231 DIGITAL LOGIC DESIGN. Hardware Description Languages

Lecture #2: Verilog HDL

ECE 4514 Digital Design II. Spring Lecture 7: Dataflow Modeling

Verilog introduction. Embedded and Ambient Systems Lab

Design Using Verilog

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Lab 5: Arithmetic Logic Unit (ALU)

Lab 4: Arithmetic Logic Unit (ALU)

Introduction To Verilog Design. Chun-Hung Chou

Digital Design with FPGAs. By Neeraj Kulkarni

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

In this lecture, we will go beyond the basic Verilog syntax and examine how flipflops and other clocked circuits are specified.

Verilog HDL:Digital Design and Modeling. Chapter 4. Expressions

Combinational Logic II

Schematic design. Gate level design. 0 EDA (Electronic Design Assistance) 0 Classical design. 0 Computer based language

Introduction to Verilog/System Verilog

Introduction to Verilog. Garrison W. Greenwood, Ph.D, P.E.

Chapter 2 Basic Logic Circuits and VHDL Description

Lecture 3: Modeling in VHDL. EE 3610 Digital Systems

1. Prove that if you have tri-state buffers and inverters, you can build any combinational logic circuit. [4]

Course Topics - Outline

Verilog Module 1 Introduction and Combinational Logic

CSE140L: Components and Design Techniques for Digital Systems Lab. Verilog HDL. Instructor: Mohsen Imani UC San Diego. Source: Eric Crabill, Xilinx

Lecture 12 VHDL Synthesis

Introduction to synthesis. Logic Synthesis

Number Systems and Computer Arithmetic

Lecture 1: VHDL Quick Start. Digital Systems Design. Fall 10, Dec 17 Lecture 1 1

Arithmetic and Logic Blocks

A Verilog Primer. An Overview of Verilog for Digital Design and Simulation

a, b sum module add32 sum vector bus sum[31:0] sum[0] sum[31]. sum[7:0] sum sum overflow module add32_carry assign

VERILOG 2: LANGUAGE BASICS

Contents. Appendix D Verilog Summary Page 1 of 16

Digital Design (VIMIAA01) Introduction to the Verilog HDL

Informatics Ingeniería en Electrónica y Automática Industrial

Verilog Design Principles

Verilog HDL Introduction

Week 7: Assignment Solutions

Department of Computer Science and Electrical Engineering. Intro to Verilog II

Computer Aided Design Basic Syntax Gate Level Modeling Behavioral Modeling. Verilog

Lecture 2: Data Types, Modeling Combinational Logic in Verilog HDL. Variables and Logic Value Set. Data Types. Why use an HDL?

Verilog. Reminder: Lab #1 due tonight! Fall 2008 Lecture 3

EN2911X: Reconfigurable Computing Lecture 05: Verilog (2)

Synthesis of Language Constructs. 5/10/04 & 5/13/04 Hardware Description Languages and Synthesis

Chapter 3 Arithmetic for Computers

ECE 353 Lab 3 (Verilog Design Approach)

EN164: Design of Computing Systems Lecture 06: Lab Foundations / Verilog 2

Introduction to Verilog HDL

Tailoring the 32-Bit ALU to MIPS

Chapter 3: part 3 Binary Subtraction

Parallel logic circuits

Verilog Design Principles

Chapter 4 Arithmetic Functions

Digital Design with SystemVerilog

This Lecture. Some components (useful for the homework) Verilog HDL (will continue next lecture)

Combinational Circuit Design

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Hardware Description Language VHDL (1) Introduction

FPGA Design Challenge :Techkriti 14 Digital Design using Verilog Part 1

Computer Architecture and Organization

ECE468 Computer Organization & Architecture. The Design Process & ALU Design

Chapter 3 Part 2 Combinational Logic Design

Speaker: Kayting Adviser: Prof. An-Yeu Wu Date: 2009/11/23

Verilog. Verilog for Synthesis

Advanced Digital Design Using FPGA. Dr. Shahrokh Abadi

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

Lec-6-HW-3-ALUarithmetic-SOLN

yamin/

ECOM4311 Digital Systems Design

Expression and Operator

Verilog Tutorial. Introduction. T. A.: Hsueh-Yi Lin. 2008/3/12 VLSI Digital Signal Processing 2

Verilog Coding Guideline

Chapter 2 Using Hardware Description Language Verilog. Overview

Timing for Ripple Carry Adder

UNIT V: SPECIFICATION USING VERILOG HDL

Computer Architecture Set Four. Arithmetic

Why Should I Learn This Language? VLSI HDL. Verilog-2

Chap 6 Introduction to HDL (d)

LAB K Basic Verilog Programming

JAVA OPERATORS GENERAL

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers Implementation

Brief Introduction to Verilog HDL (Part 1)

Programmable Logic Devices Verilog VII CMPE 415

Under-Graduate Project Logic Design with Behavioral Models

271/469 Verilog Tutorial

Abi Farsoni, Department of Nuclear Engineering and Radiation Health Physics, Oregon State University

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

ECE 448 Lecture 3. Combinational-Circuit Building Blocks. Data Flow Modeling of Combinational Logic

EE 8351 Digital Logic Circuits Ms.J.Jayaudhaya, ASP/EEE

Verilog Tutorial - Edited for CS141

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Unit 3. Operators. School of Science and Technology INTRODUCTION

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Design units can NOT be split across different files

Transcription:

Verilog operators operate on several data types to produce an output Not all Verilog operators are synthesible (can produce gates) Some operators are similar to those in the C language Remember, you are making gates, not an algorithm (in most cases)

Arithmetic Operators There are two types of operators: binary and unary Binary operators: add(+), subtract(-), multiply(*), divide(/), power(**), modulus(%) //suppose that: a = 4 b0011; // b = 4 b0100; // d = 6; e = 4; f = 2; //then, a + b //add a and b; evaluates to 4 b0111 b - a //subtract a from b; evaluates to 4 b0001 a * b //multiply a and b; evaluates to 4 b1100 d / e //divide d by e, evaluates to 4 b0001. Truncates fractional part e ** f //raises e to the power f, evaluates to 4 b1111 //power operator is most likely not synthesible If any operand bit has a value x, the result of the expression is all x. If an operand is not fully known the result cannot be either.

Arithmetic Operators (cont.) Modulus operator yields the remainder from division of two numbers It works like the modulus operator in C Modulus is synthesible 3 % 2; //evaluates to 1 16 % 4; //evaluates to 0-7 % 2; //evaluates to -1, takes sign of first operand 7 % -2; //evaluates to 1, takes sign of first operand

Arithmetic Operators (cont.) Unary operators Operators + and - can act as unary operators They indicate the sign of an operand i.e., -4 // negative four +5 // positive five!!! Negative numbers are represented as 2 s compliment numbers!!!!!! Use negative numbers only as type integer or real!!!!!! Avoid the use of <sss> <base><number >in expressions!!!!!! These are converted to unsigned 2 s compliment numbers!!!!!! This yields unexpected results in simulation and synthesis!!!

Arithmetic Operators (cont.) The logic gate realization depends on several variables coding style synthesis tool used synthesis constraints (more later on this) So, when we say +, is it a... ripple-carry adder look-ahead-carry adder (how many bits of lookahead to be used?) carry-save adder When writing RTL code, keep in mind what will eventually be needed Continually thinking about structure, timing, size, power

Arithmetic Operators (cont.) 16-bit adder with loose constraints: set_max_delay 2 [get_ports sum*] max delay = 0.8ns, area = 472 = 85 gates

Arithmetic Operators (cont.) 16-bit adder with tighter constraints: set_max_delay 0.5 [get_ports sum*] max delay = 0.5ns, area = 2038 = 368gates

Logical Operators Verilog Logical Operators logical-and(&&) //binary operator logical-or( ) //binary operator logical-not(!) //unary operator //suppose that: a = 3 and b = 0, then... (a && b) //evaluates to zero (b a) //evaluates to one (!a) //evaluates to 0 (!b) //evaluates to 1 //with unknowns: a = 2 b0x; b = 2 b10; (a && b) // evaluates to x //with expressions... (a == 2) && (b == 3) //evaluates to 1 only if both comparisons are true

Logical Operators (.cont) Logical operators evaluate to a 1 bit value 0 (false), 1 (true), or x (ambiguous) Operands not equal to zero are equivalent to one Logical operators take variables or expressions as operators

Relational Operators (.cont) greater-than (>) less-than (<) greater-than-or-equal-to (>=) less-than-or-equal-to (<=) Relational operators return logical 1 if expression is true, 0 if false //let a = 4, b = 3, and... //x = 4 b1010, y = 4 b1101, z = 4 b1xxx a <= b //evaluates to logical zero a > b //evaluates to logical one y >= x //evaluates to logical 1 y < z //evaluates to x!!! Note: These are expensive and slow operators at gate level!!!

Equality Operators - LT is big and slow //8-bit less than detector //if a is less than b, output is logic one module less8( input [7:0] a,b, output z ); assign z = (a < b)? 1 b1 : 1 b0; endmodule Results from synthesis:... U14 U13... U12 U10...... U9... U8... U7 U20 U6 U5 U4 U3

Equality Operators logical equality (== ) logical inequality (!= ) logical case equality (===) logical case inequality (!==) Equality operators return logical 1 if expression is true, else 0 Operands are compared bit by bit Zero filling is done if operands are of unequal length (Warning!) Logical case inequality allows for checking of x and z values Checking for X and Z is most definitely non-synthesible!

Equality Operators (cont.) //let a = 4, b = 3, and... //x = 4 b1010, y = 4 b1101, //z = 4 b1xxz, m = 4 b1xxz, n = 4 b1xxx a == b //evaluates to logical 0 x!= y //evaluates to logical 1 x == z //evaluates to x z === m //evaluates to logical 1 z === n //evaluates to logical 0 m!== n //evaluates to logical 1

Bitwise Operators negation ( ), and(&), or( ), xor(^), xnor(^-, -^) Perform bit-by-bit operation on two operands (except ) Mismatched length operands are zero extended x and z treated the same bitwise AND bitwise OR bitwise XOR bitwise XNOR 0 1 x 0 1 x 0 1 x 0 1 x 0 0 0 0 0 0 1 x 0 0 1 x 0 1 0 x 1 0 1 x 1 1 1 1 1 1 0 x 1 0 1 x x 0 x x x x 1 x x x x x x x x x bitwise negation result 0 1 1 0 x x

Bitwise Operators (cont.) Logical operators result in logical 1, 0 or x Bitwise operators results in a bit-by-bit value //let x = 4 b1010, y = 4 b0000 x y //bitwise OR, result is 4 b1010 x y //logical OR, result is 1

Bitwise operators give bit-by-bit results b[7:0] b[6] a[6] U10 z[6] z[7:0] b[5] a[5] U11 z[5] b[4] a[4] U12 z[4] //8-bit wide AND module and8( input [7:0] a,b, output [7:0] z ); assign z = a & b; endmodule b[3] a[3] b[2] a[2] b[1] a[1] U13 U14 U15 z[3] z[2] z[1] b[0] a[0] U16 z[0] b[7] b[7:0] a[7:0] a[7] U9 z[7] z[7:0] a[7:0]

Reduction Operators and(&), nand( &), or( ), nor( ) xor(^), xnor(^, ^) Operates on only one operand Performs a bitwise operation on all bits of the operand Returns a 1-bit result Works from right to left, bit by bit //let x = 4 b1010 &x //equivalent to 1 & 0 & 1 & 0. Results in 1 b0 x //equivalent to 1 0 1 0. Results in 1 b1 ^x //equivalent to 1 ^ 0 ^ 1 ^ 0. Results in 1 b0 A good example of the XOR operator is generation of parity

Reduction Operators d_in[3] U10 d_in[2] //8-bit parity generator //output is one if odd # of ones module parity8( input [7:0] d_in, d_in[7:0] output parity_out ); assign parity_out = ^d_in; endmodule d_in[7:0] d_in[7] d_in[6] U9 d_in[5] d_in[4] d_in[1] d_in[0] n8 U8 U7 n5 n6 n7 U6 parity_out parity_out

Shift Operators right shift (>>) left shift (<<) arithmetic right shift (>>>) arithmetic left shift (<<<) Shift operator shifts a vector operand left or right by a specified number of bits, filling vacant bit positions with zeros. Shifts do not wrap around. Arithmetic shift uses context to determine the fill bits. // let x = 4 b1100 y = x >> 1; // y is 4 b0110 y = x << 1; // y is 4 b1000 y = x << 2; // y is 4 b0000

Arithmetic Shift Operators arithmetic right shift (>>>) Shift right specified number of bits, fill with value of sign bit if expression is signed, othewise fill with zero. arithmetic left shift (<<<) Shift left specified number of bits, filling with zero.

Concatenation Operator {,} Provides a way to append busses or wires to make busses The operands must be sized Expressed as operands in braces separated by commas //let a = 1 b1, b = 2 b00, c = 2 b10, d = 3 b110 y = {b, c} // y is then 4 b0010 y = {a, b, c, d, 3 b001} // y is then 11 b10010110001 y = {a, b[0], c[1]} // y is then 3 b101

Replication Operator { { } } Repetitive concatenation of the same number Operands are number of repetitions, and the bus or wire //let a = 1 b1, b = 2 b00, c = 2 b10, d = 3 b110 y = { 4{a} } // y = 4 b1111 y = { 4{a}, 2{b} } // y = 8 b11110000 y = { 4{a}, 2{b}, c } // y = 8 b1111000010

Conditional Operator?: Operates like the C statement conditional expression? true expression : false expression ; The conditional expression is first evaluated If the result is true, true expression is evaluated If the result is false, false expression is evaluated If the result is x: both true and false expressions are evaluated,... their results compared bit by bit,... returns a value of x if bits differ, OR... the value of the bits if they are the same. This is an ideal way to model a multiplexer or tri-state buffer.

Conditional Operator (cont.) d_in0[6] d_in1[6] U11 d_out[6] d_in0[7:0] d_in0[5] d_in1[5] U12 d_in1[7:0] d_in0[4] U13 d_out[4] //8-bit wide, 2:1 mux module mux2_1_8wide( input sel, input [7:0] d_in1, d_in0, output [7:0] d_out ); assign d_out = sel? d_in1 : d_in0; endmodule d_in1[4] d_in0[3] d_in1[3] d_in0[2] d_in1[2] d_in0[1] d_in1[1] d_in0[0] d_in1[0] U14 U15 U16 U17 d_out[2] d_out[0] d_out[7:0] d_in0[7:0] d_in0[7] d_in1[7] U10 d_out[7] d_out[7:0] d_in1[7:0] sel sel

Conditional Operator (cont.) n16 d_in[6] d_out_tri[6] d_out[6] d_in[5] d_out_tri[5] d_out[5] d_in[4] d_out_tri[4] d_out[4] //8-bit wide, //active-low enabled tri-state buffer module ts_buff8( input [7:0] d_in, input en_n, output [7:0] d_out ); assign d_out = ~en_n? d_in : 8 bz; endmodule d_in[3] d_in[2] d_in[1] d_out_tri[3] d_out_tri[2] d_out_tri[1] d_out[3] d_out[2] d_out[1] d_in[0] d_out_tri[0] d_out[0] en_n d_in[7:0] en_n U2 d_out[7:0] d_out_tri[7] d_out[7] d_out[7:0] d_in[7] d_in[7:0]

More Lexical Conventions The assign statement places a value (a binding) on a wire Also known as a continuous assign A simple way to build combinatorial logic Confusing for complex functions Must be used outside a procedural statement (always) //two input mux, output is z, inputs in1, in2, sel assign z = (a b); assign a = in1 & sel; assign b = in2 & ~sel;

Some More Lexical Conventions The order of execution of the assign statements is unknown We must fake parallel execution... gates operate in parallel The assign statements fire when the RHS variables change RHS = a, b, in1, in2, sel The values of a, b, and z are updated at the end of the timestep In the next time step if variables changed the next result is posted This repeats until no further changes occur Then... time advances //two input mux, output is z, inputs in1, in2, sel assign z = (a b); assign a = in1 & sel; assign b = in2 & ~sel;