简体   繁体   English

将__m128i值转换为std :: tuple

[英]Convert __m128i value into std::tuple

Imagine that, after some SIMD calculations, I get a __m128i value with the fourth field with a useless zero value. 想象一下,经过一些SIMD计算后,我得到一个__m128i值,第四个字段的零值无用。 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 ? 是否有一种简单且可移植的方法将其他三个字段转换为std::tuple<int,int,int> ,请记住它不是标准布局

Ugly, but portable. 丑陋,但便携。 I don't believe, that there is fast solution, since std::tuple does not have defined memory layout. 我不相信,有快速的解决方案,因为std::tuple没有定义的内存布局。 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. 也许你可以通过其他方式绕过你的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM