简体   繁体   English

预测分支

[英]Predicting branches

Assume that a processor has a feature that enables the compilier to specify the initial prediction state as either LT or LNT for a branch instruction. 假定处理器具有使编译器将初始预测状态指定为分支指令的LT或LNT的功能。 Consider a statement of the form 考虑以下形式的声明

IF A > B THEN A = A + 1 ELSE B = B + 1 如果A> B那么A = A + 1 ELSE B = B + 1

(a) Generate assembly-language code for the statement above. (a)为上述语句生成汇编语言代码。

(b) In the absence of any other information, discuss how the compiler should specify the initial prediction state for the branch instructions in the assembly code. (b)在没有其他信息的情况下,讨论编译器应如何在汇编代码中为分支指令指定初始预测状态。

(c) A study of the execution behavior of the program containing the above statement reveals that the value of variable A is often larger than the value of variable B. If this information is made available to the compiler, discuss how it would influence the initial prediction state for the branch instructions. (c)对包含上述语句的程序的执行行为的研究表明,变量A的值通常大于变量B的值。如果此信息可供编译器使用,请讨论它如何影响初始值。分支指令的预测状态。

I think I have part a and b. 我想我有a和b部分。 For part a, wouldn't this be something like: 对于a部分,不是这样的:

Assume R0 contains the value in A and R1 contains the value in B. 假设R0包含A中的值,R1包含B中的值。

       Branch_if_R0>R1   LOOP            //Compares A and B
       Add               R1, R1, #1      //A>B is false so B=B+1
LOOP   Add               R0, R0, #1      //A>B is true so A=A+1

As for part b, since the loop conditional is at the beginning of the loop, wouldn't this be LNT? 至于b部分,由于循环条件在循环的开始,所以这不是LNT吗? And for part c, if we knot that A is often greater then B, wouldn't this then be LT? 对于c部分,如果我们知道A通常大于B,那么这不是LT吗?

Your code have bug. 您的代码有错误。

 IF A > B THEN A = A + 1 ELSE B = B + 1

to assembly language 汇编语言

       cmp               R0, R1
       jg                LOOP             //Compares A and B
       Add               R1, R1, #1      //A>B is false so B=B+1
       jmp               LOOP1
LOOP:  Add               R0, R0, #1      //A>B is true so A=A+1
LOOP1:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM