将int32_t转换为未签名的char。 avx
需要使用AVX Intrinsics正确将8 int32_t的YMM和8个未签名的UINT8_T转换为XMM。它应该是static_cast< uint8_t>
的类似物。这意味着C ++标准规则有效(模块化减少)。因此,我们得到了2个补充bit-Pattern的截断。
例如,(int32_t)( - 1)
- > (uint8_t)(255)
和+200
- > (uint8_t)(200)
因此,我们不能将签名或未签名的饱和度(甚至是16位作为中间步骤)。
我有此代码为示例:
packssdw xmm0, xmm0
packuswb xmm0, xmm0
movd somewhere, xmm0
但是这些命令使用未签名的饱和度,因此我们获得(int32_t)(-1)
- > (UINT8_T)(0)
。
我知道vcvttss2si
,并且仅适用于一个值。为了获得最佳性能,我想使用向量寄存器。
我也知道改组,但对我来说足够慢。
因此,是否有另一种方法可以将从int32_t ymm转换为uint8_t ymm作为static_cast< uint8_t>
?
upd:@chtz的评论是我问题的答案。
Need to correctly convert YMM with 8 int32_t to XMM with 8 UNSIGNED uint8_t at the bottom, using AVX intrinsics. It should be analogue of static_cast<uint8_t>
. It means that C++ standard rules work (modular reduction). So we get truncation of the 2's complement bit-pattern.
For example, (int32_t)(-1)
-> (uint8_t)(255)
, and +200
-> (uint8_t)(200)
so we can't use signed or unsigned saturation to 8-bit (or even to 16-bit as an intermediate step).
I have this code as the example:
packssdw xmm0, xmm0
packuswb xmm0, xmm0
movd somewhere, xmm0
But these commands use unsigned saturation, so we get (int32_t)(-1)
-> (uint8_t)(0)
.
I know vcvttss2si
and it works correctly but only for one value. For the best performance I want to use vector registers.
Also I know about shuffling but it's enough slow for me.
So Is there another way to convert from int32_t YMM to uint8_t YMM as static_cast<uint8_t>
?
UPD: The comment of @chtz is answer of my question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论