|
Boost : |
Subject: Re: [boost] Boost SIMD beta release
From: Joel Falcou (joel.falcou_at_[hidden])
Date: 2012-12-20 13:01:47
Le 20/12/2012 18:34, Peter Dimov a écrit :
> What is the recommended Boost.SIMD way to write a function like
>
> void add_n( float const * s, float const * s2, float * d, size_t n );
> // d[i] = s[i] + s2[i]
>
> where none of s, s2, d are guaranteed to be aligned?
You should align them ;)
More seriously, you can run a for using with pack and unaligned_load/store:
void add_n( float const * s, float const * s2, float * d, size_t n )
{
size_t c = pack<float>::static_size;
size_t vn = v / c * c;
size_t sn = v % c;
for(std::size_t i=0, i<vn; i+= c, d+=c,s+=c,s2+=c)
store(unaligned_load<pack<T>>(s) + unaligned_load<pack<T>>(s2), d );
for(std::size_t i=0, i<sn; i++,d++,s++,s2++)
*d = *s + *s2;
}
This also takes the fact n can be not a multiple of pack cardinal into
account.
If pointer is aligned you can actually just use simd::input_iterator and
feed this to std::transform.
Maybe we should have a simd::unaligned_input_iterator and/or make
simd::transform accept non aligned data. Note that on any pre-Nehalem
CPU, the unaligned load will be horrendsously slow.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk