为什么 x86(-64) 上的有符号和无符号乘法指令不同? [英] Why are signed and unsigned multiplication different instructions on x86(-64)?

查看:31
本文介绍了为什么 x86(-64) 上的有符号和无符号乘法指令不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为 2 的补码的全部意义在于,对于有符号数和无符号数,操作可以以相同的方式实现.维基百科甚至特别将乘法列为受益的操作之一.那么为什么 x86 对 mulimul 分别有单独的指令?这对于 x86-64 仍然适用吗?

I thought the whole point of 2's complement was that operations could be implemented the same way for signed and unsigned numbers. Wikipedia even specifically lists multiply as one of the operations that benefits. So why does x86 have separate instructions for each, mul and imul? Is this still true for x86-64?

推荐答案

加法和减法是一样的,乘法的低半部分也是一样.然而,完整的乘法不是.简单例子:

Addition and subtraction are the same, as is the low-half of a multiply. A full multiply, however, is not. Simple example:

在 32 位二进制补码中,-1 与无符号量 2**32 - 1 具有相同的表示形式.但是:

In 32-bit twos-complement, -1 has the same representation as the unsigned quantity 2**32 - 1. However:

-1 * -1 = +1
(2**32 - 1) * (2**32 - 1) = (2**64 - 2**33 + 1)

(请注意,两个结果的低 32 位是相同的;这就是我说乘法的低一半"是相同的意思).

(Note that the low 32-bits of both results are the same; that's what I mean when I say the "low-half of the multiply" is the same).

这篇关于为什么 x86(-64) 上的有符号和无符号乘法指令不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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