This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Valarrays and [altivec] vectors (was Re: [PATCH]: Handle vector modes in genopinit.c, c-typeck.c)
- From: Gabriel Dos Reis <gdr at codesourcery dot com>
- To: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- Cc: Gabriel Dos Reis <gdr at codesourcery dot com>, Phil Edwards <pedwards at disaster dot jaj dot com>, Per Bothner <per at bothner dot com>, Daniel Berlin <dan at cgsoftware dot com>, <gcc-patches at gcc dot gnu dot org>
- Date: 30 Nov 2001 14:34:34 +0100
- Subject: Re: Valarrays and [altivec] vectors (was Re: [PATCH]: Handle vector modes in genopinit.c, c-typeck.c)
- Organization: CodeSourcery, LLC
- References: <Pine.LNX.4.33.0111301253050.12846-100000@kern.srcf.societies.cam.ac.uk>
"Joseph S. Myers" <jsm28@cam.ac.uk> writes:
| On 30 Nov 2001, Gabriel Dos Reis wrote:
|
| > | > When can valarrays be used in ? : conditional expressions?
| > |
| > | I don't know of any restrictions here. Gaby?
| >
| > There is no implicit conversion valarray<T> -> bool. So they can't be
| > used in the condition part of "?:", but they are certainly valid
| > arguments for the second and third operands are any C++ objects.
|
| When used as the second or third arguments, must the second and third
| arguments then be valarrays of the same type?
Yes. There is no standard conversion valarray<T> -> valarray<U>.
| > | > Can operations be applied between valarrays of different lengths?
| > |
| > | Undefined behavior. I think the current implementation formats the user's
| > | hard drive.
| >
| > Exact :-)
|
| I hope that for vectors in C we make this a constraint violation.
That is a constraint violation in C++ as well, but then what should
happen if that constraint is violated? In C++, it is an undefined
behaviour. What do you propose for C?
| > | > Can
| > | > they be applied between valarrays and scalars?
| > |
| > | Yes.
| >
| > Exact.
|
| What's the result? Applying the operation between each element and the
| scalar (the scalar being evaluated only once) and returning a valarray of
| the same type as the valarray argument?
Exactly.
| Does this apply to such
| operations as "valarray = scalar" (setting each element) and "valarray +=
| scalar" (adding scalar to each element)?
Yes, (known in Fortran as a "broadcast operation").
| What's the result of array indexing on a valarray?
There our four (4) kinds of indexing valarray<>s in C++
1) index by a slice (start, end, stride). The result is a either a
slice_array<T> (having a reference semantics and convertible to a
valarray<T> value) or a value of type valarray<T>.
2) index by a generalized slice (glice) -- this is the C++ way of
constructing a multidimensional array out of a unidimensional
array. The result is either a gslice<T> (having a reference
semantics, and convertible to a valarray<T> value) or a value of
type valarray<T>.
3) index by a valarray<size_t> (a mapping from "logical" slots to
"physical" slots). The result is either an indirect_array<T>
(having a referebce semantics, and convertible to a valarray<T>
object) or a value of type valarray<T>.
4) index by a valarray<bool> (pretty much close to the
WHERE-construct in FORTRAN). The result is either a mask_array<T>
(having a reference semantics, and convertible to a valarray<T>
object) or a value of type valarray<T>.
| Ordinary array
| indexing extracting a single value, or applying the indexing to each
| element and producing another valarray? (We need to define in C the way
| of extracting and setting individual vector elements.)
I'm unsure of what you mean here. Please, could you elaborate?
If v is a valarray<T> and i is a
1) size_t, then v[i] is a T
2) slice, then v[i] is slice_array<T> when used in an "lvalue"
context, and a valarray<T> in an "rvalue" context".
3) gslice, then v[i] is gslice_array<T> when used in an "lvalue"
context, and a valarray<T> in an "rvalue" context.
4) valarray<size_t>, then v[i] is an indirect_array<T> when used in
an "lvalue" context, and a valarray<T> in an "rvalue" context.
5) valarray<bool>, then v[i] is a mask_array<T> when used in an
"lvalue" context, and a valarray<T> in an "rvalue" context.
-- Gaby