用汇编语言中的一条指令替换两条指令
Replacing two instructions with one instruction in assembly language
这是程序中给出的一些指令的 table。第一列表示指令本身,第二列表示程序中任何指令的权重百分比,第三列表示任何给定指令的 CPI(每条指令的周期数)。
现在,我想用一条指令 madd 替换 add 和 mult。
madd takes three inputs, multiplies the first two inputs and add the result to the third input. This way madd instruction does both the multiplication and addition.
add 和 mult 的当前权重均为 40%。所以问题是,当我用 madd 替换 mult 和 add 时,新的权重是多少madd指令?
Current weight of both add and mult is 40%. So the question is when I
replace the mult and add with madd what will be the weight of new madd
instruction?
如果程序在一个地方包含加法(消耗 CPU 时间的 30%),而在另一个完全不同的地方包含乘法(消耗 CPU 时间的 10%)与添加无关;那么可能完全不可能用 "multiply and add" 指令替换任何东西。
如果程序由一个加法(本身消耗 30% 的 CPU 时间)和 1000 次乘法(每个消耗 0.01% 的 CPU 时间)组成,那么对于 "best case" 你只能替换一次加法和一次乘法,你仍然有 999 "unpaired" 次乘法。
如果程序包含 1000 次加法(每次消耗 0.03% 的 CPU 时间)和一次乘法(本身消耗 10% 的 CPU 时间)那么对于 "best case" 你只能替换一次加法和一次乘法,你仍然有 999 "unpaired" 次加法。
如果你知道有相同数量的加法和乘法,并且所有的加法和乘法都可以配对并用"multiply and add"指令代替而不改变加载、存储或分支的数量;那么您不知道 fast/slow 一条 "multiply and add" 指令是如何(或者至少您没有提供该信息),因此仍然无法弄清楚它会如何影响性能。
换句话说,您已经获得了几乎 none 的寻找答案所需的信息。
这是程序中给出的一些指令的 table。第一列表示指令本身,第二列表示程序中任何指令的权重百分比,第三列表示任何给定指令的 CPI(每条指令的周期数)。
现在,我想用一条指令 madd 替换 add 和 mult。
madd takes three inputs, multiplies the first two inputs and add the result to the third input. This way madd instruction does both the multiplication and addition.
add 和 mult 的当前权重均为 40%。所以问题是,当我用 madd 替换 mult 和 add 时,新的权重是多少madd指令?
Current weight of both add and mult is 40%. So the question is when I replace the mult and add with madd what will be the weight of new madd instruction?
如果程序在一个地方包含加法(消耗 CPU 时间的 30%),而在另一个完全不同的地方包含乘法(消耗 CPU 时间的 10%)与添加无关;那么可能完全不可能用 "multiply and add" 指令替换任何东西。
如果程序由一个加法(本身消耗 30% 的 CPU 时间)和 1000 次乘法(每个消耗 0.01% 的 CPU 时间)组成,那么对于 "best case" 你只能替换一次加法和一次乘法,你仍然有 999 "unpaired" 次乘法。
如果程序包含 1000 次加法(每次消耗 0.03% 的 CPU 时间)和一次乘法(本身消耗 10% 的 CPU 时间)那么对于 "best case" 你只能替换一次加法和一次乘法,你仍然有 999 "unpaired" 次加法。
如果你知道有相同数量的加法和乘法,并且所有的加法和乘法都可以配对并用"multiply and add"指令代替而不改变加载、存储或分支的数量;那么您不知道 fast/slow 一条 "multiply and add" 指令是如何(或者至少您没有提供该信息),因此仍然无法弄清楚它会如何影响性能。
换句话说,您已经获得了几乎 none 的寻找答案所需的信息。