分由一个常数存储在寄存器2非常大量有效的方式 [英] efficient way to divide a very large number stored in 2 registers by a constant

查看:93
本文介绍了分由一个常数存储在寄存器2非常大量有效的方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我想计算如下:

Let's say I want to calculate the following:

A / Z

其中, A 的长度为128位和以Z 是64位长。 A 存储在2 64位寄存器,因为系统的寄存器可以存储多达64位。什么是来计算结果的有效途径?

Where A is of length 128 bit and Z is 64 bit long. A is stored in 2 64 bit registers since the registers of the system can store up to 64 bits. What would be an efficient way to calculate the result?

PS:我已经通过CSD重新presentations解决类似的乘法问题。然而,这需要计算 1 / Z 第一。

P.S: I've solved similar multiplication problems by using CSD representations. However, this would require calculating 1/Z first.

推荐答案

正确的方法来解决这样的问题,就是回到最基础的:

The right way to solve such a problem, is by returning to the basics:

  • 将分母除以最显著寄存器
  • 计算出商数问:,其余研究
  • pferrably定义一个新的临时寄存器$ P $具有相同的长度与其他2
  • 的其余部分应占据临时寄存器最显著位
  • 由相同的比特量移位的较小显著寄存器向右载我研究并添加到结果到临时寄存器中。
  • 回到步骤1
  • divide the most significant register by the denominator
  • calculate the quotient Q and the rest R
  • define a new temporary register preferrably with the same length as the other 2
  • the rest should occupy the most significant bits in the temporary register
  • shift the lesser significant register to the right by the same amount of bits contained iR and add to the result to the temporary register.
  • go back to step 1

师后,所产生的剩余的被强制转换为,除以分母,然后加入到商。

after the division, the resulting rest must be casted to double, divided by the denominator then added to the quotient.

这篇关于分由一个常数存储在寄存器2非常大量有效的方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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