c - 在没有 C 运行时的情况下使用 64 位整数 - 链接错误 __alldiv

标签 c html 64-bit linker runtime

我正在尝试在不使用 C 运行时(msvcrt 或 libcmt)的情况下构建 Windows 控制台应用程序。即仅链接 kernel32.lib 并使用 WIN32 API 中的控制台函数而不是 printf 等。

我的问题是,在链接期间,编译器无法找到 __alldiv,它似乎可以在 32 位应用程序中处理 64 位整数除法。我尝试了微软的编译器和英特尔的编译器。

该函数存在于运行时库中。令人烦恼的是,像 64 位整数这样的基本数据将需要完整的 C 运行时。

有什么想法可以解决这个问题吗?

最佳答案

可以处理比硬件除法器可以处理的除数更大的扩展精度除法例程,它比您想象的更复杂。我曾经不得不编写一个函数来将 128 位值除以 64 位值,这是相当痛苦的(并且在一般情况下很慢)。

看看 Randall Hyde 在他的 "Art of Assembly Language" text (Volume 4, Section 4.2.5 - Extended Precision Division) 中讨论的算法.

以下是摘录:

You cannot synthesize a general n-bit/m-bit division operation using the DIV and IDIV instructions. Such an operation must be performed using a sequence of shift and subtract instructions and is extremely messy. However, a less general operation, dividing an n-bit quantity by a 32 bit quantity is easily synthesized using the DIV instruction. This section presents both methods for extended precision division.

Before describing how to perform a multi-precision division operation, you should note that some operations require an extended precision division even though they may look calculable with a single DIV or IDIV instruction. Dividing a 64-bit quantity by a 32-bit quantity is easy, as long as the resulting quotient fits into 32 bits. The DIV and IDIV instructions will handle this directly. However, if the quotient does not fit into 32 bits then you have to handle this problem as an extended precision division. The trick here is to divide the (zero or sign extended) H.O dword of the dividend by the divisor, and then repeat the process with the remainder and the L.O. dword of the dividend.

因此,您可能想做的一件事是确定是否确实需要在除数中使用 64 位数量 - 如果不需要,您可以轻松编写一个执行该任务的函数。如果您确实需要将 64 位值除以 64 位值,您仍然可以这样做,但这是一个更困难的问题。更具体地说,它可能不适合编译器“内联” - 因此它是一个库例程。

哦,别忘了 - MS 提供了库源代码。 __alldiv()lldiv.asm 中的汇编语言函数。只需将该文件添加到您的项目中并将其链接起来,而不需要库的其余部分,应该不会太难。

关于c - 在没有 C 运行时的情况下使用 64 位整数 - 链接错误 __alldiv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/482624/

相关文章:

asp.net - mvc4 或 html 5 中的文件输入过滤器?

javascript - 选项卡式 View ,为什么它不起作用?

ios - 我的应用程序支持 64 位吗? (IOS)

C - 使用暴力搜索 64 位 Linux 内核中的系统调用表

c - 在 C : "undefined reference to ` sqrtf'"中使用 sqrtf()

字符数组转整数

iphone - 如果值大于 10,则使用一个函数处理该值每 10 个,然后使用另一个函数处理该值的其余部分

c - 如何将 argv 与元素数组进行比较?

javascript - 第二次选择菜单更改基于第一次选择菜单

visual-studio-2008 - 有没有人已经完成了使用 VS2008 构建 STLPort 和/或使用 VS2005 构建 x64 的工作?