128-bit division intrinsic in Visual C++

128-bit, integer-division, intrinsics, visual-c++

Solution

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/

Problem

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

Original source

Related problems