Re: [sv-bc] Question about replication in array literal


Subject: Re: [sv-bc] Question about replication in array literal
From: Paul Graham (pgraham@cadence.com)
Date: Mon Jan 12 2004 - 11:07:17 PST


> I'm not sure how this construct should be interpreted:
>
> int x[2:0][1:0] = { 3{1, 0} };

This reminds me of the situation with VHDL array aggregates where you don't
know if (x) is a one-element aggregate or just a parenthesized expression.
VHDL resolves this problem by saying that (x) is a parenthesized expression,
and that if you want an aggregate you have to use some syntactic indicator,
like (others=>x).

At issue is whether the inner {} in an array multi-concat is an expression
enclosed in {} or or an array literal itself. For this test case:

1) int x[2:0][1:0] = { 3{1, 0} };

the 1, 0 is not an expression (if it were, it would be the C comma operator,
which is probably not the intention). But if we treat {1, 0} as an array
literal in its own right, then this example is equivalent to:

2) int x[2:0][1:0] = { {1, 0}, {1, 0}, {1, 0} };

On the other hand, you might also want to write:

3) int x[2:0] = { 3{1} }; // == { 1, 1, 1 }

Here, the {1} is not meant as an array literal, but as a placeholder for the
expression 1.

As examples of a one-element array literal:

4a) int x[2:0][0:0] = { 3{default:1} };

or

4b) int x[2:0][0:0] = { 3{0:1} };

or

4c) int x[2:0][0:0] = { 3{ 1{1} } }

I'm not sure I'm happy about having to distinguish between an array literal
and an expression surrounded by curly braces. Maybe the best thing is to
say that a multi-concat in an array literal context consists of a repeat
count expression followed by an expression enclosed in braces. In that
case, the above examples would be written as:

1) int x[2:0][1:0] = { 3{{1, 0}} }; // extra level of braces needed
3) int x[2:0] = { 3{1} }; // no change
4a) int x[2:0][0:0] = { 3{{default:1}} }; // extra level of braces needed
4b) int x[2:0][0:0] = { 3{{0:1}} }; // extra level of braces needed
4c) int x[2:0][0:0] = { 3{{ 1{1} }} } // extra level of braces needed

Was the array literal multi-concat syntax in the original SuperLog language?
If so, could a CoDesign veteran comment on how they were defined?

Paul



This archive was generated by hypermail 2b28 : Mon Jan 12 2004 - 11:08:08 PST