how to "type_cast<float>(unsigned short)" with Boost.SIMD

17 views
Skip to first unread message

217...@gmail.com

unread,
Jan 20, 2016, 12:14:18 PM1/20/16
to nt2-dev
Does/how does Boost.SIMD provide type_casts?

And how could the following loop be implemented with Boost.SIMD?

std::vector<unsigned short> buffer_in(1024);
std::vector<float, boost::simd::allocator<float> > buffer_out(1024);

for (int i=0;i<1024;i++) {
    buffer_out[i]   = static_cast<float>([i])   - 512.0;
}

Thanks!

Best,
Jan


jean-thierry lapresté

unread,
Jan 20, 2016, 1:41:03 PM1/20/16
to nt2...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "nt2-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nt2-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
The problem here is that native simd vector of short are not of the same size
as simd vector of float, so with boost simd you have to
begin by a split that will transform your vector of int16_t in two
vectors of int32_t each of these vectors can be converted using tofloat
function in an simd vector of float.

Generally to optimize mixing of vectors of floating points numbers and of integers
in simd situations, the best is to have same bit size for the scalar floatings and integers:
float<->int32_t
double<->int64_t

If you were able to put your short directly in a vector of int32_t, it
will avoid the splitting phase and will perhaps be speedier ?!

This also depends of the used proc. Recent ones have no simd vector of short
in their API and directly load short* in vectors of int32_t...

  Cordialy

            J.T. Lapresté
Reply all
Reply to author
Forward
0 new messages