Re: [sv-bc] A question about type casting

From: Paul Graham <pgraham@cadence.com>
Date: Wed Mar 17 2004 - 11:50:24 PST

Dan,

> 1. Does the term different sizes in section refer to the number of
> bits meaning the size of both src_type is 2 bits and the size of
> trg_type is 4 bits, or does the word size refer the number of unpacked
> element / words meaning the size of both src_type and trg_type is 2
> elements. (Do we need any clarification)

The intent is that unpacked arrays must have the same dimension
lengths to be assignment compatible. The element sizes don't have to
be the same. In this way, assignment of one unpacked array to another
is equivalent to the set of assignments of corresponding words in the
arrays. For instance:

    wire signed [3:0] x [7:0];
    wire [4:0] y [8:1];

    assign y = x;

has the same meaning as:

    assign y[8] = x[7]; // sign extend x[7] to five bits
    assign y[7] = x[6]; // sign extend x[6] to five bits
    ...
    assign y[1] = x[0]; // sign extend x[0] to five bits

Verilog is permissive about extending or truncating a word in an
assignment, and that permissiveness extends to assignment of array
elements. But it doesn't make sense to truncate or extend unpacked
arrays by removing or adding whole words. Hence in an assignment the
lengths of each unpacked dimension of the source and target arrays
must match.

Paul
Received on Wed Mar 17 11:50:37 2004

This archive was generated by hypermail 2.1.8 : Wed Mar 17 2004 - 11:50:48 PST