将int32_t转换为未签名的char。 avx

发布于 2025-02-04 05:36:12 字数 902 浏览 3 评论 0原文

需要使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文