流连接

Streaming concatenation

在 SystemVerilog IEEE Std 1800-2017 第 277 页中,显示了以下示例:

int a, b, c;
logic [10:0] up [3:0];
logic [11:1] p1, p2, p3, p4;
bit [96:1] y = {>>{ a, b, c }}; // OK: pack a, b, c
int j = {>>{ a, b, c }}; // error: j is 32 bits < 96 bits
bit [99:0] d = {>>{ a, b, c }}; // OK: d is padded with 4 bits
{>>{ a, b, c }} = 23'b1; // error: too few bits in stream
{>>{ a, b, c }} = 96'b1; // OK: unpack a = 0, b = 0, c = 1
{>>{ a, b, c }} = 100'b11111; // OK: unpack a = 0, b = 0, c = 1 // 96 MSBs unpacked, 4 LSBs truncated
{ >> {p1, p2, p3, p4}} = up; // OK: unpack p1 = up[3], p2 = up[2],
                             // p3 = up[1], p4 = up[0]

关于这一行:

{>>{ a, b, c }} = 96'b1; // OK: unpack a = 0, b = 0, c = 1

为什么ab得到的值为0?

来自 IEEE Std 180-2017,第 11.4.14.3 节流式连接作为分配目标(解包)

When a streaming_concatenation appears as the target of an assignment, the streaming operators perform the reverse operation; i.e., to unpack a stream of bits into one or more variables.

a、b 和 c 被声明为 int,这意味着它们每个都是 32 位宽。常量 96'b1 是 96 位宽(95 个 MSB 为 0,LSB 为 1)。由于 96 = 3 x 32,a 将分配给最高有效的 32 位(32 个 0),b 将分配中间的 32 位(32 个 0),而 c 将是分配了最低有效的 32 位(31 个 0 和一个 1)。

00000000000000000000000000000000_00000000000000000000000000000000_00000000000000000000000000000001

|<-----------  a  ------------>| |<-----------  b  ------------>| |<-----------  c  ------------>|