Subject: Re: Proposal for array types
From: Kevin Cameron x3251 (dkc@galaxy.nsc.com)
Date: Mon Apr 08 2002 - 13:47:17 PDT
> From pgraham@cadence.com Mon Apr 8 11:50:03 2002
>
> > I suggest dropping $low and $high, and adding $increment - which will return
> > -1,0 or 1 for the right -> left increment. A non-existant dimension would
> > return 0,-1,1 for $left, $right, $increment. A zero value for $increment
> > indicates a single element array or a scalar.
> > $increment would be forward compatible if we allow increments other than
> > 1 (or the array is foreign).
>
> It doesn't make sense for $increment to return 0. Otherwise a for loop
> with an incrementer like:
>
> i = i + $increment(X, 1);
>
> will loop forever.
OK, maybe skip 0 return.
> Also, it's not easy to step through an array using $left and $right only,
> because you need to know whether the stop condition is (i <= $right) or (i
> >= $right), or else you need to use MIN and MAX macros. So I think $low and
> $high are still useful.
It is useful, but in my experience the data stored for run-time is the left,
right and increment (direction), rather than left,right,high and low, because
it requires less space and high & low are easily calculated.
> Practically speaking, it's hard to imagine a case where you would query a
> non-existent dimension, except as a typo. Remember, this is not the same as
> querying a non-existing element of an array. It's easy to query a
> non-existent element by accident, because it's hard to keep track of array
> bounds and index variables. But for instance, a two-dimensional unpacked
> array has only two unpacked dimensions (and one or more packed dimensions),
> so you're only ever likely going to use the integer literals 1, 2 and maybe
> 3 or more for the unpacked dimensions. I imagine you will have code like:
>
> for (i1 = $low(A, 1); i1 <= $high(A, 1); i++)
> for (i2 = $low(A, 2); i2 <= $high(A, 2); i2++)
> A[i1][i2] = ...
>
> If I accidentally type:
>
> for (i = $low(A, 11); ...
>
> then I would like the compiler to tell me as soon as possible. If $low and
> $high just return 1'bx, then my array will remain mysteriously uninitialized
> and it will take a long time to figure out why.
>
> Paul
Seems reasonable, it just doesn't quite fit with the way that syntax usually
works. We really want somothing like the VHDL '<implicit...> syntax.
Kev.
This archive was generated by hypermail 2b28 : Mon Apr 08 2002 - 13:49:57 PDT