32 位处理器上的 64 位/64 位余数查找算法? [英] 64 bit / 64 bit remainder finding algorithm on a 32 bit processor?

查看:26
本文介绍了32 位处理器上的 64 位/64 位余数查找算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道过去曾有人问过类似的问题,但经过长时间的处理,我实现了使用重复减法除法正确找到的算法.但是我无法从这种方法中找出剩余部分.有什么快速简便的方法可以在 32 位处理器上找出 64 位/64 位划分中的余数.更准确地说,我正在尝试实施

I know that similar questions has been asked in the past, but I have implemented after a long process the algorithm to find the quotient correctly using the division by repeated subtraction method. But I am not able to find out the remainder from this approach. Is there any quick and easy way for finding out remainder in 64bit/64bit division on 32bit processor. To be more precise I am trying to implement

ulldiv_t __aeabi_uldivmod(  
 unsigned long long n, unsigned long long d)  

在本文档中引用 http://infocenter.arm.com/help/topic/com.arm.doc.ihi0043d/IHI0043D_rtabi.pdf

推荐答案

什么?如果你做重复减法(这听起来很基础),那么当你不能再做一次减法时,你剩下的就是余数不是那么简单吗?

What? If you do repeated subtraction (which sounds really basic), then isn't it as simple as whatever you have left when you can't do another subtraction is the remainder?

至少这是一种天真的直观方式:

At least that's the naïve intuitive way:

uint64_t simple_divmod(uint64_t n, uint64_t d)
{
  if (n == 0 || d == 0)
    return 0;
  uint64_t q = 0;
  while (n >= d)
  {
    ++q;
    n -= d;
  }
  return n;
}

或者我错过了这里的船?

Or am I missing the boat, here?

当然,这对于大数来说会非常慢,但这是重复减法.我敢肯定(即使不看!)还有更高级的算法.

Of course this will be fantastically slow for large numbers, but this is repeated subtraction. I'm sure (even without looking!) there are more advanced algorithms.

这篇关于32 位处理器上的 64 位/64 位余数查找算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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