RE: [sv-bc] 5.15.3 Array reduction methods - result type

From: Steven Sharp <sharp_at_.....>
Date: Thu Jun 29 2006 - 08:43:10 PDT
>From: "Bresticker, Shalom" <shalom.bresticker@intel.com>

>A question about the current definition is whether the return type is
>self-determined or context-determined. If I write (array.sum() + 0),
>does that turn sum() into 32 bits before its calculation and prevent the
>loss of bits, or is sum() first calculated according to the element type
>and only afterwards bit-extended?

Since sum() is a method call, and therefore a function call, its return
type should not be affected by the context in which it appears.  For
an explicitly declared function, the return type is specified explicitly
in the function declaration, and is not affected by the calling context.
For these method calls, the return type is implicitly declared by the
type of the array from which it is invoked.  I would still expect that
the return type is not affected by the context where the result is used.

>My intuition expected the 2nd case, meaning that I don't even have a way
>to prevent or workaround the overflow.

I would agree.

Note that you do have a way to work around the problem in many situations:
stop using these methods and write a foreach loop to perform the sum
yourself, using an accumulator of whatever size you want.  I am not fond
of the idea of having built-in methods for things that are trivial to write
for yourself.  Apparently these methods were added primarily for use in
constraints, where that is not an option.



Steven Sharp
sharp@cadence.com
Received on Thu Jun 29 08:43:18 2006

This archive was generated by hypermail 2.1.8 : Thu Jun 29 2006 - 08:43:23 PDT