如何使用32位除法指令执行64位除法? [英] How can I perform 64-bit division with a 32-bit divide instruction?

查看:869
本文介绍了如何使用32位除法指令执行64位除法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是(AFAIK)在此常规中的一个特定问题主题.

这里是情况:

我有一个基于32位RISC微控制器(NEC V810的变体)的嵌入式系统(视频游戏机).我想写一个定点数学库.我阅读了这篇文章,但是随附的源代码是用386程序集编写的,因此既不能直接使用,也不能轻易修改.

V810具有内置的整数乘法/除法功能,但是我想使用上面文章中提到的18.14格式.这需要将64位int除以32位int,并且V810仅执行(有符号或无符号)32位/32位除法(这将产生32位商和32位余数). /p>

所以,我的问题是:如何模拟32位/32位除法的64位/32位除法(以允许对股息进行预移位)?或者,从另一种角度看问题,使用标准的32位算术/逻辑运算将18.14定点除以另一点的最佳方法是什么? (最佳"表示最快,最小或两者兼有.)

代数,(V810)汇编和伪代码都很好.我将从C调用代码.

提前谢谢!

不知何故我错过了此问题.但是,它仍然需要进行一些修改才能变得超级高效(它必须比v810提供的浮点div更快,尽管它可能已经是...),所以请随时为我做我的工作以换取声誉点数;)(当然,还要记入我的图书馆文档中).

解决方案

GCC对于许多处理器都具有这样的例程,名为_divdi3(通常使用常见的divmod调用实现). 这是一个.一些Unix内核也有一个实现,例如 FreeBSD .

This is (AFAIK) a specific question within this general topic.

Here's the situation:

I have an embedded system (a video game console) based on a 32-bit RISC microcontroller (a variant of NEC's V810). I want to write a fixed-point math library. I read this article, but the accompanying source code is written in 386 assembly, so it's neither directly usable nor easily modifiable.

The V810 has built-in integer multiply/divide, but I want to use the 18.14 format mentioned in the above article. This requires dividing a 64-bit int by a 32-bit int, and the V810 only does (signed or unsigned) 32-bit/32-bit division (which produces a 32-bit quotient and a 32-bit remainder).

So, my question is: how do I simulate a 64-bit/32-bit divide with a 32-bit/32-bit one (to allow for the pre-shifting of the dividend)? Or, to look at the problem from another way, what's the best way to divide an 18.14 fixed-point by another using standard 32-bit arithmetic/logic operations? ("best" meaning fastest, smallest, or both).

Algebra, (V810) assembly, and pseudo-code are all fine. I will be calling the code from C.

Thanks in advance!

EDIT: Somehow I missed this question... However, it will still need some modification to be super-efficient (it has to be faster than the floating-point div provided by the v810, though it may already be...), so feel free to do my work for me in exchange for reputation points ;) (and credit in my library documentation, of course).

解决方案

GCC has such a routine for many processors, named _divdi3 (usually implemented using a common divmod call). Here's one. Some Unix kernels have an implementation too, e.g. FreeBSD.

这篇关于如何使用32位除法指令执行64位除法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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