计算机组成原理一道习题的一个错误解法

题目

题目来自计算机组成与系统结构(第2版)第一章课后习题第6题。

题目的描述是:
若机器M1和M2具有相同的指令集,其时钟频率分别为\(1GHz\)\(1.5GHz\)。在指令集中有五种不同类型的指令A~E。下表给出了在M1和M2上每类指令的平均时钟周期数CPI。
机器

机器一个普通标题BCDE
M112234
M222456

请回答下列问题:
(1)M1和M2的峰值MIPS各是多少?
(2)假定某程序P的指令序列中,五类指令具有完全相同的指令条数,则程序P在M1和M2上运行时,
哪台机器更快?快多少?在M1和M2上执行程序P时的平均时钟周期数CPI各是多少?
本文我们将讨论一位同学在做第(2)问中的一个步骤。
有位同学的回到是:

对于第(2)问
\(\frac{1}{5}\times(1000+\frac{1000}{2}+\frac{1000}{2}+\frac{1000}{4}+\frac{1000}{3})\) = 516.7MIPS
第二个同理,然后比较他们的MIPS。

这里看似正确,但是其实是错误。在计算MIPS的时候,他的做法是计算出单独执行每个指令的MIPS然后取期望。
似乎是对的,但是题目的要求是每个指令的条数是一样的,但在你的计算中相当于把CPU的频率平分给每个指令,
求他们的MIPS,所以这是不正确的,因为CPI少的指令,在指令条数都是一样的情况下,它所分到的CPU应该会少一些。举个极端例子,
假设A的CPI为1,
而其他几个CPI都是无穷大,按照你的算法,算出来应该是后面几项全部为0,最后结果为1000/5=200MIPS.显然这是不正确的,
因为最后的结果应该是趋近于0的。

实际应该这样算:按照他们的CPI来划分CPU的时间,再计算他们各自的"时间内的MIPS".按M1来说CPU 1秒中的时间内执行A指令的时间只占其中的\(\frac{1}{12}\),其他类推,所以\(MIPS_{M1}=(\frac{1000\times\frac{1}{12}}{1}+\frac{1000\times\frac{2}{12}}{2}+\frac{1000\times\frac{2}{12}}{2}+\frac{1000\times\frac{4}{12}}{4}+\frac{1000\times\frac{3}{12}}{3})\)=416.7MIPS
对于M2也是同样的计算。
当然也可以计算M1和M2各自的平均CPI再计算MIPS,即:
\(CPI_{M1} = \frac{(1+2+2+4+3)}{5}=2.4\)
\(MIPS_{M1}=\frac{1000}{2.4}=416.7MIPS\)
与上式计算结果一致。

转载于:https://www.cnblogs.com/dshale/p/10513873.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package com.hexiang.utils; import java.awt.Component; import javax.swing.JOptionPane; /** * This class ExceptionManager and its subclasses are a form of * Exception. It is used to wrap all the Throwable instances * and handle them in a unified way. It will show the information which consists of * StackTraces and Messages by using JOptionPanel. * * @author Estelle * @version 1.0 * @see java.lang.Exception * @since jdk 1.5 */ public class ExceptionManager extends RuntimeException { private static final long serialVersionUID = -6963187366089365790L; /** * This field alerter is used to show the information the Class offered. * * @see javax.swing.JOptionPane */ private JOptionPane alerter; /** * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(String msg). * * @param msg The message will pass the specified constructor * @return An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(String msg). */ public static ExceptionManager wrap(String msg){ return new ExceptionManager(msg); } /** * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(Throwable throwable). * * @param throwable The cause will pass the specified constructor * @return An instance of the ExceptionManager created by invoking the constructor * ExceptionManager(Throwable throwable). */ public static ExceptionManager wrap(Throwable throwable){ return new ExceptionManager(throwable); } /** * This static method create an instance of the ExceptionManager by invoking the * constructor ExceptionManager(String msg,Throwable throwable). * * @param msg The message will pass the specified constructor * @param throwable The cause will pass the specified c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值