Boost logo

Boost :

Subject: Re: [boost] [SIMD] Pre-review questions
From: Joel FALCOU (joel.falcou_at_[hidden])
Date: 2017-03-26 16:14:15


On 26/03/2017 15:28, Artyom Beilis via Boost wrote:

> Still do you have examples or documentation for:
>
> How do I cast for example low part or high part something like:
>
> pack<unsigned byte,16> v;
> pack<unsigned short,8> v1=cast_low(v); // note sometimes I indeed need
> only low or only high part - not both
> pack<unsigned short,8> v2=cast_high(v);
> ...
> v=join_cast(v1,v2); // short to byte
>
> What is saturation policy: if I have unsigned short of value 257
> casted to unsigned char would it cast to 1 or to 255?
> How can I control the policy?

If you only need part of it, it's not a cast, it's a split as cast
preserve cardinality of pack.

pack<unsigned byte,16> v;
pack<unsigned short,8> v1=split_low(v);
pack<unsigned short,8> v2=split_high(v);

and if you need both :

pack<unsigned byte,16> v;
auto vs = split(v);

and vs[0],vs[1] are the low and high parts respectively.

IIRC split has no saturation policy as saturation is what we use when
you go down the type. You can rebuild a smaller type using group or
saturated_(group).

You also have slice that slice a pack in two, keeping the type but
reducing the cardinal. combine do the reverse.

Considering this complexity, most of the common use-cases are handled by
pack_cast already, leaving direct call to split_* for more advanced usages.

As for the doc, thanks for raising an actual bug, the doc is not indeed
properly included. Will fix this.

Maybe a tutorial about pack_cast,slice,split,group and combine is indeed
needed.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk