Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert __m128i value into std::tuple

Tags:

c++

c++11

simd

sse

Imagine that, after some SIMD calculations, I get a __m128i value with the fourth field with a useless zero value. Is there a simple and portable way to cast the other three fields into a std::tuple<int,int,int>, bearing in mind it is not standard layout?

like image 652
metalfox Avatar asked Apr 01 '26 00:04

metalfox


1 Answers

Ugly, but portable. I don't believe, that there is fast solution, since std::tuple does not have defined memory layout. So just copying those three values into a tuple.

std::tuple<int, int, int> to_tuple(__m128i& value)
{
    auto* ptr = reinterpret_cast<int*>(&value);
    return std::make_tuple(ptr[0], ptr[1], ptr[2]);
}

Why do you need this? Maybe you can get around your problem some other way.

like image 78
Zereges Avatar answered Apr 02 '26 12:04

Zereges



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!