使用 AVX2 将 2 个 32 位数字相乘并取前 32 位 [英] Multiplying 2 32-bit numbers and taking the top 32 bits using AVX2

查看:50
本文介绍了使用 AVX2 将 2 个 32 位数字相乘并取前 32 位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用乘法(加上其他运算)作为整数除法的替代.我的解决方案最终要求我将 2 个 32 位数字相乘并取前 32 位(就像 mulhi 函数一样),但 AVX2 不提供 _mm256_mulhi_epu16 的 32 位变体(例如:没有 '_mm256_mulhi_epu32' 函数).

I am using multiplication (with the addition of other operations) as a substitution for integer division. My solution eventually requires me to multiply 2 32-bit numbers together and take the top 32 bits (just like the mulhi function), but AVX2 does not offer a 32-bit variant of _mm256_mulhi_epu16 (Ex: there's no '_mm256_mulhi_epu32' function).

我尝试了各种方法,例如检查AVX512的功能,甚至将32位整数操纵为2 hi/lo 16位整数.我对使用低级编程非常陌生,所以我不知道什么是最佳的,甚至是可能的.

I have tried various methods such as checking the functions of AVX512, or even manipulating the 32-bit integers to be 2 hi/lo 16-bit integers. I'm very new to working with low-level programming, so I'm unaware what is optimal, or even just possible.

推荐答案

这可以通过执行以下操作来完成:

This can be done by doing the following:

__m256i t1 = _mm256_mul_epu32(m, n);
t1 = _mm256_srli_epi64(t1, 32);

这篇关于使用 AVX2 将 2 个 32 位数字相乘并取前 32 位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆