内在的mulx指令 [英] intrinsic for the mulx instruction

查看:645
本文介绍了内在的mulx指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


根据 Intel公司的文档应该有 mulx
$ b

  unsigned __int64 umul128(unsigned __int64 a,unsigned __int64 b,unsigned __int64 * hi); 

但是,我从 BMI2下的英特尔内部指南。然而,我从ADX指令集中发现了addcarry内在函数。



根据这个链接内在是 mulx_u64 ,但我也没有找到。



MSVC添加了 _umul128内部在MSVC 2005,但只产生 mul 而不是 mulx (我不知道如何在MSVC中启用BMI2)。

我可以使用 __ int128 来间接产生 mulx / code>在GCC中使用 -mbmi2 (或 -march = haswell ),但我宁愿做这更直接地使用一个内部函数。

为什么ADX内在函数存在,但对于 mulx a href =http://www.intel.com/content/www/us/en/intelligent-systems/intel-technology/ia-large-integer-arithmetic-paper.html rel =nofollow> Intel的文档

解决方案

生成64位Integer乘法的mulx指令的内在是_mulx_u64()。下面是同样的例子:

  #include  
int main()
{
unsigned __int64 a = 0x0fffffffffffffff;
unsigned __int64 b = 0xf0000000;
unsigned __int64 c,d;
d = _mulx_u64(a,b,& c);
printf_s(%#I64x *%#I64x =%#I64x%I64x \\\
,a,b,c,d);





变量c将保存结果的高64位和变量 d将保持结果的低64位。 Microsoft Visual Studio编译器也支持此内部函数。我们正在努力更新白皮书(新指令支持大整数算术)并使用正确的内部函数。感谢您将此引入我们的注意。


The mulx instruction was introduced with the BMI2 instruction set starting with the Haswell processor.

According to Intel's documentation there should be an intrinsic for mulx

unsigned __int64 umul128(unsigned __int64 a, unsigned __int64 b, unsigned __int64 * hi);

However, I find no such intrinsic from Intel's intrinsic guide online under BMI2 or in general. I do however find the addcarry intrinsics from the ADX instruction set.

According to this link the intrinsic is mulx_u64 but I don't find that one either.

MSVC added a _umul128 intrinsic in MSVC 2005 but that only produces mul and not mulx (and I have no idea how to enable BMI2 in MSVC).

I can produce the mulx instruction indirectly using __int128 in GCC with -mbmi2 (or -march=haswell) but I would prefer to do this more directly using an intrinsic.

Why do the ADX intrinsics exist but not one for mulx as defined in Intel's documentation?

解决方案

The intrinsic which generates mulx instruction for 64 bit Integer multiplication is _mulx_u64(). Below is an example for the same:

    #include <stdio.h> 
    int main() 
    { 
        unsigned __int64 a = 0x0fffffffffffffff; 
        unsigned __int64 b = 0xf0000000; 
        unsigned __int64 c, d; 
        d = _mulx_u64(a, b, &c); 
        printf_s("%#I64x * %#I64x = %#I64x%I64x\n", a, b, c, d); 
    }

Variable "c" will hold the higher 64 bits of the result and variable "d" will hold the lower 64 bits of the result. This intrinsic is also supported in Microsoft Visual Studio Compiler. We are working on updating the white paper (New Instructions Support Large Integer Arithmetic) with the right intrinsic. Thanks for bringing this to our attention.

这篇关于内在的mulx指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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