Using 64bit integers without C runtime - __alldiv link error

I am trying to create a windows console application without using the C runtime (msvcrt or libcmt). That is, to bind only to kernel32.lib and use console functions from the WIN32 API instead of printf, etc.

My problem is that during linking the compiler doesn't find __alldiv, which seems to handle division of 64 bit integers in 32 bit applications. I tried both Microsoft and Intel compiler.

This function exists in runtime libraries. It is quite annoying that something as basic as 64-bit integers would require a full C implementation.

Any ideas on how to overcome the problem?


source to share

3 answers

An extended precision subroutine that can handle a divisor larger than a hardware divisor can be more complex than you might think. I once had to write a function to divide 128 values ​​by 64 bit values, and it was quite painful (and generally slow).

Take a look at the algorithm that Randall Hyde discusses in his "The Art of Assembly Language" (Volume 4, Section 4.2.5 - Advanced Precision Division) .

Here's an excerpt:

You cannot synthesize the general n-bit / m-bit division operation with the DIV and IDIV instructions. This operation must be performed using a sequence of shift and subtract commands and is extremely messy. However, the less general operation dividing an n-bit value by a 32-bit amount is easily synthesized using the DIV instruction. This section introduces both advanced dividing methods.

Before describing how to perform a multipoint division operation, you should note that some operations require extended precision division even though they can be calculated with a single DIV or IDIV statement. Dividing a 64-bit quantity by a 32-bit quantity is easy if the resulting factor fits into 32 bits. The DIV and IDIV statements will handle this directly. However, if the factor does not fit into 32 bits, then you have to treat this problem as an extended division of precision. The trick here is to split (zero or extended sign) the word X.O. dividend by the divisor, then repeat the process with the remainder and the LO dword of the dividend.

So, one thing you might want to do is determine if you really need to use 64-bit values ​​in the divisor, and if not, you can easily write a function that will do the task. If you really need to split 64-bit values ​​by 64-bit values, you can still do that, but this is a more complex problem. More specifically, this is probably not something that would be compiler-friendly for "inline" - hence it is a library.

Oh, and don't forget - MS provides the source code for the library. __alldiv()

is a function of the assembly language in lldiv.asm

. Don't just add this file to your project and link it without the rest of the library.



Found a solution to the __alldiv link problem:

Found lldiv.obj in msdev installation. I can add this object file to the link instead of the C runtime.

For me the path is:

c: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ VC \ crt \ src \ intel \ mt_lib \ lldiv.obj.



The msdn page for _alldiv says its usage depends on the compiler optimization settings, not to mention which settings depend on them.

Wine also has _alldiv, which you could borrow.



All Articles