Fastest way to fill SIMD-vector with data
Matthias Kretz
[please enable javascript to see the address]
Fri Nov 1 12:55:58 CET 2013
Hi,
On Thursday 31 October 2013 10:30:37 Kulakov, Igor wrote:
> what is actually current the fastest way to fill a vector with data?
an aligned load. Meaning, the data you want to have in the vector is stored in
memory in the order you will need it later.
> Before Vc didn't let us to assign a data entry by entry and we used Memory
> class. Like this:
>
> float_v::Memory tmpFloat;
> for(int iV=0; iV < float_v::Size; iV++)
> tmpFloat[iV] = t0[iV]->X();
> tmpVec.load( tmpFloat );
> t.SetX(tmpVec);
>
>
> But will it be optimised by compiler to be equivalent to desired:
>
>
> for(int iV=0; iV < float_v::Size; iV++)
> t.fX[iV] = t0[iV]->X();
You can do the latter with Vc now. The former should be equivalent with a good
optimizing compiler. But, the latter is obviously a lot more readable and
states the intent of the programmer much clearer.
> I tried to find a use case of Vc::Memory in Vc-0.7 doxygen documentation and
> failed. When exactly we should use this class?
Vc::Memory is meant as a smarter array. I.e. one that knows how to iterate
over SIMD vectors and scalars. And it ensures padding at the end.
You could also use std::vector<float_v>, but in that case scalar iteration is
a bit awkward (because std::vector does not provide the extra API):
void f(const std::vector<float_v> &data) {
for (float_v entry : data)
for (size_t i = 0; i < entry.Size; ++i)
std::cout << entry[i] << '\n';
}
--
─────────────────────────────────────────────────────────────
Dipl.-Phys. Matthias Kretz
Phone: +49 69 798 44110
Web: http://compeng.uni-frankfurt.de/?mkretz
SIMD easy and portable: http://compeng.uni-frankfurt.de/?vc
─────────────────────────────────────────────────────────────
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://compeng.uni-frankfurt.de/pipermail/vc/attachments/20131101/e6f9d63d/attachment.pgp>
More information about the Vc
mailing list