[macstl-dev] Re: Question about sized booleans
Glen Low
glen.low at pixelglow.com
Tue Jul 19 21:07:00 WST 2005
IIya:
On 19/07/2005, at 11:49 AM, Ilya Lipovsky wrote:
> On Tue, 19 Jul 2005, Glen Low wrote:
>
>>> Can I have this: "valarray <macstl::boolean <float> > and then
>>> assign to it (vec1 < vec2), where vec1&vec2 are both of type
>>> "valarray <float>"? I tried it and failed. Should valarray be
>>> extended for sized booleans?
>>>
>>
>> All valarray expressions that return a bool already chunk as the
>> appropriate sized boolean e.g.
>>
>> valarray <float> a, b;
>> a < b chunks as boolean <int>
>> valarray <short> c, d;
>> c < d chunks as boolean <short>
>>
>> You just can't store them in a valarray <bool> yet, because bool
>> is usually a fixed size on particular compilers/operating systems.
>> You used to be able to assign a 4 byte element to valarray <bool>
>> in 0.1.x, but I had some problems when I changed the architecture
>> on 0.2.x so I had it #if 0'd out.
>>
>> I'll consider your request as it makes sense. However do note that
>> boolean <float> is only defined in SSE, to express the "subtle"
>> difference between boolean <float> and boolean <int> -- they use
>> different SSE logical operators, even though conceptually and
>> register-wise they are identical. Someone on the simdtech list, I
>> think it was Holger, theorized they might use different register
>> files. We'd have to do a bit of inner type declaring to get it
>> come out correctly e.g.
>>
>> valarray <float>::boolean result = vec1 < vec2;
>>
>> and declare the boolean type inside of valarray <float>. A little
>> uncomfortable with this since this breaks compatibility with
>> std::valarray -- any suggestions?
>>
>>
>
> Hmmm... I sound redundant, but the solution: to extend valarray
> operate on boolean <T> seems to be pretty elegant.
>
> I want to be able to do:
>
> v3 = (v1 || v2), where v1 & v2 are valarray<int> and use v3 any way
> I want to. Currently, I have problems with that. Declaring v3 as
> valarray<int> produces compile-time error (the same goes for
> valarray<macstl::boolean<int> >, as mentioned before). Declaring v3
> as valarray<bool> produces scalar code. The same goes for
> operator&& . What to do... Any suggestions ;) ?
Yes I will do that for 0.3.1.
>
> Also, how to properly use your select function?
The signature looks similar to this:
valarray <T> select (const valarray <bool>& boolexpr, const valarray
<T>& trueexpr, const valarray <T>& falseexpr);
And it will chunk i.e. optimize using Altivec whenever the boolexpr
has the same element size (and in SSE, similar base element) as the
trueexpr and falseexpr e.g.
valarray <float> a, b;
valarray <float> c = select (a < b, a, b); // is a naive
implementation of min (a, b)
You can replace any of the parameters with scalar "constants" (except
for all of the constants), so
c = select (true, a, b);
c = select (a < b, 1.0f, b);
c = select (a < b, a, 1.0f);
c = select (true, 1.0f, b);
c = select (true, a, 1.0f);
c = select (a < b, 1.0f, 2.0f);
will all work and the constants act as if they are a valarray
containing just that constant. (I say "constant" because you can
substitute a scalar variable instead but I wanted the examples to be
clearer.)
Cheers, Glen Low
---
pixelglow software | simply brilliant stuff
www.pixelglow.com
aim: pixglen
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.pixelglow.com/lists/archive/macstl-dev/attachments/20050719/c253abf2/attachment-0001.html
More information about the macstl-dev
mailing list