问题描述
x86-64上的高性能高性能本机大整数库如何表示内存中的一个大整数? (或者是否有所不同?有最常用的方法吗?)
How do hig-performance native big-integer libraries on x86-64 represent a big integer in memory? (or does it vary? Is there a most common way?)
天真的我正在考虑将它们存储为以0终止的数字字符串,并以2为底的.
Naively I was thinking about storing them as 0-terminated strings of numbers in base 2.
例如,假设X
在内存中为:
For example suppose X
is in memory as:
[8 bytes] Dn
.
.
[8 bytes] D2
[8 bytes] D1
[8 bytes] D0
[8 bytes] 0
让B = 2
然后
空字符串(即8个字节的零)表示零.
The empty string (i.e. 8 bytes of zero) means zero.
这是一种合理的方法吗?这种方式的优缺点是什么?有更好的方法吗?
Is this a reasonable way? What are the pros and cons of this way? Is there a better way?
您将如何处理签名? 2的补码是否可以与此可变长度值一起使用?
How would you handle signedness? Does 2's complement work with this variable length value?
(发现: http://gmplib.org/manual/Integer-Internals.html 什么是肢体?)
(Found this: http://gmplib.org/manual/Integer-Internals.html Whats a limb?)
推荐答案
我认为这将是数组的最低值到最高值.我在汇编程序中实现了任意大小数字的加法. CPU提供了进位标志,使您可以轻松地执行这些类型的操作.您编写一个以字节大小的块执行操作的循环.进位标志包含在使用加进位加法"指令(ADC操作码)的下一个操作中.
I would think it would be as an array lowest value to highest. I implemented addition of arbitrary sized numbers in assembler. The CPU provides the carry flag that allows you to easily perform these sorts of operations. You write a loop that performs the operation in byte size chunks. The carry flag is included in the next operation using the "Add with carry" instruction (ADC opcode).
这篇关于x86-64大整数表示形式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!