- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当 gcc
看到硬件不支持的整数类型的乘法或除法,它会生成对特殊库函数的调用。
http://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html#Integer-library-routines
根据上面的链接,long __divdi3 (long a, long b)
用于长的除法。然而,这里http://gcc.gnu.org/onlinedocs/gcc-3.3/gccint/Library-Calls.html divdi 解释为“要求分割一个带符号的双字”。当第一个源具有 di 后缀 -> 长参数的清晰映射时,第二个表示双字 divdi 和全字 udivdi(单个,对吗?)
当我编译简单的例子时
int main(int argc, char *argv[]) {
long long t1, t2, tr;
t1 = 1;
t2 = 1;
tr = t1 / t2;
return tr;
}
与 gcc -Wall -O0 -m32 -march=i386
(海湾合作委员会版本 4.7.2)拆解给我看
080483cc <main>:
80483cc: 55 push %ebp
80483cd: 89 e5 mov %esp,%ebp
80483cf: 83 e4 f0 and $0xfffffff0,%esp
80483d2: 83 ec 30 sub $0x30,%esp
80483d5: c7 44 24 28 01 00 00 movl $0x1,0x28(%esp)
80483dc: 00
80483dd: c7 44 24 2c 00 00 00 movl $0x0,0x2c(%esp)
80483e4: 00
80483e5: c7 44 24 20 01 00 00 movl $0x1,0x20(%esp)
80483ec: 00
80483ed: c7 44 24 24 00 00 00 movl $0x0,0x24(%esp)
80483f4: 00
80483f5: 8b 44 24 20 mov 0x20(%esp),%eax
80483f9: 8b 54 24 24 mov 0x24(%esp),%edx
80483fd: 89 44 24 08 mov %eax,0x8(%esp)
8048401: 89 54 24 0c mov %edx,0xc(%esp)
8048405: 8b 44 24 28 mov 0x28(%esp),%eax
8048409: 8b 54 24 2c mov 0x2c(%esp),%edx
804840d: 89 04 24 mov %eax,(%esp)
8048410: 89 54 24 04 mov %edx,0x4(%esp)
8048414: e8 17 00 00 00 call 8048430 <__divdi3>
8048419: 89 44 24 18 mov %eax,0x18(%esp)
804841d: 89 54 24 1c mov %edx,0x1c(%esp)
8048421: 8b 44 24 18 mov 0x18(%esp),%eax
8048425: c9 leave
8048426: c3 ret
备注8048414: call 8048430 <__divdi3>
.
我不能为我的项目使用 gcc 库,而且它是多平台的。我希望不要写所有__*
适用于所有平台的功能(速度无关紧要),但现在我有点困惑。
有人可以解释一下,为什么会有__divdi3
(不是 __divti3
)为 long long int
生成的调用(64 位)除法?
最佳答案
在 x86 机器上,术语“字”通常表示存在 16 位值。更一般地,在计算机科学领域,word
可以表示几乎任意长度的值,10 或 12 位的字在嵌入式系统中并不少见。
我认为您偶然发现的术语用于 Linux/Unix 系统只是为了统一操作系统级别,与您构建的目标平台无关。在 gdb
中可以找到使用相同符号的示例,它使用 w
表示 32 位字,使用 hw
表示 16 位字位“半字”(在 x86 意义上)。
此外,该约定还可以轻松扩展到标准 IEEE-754 float ,并在下面的几个要点中进行了总结
s
- 单(精度,字)用于四字节整数(int
)/ float (float
)d
- 八字节整数(long
或 long long
)/ float (double
)的 double (精度) >)t
- 十个字节的整数(long long
)/ float (long double
)此命名约定用于所有算术内置函数,如 __divsi3
、__divdi3
、__divti3
或 __mulsi3
、__muldi3
、__multi3
...(以及所有 u
- 无符号 - 变体)。可以找到完整列表 here .
在 32 位机器上除法 64 位数字使用高级(并且有点困难)算法。但是,您仍然可以使用在学校学到的算法原理。这是它的简单伪代码(查看关于大整数的 this answer):
result = 0;
count = 0;
remainder = numerator;
while(highest_bit_of_divisor_not_set) {
divisor = divisor << 1;
count++;
}
while(remainder != 0) {
if(remainder >= divisor) {
remainder = remainder - divisor;
result = result | (1 << count);
}
if(count == 0) {
break;
}
divisor = divisor >> 1;
count--;
}
关于c - x86 上的 gcc 使用了 long long 的 divdi3 除法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18448343/
我正在尝试编写一个简单的除法函数,但出现错误 PS C:\Users\john> Function Div($x, $y) { $x / $y } PS C:\Users\john> Div (1,
试图找出这个伪代码。以下假设...... 我只能使用无符号和有符号整数(或长整数)。 除法返回一个没有余数的实数。 MOD 返回一个实数。 不处理分数和小数。 INT I = 41828; INT C
如果我有以下表格并且我在关系代数中执行 R1/R2,结果会是一个具有 A 值 1 和 3 的表格吗?我有点困惑,因为我知道 3 将是一个结果,因为它包含 5 和 1,但结果 1 除了匹配的值之外还有
//Declare and intialize variables - programmer to provide initial values Scanner in = new Scanne
除法运算符在 scala BigDecimal 上有什么用? val d1 = BigDecimal(2) val d2 = BigDecimal(3) val div = d1 / d2 //thr
这个问题在这里已经有了答案: How can I divide properly using BigDecimal (2 个答案) 关闭 6 年前。 我在这里做错了什么?很确定这是正确的,我能够打印
好的 - 已经为此苦苦挣扎了一段时间。我刚刚开始学习 Python,所以非常新。 我有一个元组列表,需要按每个元组中值的比率进行排序。 输入: L = [(1,3), (1,7), (4,8)] 返回
我有一个奇怪的问题,我收到计算机生成的方程式(作为字符串),其中偶尔会出现零或一和零的乘法/除法。这些等式将以字符串形式呈现给用户。 我知道我可以通过实现一种解析器来删除等式中的这些冗余部分,但我很好
我有两个变量:count,这是我过滤的对象的数量,以及每页的常量值。我想将计数除以 per_page 并获得整数值,但无论我尝试什么 - 我都得到 0 或 0.0: >>> count = frien
我尝试在 Go 中获得 2.4/0.8 == 3 w:=float64(2.4) fmt.Println(math.Floor(w/0.8),math.Floor(2.4/0.8) ) 它给了我“2
程序清单: # val_caculate.py a = 10 # a是整数 print('10/3 = ',10/3) print('9/3 = ',9/3) pri
我是 java 新手,所以我需要你对我正在进行的项目的帮助!我定义了一些计数器,这些是我将使用的: int[] acceptCounters = {}; int[] acceptFailCounter
我正在除 2 个 BigInteger 值 N = 9440056782685472448790983739834832785827768777249804302814308027414135716
我的应用程序中有使用 array.reduce 将数字相乘的代码。它看起来像这样: // Private function to multiply field values together func
我目前创建了一个名为 Array Math 的类,它将乘法加载到 10x10 数组中,如代码下显示的图像所示,但是我想要做的是在乘法后将每个位置除以 2。换句话说,(行 * 列)/2 目前我只是将这些
我正在使用代表货币金额的 BigDecimal 值。我需要将此金额分成 6 个费率,前 5 个费率四舍五入为 5,其余的为第 6 个费率。 BigDecimal numberOfRates = new
这个问题必须使用递归来解决。 我尝试使用 “else” 之后的代码来使用 int temp 计算商,该 temp 计算可以除以多少次 (temp = dividend - divisor)。 int
我知道这一定是有史以来最简单的事情,但我是这里的初学者。为什么我运行时会出现语法错误 document.write(10 / 2 + ""); //Divide 10 by 5 to get 2
这应该是一个非常基本的东西,但不知何故我没有看到问题。 #include template inline void i2c(const int & ind, int & i, int &j) {
我正在做课本中的一些家庭作业,并且有一些关于某些算术运算的浮点舍入/精度的问题。 如果我像这样从 int 中转换 double : int x = random(); double dx = (dou
我是一名优秀的程序员,十分优秀!