Beruflich Dokumente
Kultur Dokumente
1 2
3 4
Unsigned and Signed Data Types Assigning the Same Value to all Bits
• Keywords signed and unsigned can be • The common value 0, 1, x or z can be
used to override the default numeric assigned to all bit positions of a vector with
properties: a new and simple syntax:
• logic is unsigned by default:
logic [7:0] a; // a is unsigned my_bus = '0; // fills with all 0
logic signed [7:0] b; // b is signed my_bus = '1; // fills with all 1
• int is 32-bit signed by default: my_bus = 'x; // fills with all x
int c; // c is 32-bit signed my_bus = 'z; // fills with all z
int unsigned d; // 32-bit unsigned
5 6
r[10:1]
7 8
SystemVerilog Code– Part 1 of 1 SystemVerilog Code – cont.
// half adder // 10-bit truncated ripple-carry adder
module half_adder(input logic a, b, module RCA10(input logic [9:0] p, q,
output logic s, cout); output logic [10:1] r);
endmodule
9 10
endmodule
11 12
Carry Look-Ahead (CLA) Adders – Cont. Carry Look-Ahead (CLA) Adders – Cont.
• The previous equations determine the first four carries in parallel. While the previous • Given the definitions of these group generate and propagate functions, we can create
set of substitutions could be continued to higher-order carries, they become impractical the following group carries:
due to the the large number of terms involved and large fan-in gates that would be C 8 = G 7:4 + P7:4 C 4 = G 7:4 + P7:4 (G 3:0 + P3:0 C 0 )
required.
• One alternative is to construct a hierarchical structure consisting of groups, blocks and = G 7:4 + P7:4 G 3:0 + P7:4 P3:0 C 0
sections. For example, we can define the group generate and propagate functions as: C12 = G 11:8 + P11:8 C 8 = G 11:8 + P11:8 (G 7:4 + P7:4 G 3:0 + P7:4 P3:0 C 0 )
G 3:0 = G 3 + P3 G 2 + P3 P2 G 1 + P3 P2 P1G 0 , P3:0 = P3 P2 P1 P0
= G 11:8 + P11:8 G 7:4 + P11:8 P7:4 G 3:0 + P11:8 P7:4 P3:0 C 0
• Using these functions, the equation for C4 can be written as follows: C16 = G 15:12 + P15:12 C 12
C 4 = G 3:0 + P3:0 C 0 = G 15:12 + P15:12 ( G 11:8 + P11:8 G 7:4 + P11:8 P7:4 G 3:0 + P11:8 P7:4 P3:0 C 0 )
= G 15:12 + P15:12 G 11:8 + P15:12 P11:8 G 7:4
• Similarly, we can define group generate and propagate functions for other, non-
overlapping 4-bit groups: + P15:12 P11:8 P7:4 G 3:0 + P15:12 P11:8 P7:4 P3:0 C 0
G i + 3:i = G i + 3 + Pi + 3 G i + 2 + Pi + 3 Pi + 2 G i +1 + Pi + 3 Pi + 2 Pi +1G i
• This can be extended to another level of hierarchy (i.e., blocks) by forming block
Pi + 3:i = Pi + 3 Pi + 2 Pi +1 Pi generate and propagate functions, which allows us to get block carries. For example:
G 15:0 = G 15:12 + P15:12 G 11:8 + P15:12 P11:8 G 7:4 + P15:12 P11:8 P7:4 G 3:0
P15:0 = P15:12 P11:8 P7:4 P3:0 ⇒ C 16 = G 15:0 + P15:0 C 0
15 16
Parallel Prefix Adders Kogge-Stone (KS) Architecture
• Parallel prefix adders make use of recursive relations between group propagate and • The n-bit KS design achieves the minimum logical depth of log2n levels. It combines
generate functions. Consider 3 bit positions i, m and j, where i > m > j: values at spans of distance 20, 21, 22, … , 2n-1. The 8-bit KS design is:
Pi: j = (Pi Pi −1 L Pm )(Pm−1Pm− 2 L Pj ) = Pi:m Pm−1: j
• This operator is associative (i.e., a series of o operators can be evaluated in any order).
This provides a great deal of flexibility in devising various parallel prefix adder
architectures, as illustrated on the following pages.
• Also, by definition, note that: Pi:i = Pi and Gi:i = Gi
Simon Knowles, “A Family of Adders,” 15th IEEE Symposium on Computer Arithmetic, pp. 277-284, 2001.
17 18
19 20
21 22
25 26
Structures Passed Through Module Ports Example: A struct through a Module Port
• In order to be able to pass structures • First, use a typedef struct statement outside
through the ports of a module, do the of the module. Then, the module can declare one
or more of its ports to be of that type.
following:
Place the typedef struct statement
typedef struct {
outside of the module. logic [15:0] a, b;
Then, you can pass variables of that type int c;
into and out of the module. } simple;
module example (input simple r, s);
• Similarly, you can pass arguments to
...
functions and tasks which are structures. endmodule
35 36
39 40
Example of a Union – Continued Arrays
• The output from executing the previous code: • Multi-dimensional arrays are allowed.
• For example, a 3-dimensional array of integers of
signed info: -3 size 16x8x4 can be declared as:
unsigned info: 13 int my_array[0:15][0:7][0:3];
• The same array can also be declared as follows:
• Note that the value -3 is represented as a 4-bit int my_array[16][8][4];
signed binary number by: 1101 • To assign a value to a specific array element, just
specify each of its index values. For example:
• When this 4-bit pattern is interpreted as an my_array[4][3][2] = 55;
unsigned number, its value is 8+4+1=13.
41 42
Using for Loops with Arrays Using foreach Loops with Arrays
• Some features of SystemVerilog make using for • A foreach loop automatically goes through each
loops with arrays easier than in Verilog: possible index value in an array.
Declare the loop index directly in the loop. • The previous example can be coded as:
Use the ++ increment operator
Use the $size function (returns the number of array
int arr[10];
elements)
int arr[10]; initial begin
initial begin foreach (arr[i])
for (int i = 0; i < $size(arr); i++) arr[i] = 3*i;
arr[i] = 3*i; end
end
45 46
49 50
always_latch sequentially.
if (clock) Q <= D; The blocking assignment = must be used in
References
• IEEE Standard for SystemVerilog— Unified Hardware
Design, Specification, and Verification Language, IEEE,
IEEE Std 1800TM -2005, 22 November 2005.
• S. Sutherland, S. Davidmann and P. Flake, SystemVerilog
for Design, Kluwer Academic Publishers, 2004.
• C. Spear, SystemVerilog for Verification, Springer, 2006.
• SystemVerilog Tutorials, Doulos Ltd.,
http://www.doulos.com/knowhow/sysverilog/tutorial/
• SystemVerilog Tutorial, electroSofts.com,
http://electrosofts.com/systemverilog/
61