Visual C 中的 128 位除法内在函数
我想知道Visual C++中是否真的没有128位除法内部函数?
有一个名为 _umul128()
的 64x64=128 位乘法内部函数,它与 MUL
x64 汇编指令非常匹配。
当然,我假设也会有一个 128/64=64 位除法内在函数(对 DIV
指令进行建模),但令我惊讶的是 Visual C++ 和 Intel C++ 似乎都没有它,至少它是未在 intrin.h 中列出。
有人可以证实吗?我尝试在编译器可执行文件中查找函数名称,但一开始就找不到 _umul128 ,所以我想我找错了地方。
更新:至少我现在在 Visual C++ 2010 的 c1.dll 中找到了模式 umul128
(没有前导下划线)。所有其他内在函数都在它周围列出,但不幸的是没有“udiv128”或就像:(所以看来他们真的“忘记”实现它了。
澄清一下:我不仅在寻找 128 位数据类型,而且在寻找一种划分 128 位的方法C++ 中的 64 位 int 的标量 int。内在函数 或 本机 128 位整数支持可以解决我的问题
。答案是否定的,直到 2017 年,Visual Studio 2010 中都没有 _udiv128
内在函数,但它在 Visual Studio 2019 RTM 中可用
I'm wondering if there really is no 128-bit division intrinsic function in Visual C++?
There is a 64x64=128 bit multiplication intrinsic function called _umul128()
, which nicely matches the MUL
x64 assembler instruction.
Naturally, I assumed there would be a 128/64=64 bit division intrinsic as well (modelling the DIV
instruction), but to my amazement neither Visual C++ nor Intel C++ seem to have it, at least it's not listed in intrin.h.
Can someone confirm that? I tried grep'ing for the function names in the compiler executable files, but couldn't find _umul128
in the first place, so I guess I looked in the wrong spot.
Update: at least I have now found the pattern umul128
(without the leading underscore) in c1.dll of Visual C++ 2010. All the other intrinsics are listed around it, but unfortunately no "udiv128" or the like :( So it seems they really have "forgotten" to implement it.
To clarify: I'm not only looking for a 128-bit data type, but a way to divide a 128-bit scalar int by a 64-bit int in C++. Either an intrinsic function or native 128-bit integer support would solve my problem.
Edit: The answer is no, there is no _udiv128
intrinsic in Visual Studio 2010 up to 2017, but it is available in Visual Studio 2019 RTM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您不介意小技巧,这可能会有所帮助(仅限 64 位模式,未经测试):
If you don't mind little hacks, this may help (64-bit mode only, not tested):
一个小改进——少一条指令
A small improvement - one less instruction
现在可以使用了。您可以使用
_div128
和_udiv128
去年据说可以从“Dev16”获得,但我没有确定是哪个版本。我猜它是 VS 16.0 AKA VS2019,但 MSDN 上的文档显示它更进一步到 VS2015
It's available now. You can use
_div128
and_udiv128
Last year it was said to be available from "Dev16" but I'm not sure which version is that. I guess it's VS 16.0 A.K.A VS2019, but the documentation on MSDN shows that it goes further to VS2015
我不是专家,但我发现了这一点:
http://research。 swtch.com/2008/01/division-via-multiplication.html
有趣的东西。希望有帮助。
编辑:这也很有洞察力: http://www.gamedev.net/topic /508197-x64-div-内在/
I am no expert, but I dug this up:
http://research.swtch.com/2008/01/division-via-multiplication.html
Interesting stuff. Hope it helps.
EDIT: This is insightful too: http://www.gamedev.net/topic/508197-x64-div-intrinsic/
感谢@alexey-frunze,它对 VS2017 进行了一些调整,并使用与 VS2019 相同的参数进行了检查:
Thanks @alexey-frunze, it worked with little tweak for VS2017, checked with same parameters with VS2019: