为什么签署并在x86(-64)无符号乘法运算不同的指令? [英] Why are signed and unsigned multiplication different instructions on x86(-64)?

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

问题描述

我以为2的补全的一点是,操作可以实现有符号和无符号数以同样的方式。 维基百科甚至专门列出乘法作为有利于的操作之一。那么,为什么86为每个单独的指令, MUL IMUL ?这仍然是如此的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具有相同的重presentation为无符号数,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天全站免登陆