Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!amdahl!apple!baum From: baum@Apple.COM (Allen J. Baum) Newsgroups: comp.arch Subject: Re: Branch Delay Annullment Message-ID: <12300@apple.Apple.COM> Date: 16 Jun 88 19:25:04 GMT References: <22065@amdcad.AMD.COM> <12211@apple.Apple.COM> <27527@pyramid.pyramid.com> Reply-To: baum@apple.UUCP (Allen Baum) Organization: Apple Computer, Inc. Lines: 46 [] >In article<27527@pyramid.pyramid.com>markhall@pyramid.UUCP (Mark Hall) writes: >In article <12211@apple.Apple.COM> baum@apple.UUCP (Allen Baum) writes: >> >>In the looping case, obviously squash-on-non-taken works. However, in the >>standard if-then-else case (which can occur inside a loop remember, so it >>can occur even more frequently than loop-closers dynamically) just the > ^^^^^^^^ >>opposite is true. > ^^^^^^^^^^^^^^^^ > >....But doesn't ``squash-on-taken'' also mean we annul when branching >around a simple IF statement (with no ELSE part)? Do you feel >that it is unexpected to branch around such IF's? You don't really >say so in your posting, and I am just curious. Given the number of >such IF-THENs I see in code that do fatal error checking >(like malloc returning NULL), I think there would be a LOT of >dynamic annulment for squash-on-taken. > Oops. Its been so long since I've looked at this that I forgot about a second part of the argument. You're absolutely right that there is a lot of code of the form: If (error-condition( {handle it}; and that this code is executed infrequently. If this is the case, it would pay to have this code be executed out of line; that is, you would like to branch to it, and then branch back to the main line code. The most frequently executed code is then straight-line, a real win in situtations where you benefit from bust mode i-fetches. This costs nothing in the frequent case, possibly saving some cache misses, while costing cache misses, and an extra cycle, in the infrequent case. This assumes that your compiler can predict the probability of branching. The best I've seen is about ~80%+- with static branch prediction. >Anyone have any simulations or traces showing whether it is more >common for branches to be taken or not taken? Is it very lopsided >one way or the other, or is it about even? How about stats on >the number of IF-THENs in source code as opposed to IF-THEN-ELSEs? I do not have any other good numbers besides these observations. Most numbers that I've seen suggest that branches are taken roughly 50% (maybe as high as 60% for some code. Often it is unclear whether these figures include unconditional branches or not- sometimes they do, and sometimes not. I don't recall seeing any numbers at all on branching that separates forwards and backwards branching. If there is some advantage one way or the other, the compiler code rearrange the code to favor one or the other, which would skew the statistics in any case. The IF-THEN vs. IF-THEN-ELSE numbers I have are static, and from too small a sample. -- {decwrl,hplabs,ihnp4}!nsc!apple!baum (408)973-3385