Re: IF NOTs
- From: rickman <gnuarm@xxxxxxxxx>
- Date: Sat, 20 Dec 2008 18:39:48 -0800 (PST)
On Dec 20, 4:26 pm, Elizabeth D Rather <erat...@xxxxxxxxx> wrote:
rickman wrote:
On Dec 18, 4:15 am, Reinhold Straub <demarc...@xxxxxx> wrote:
On 18 Dez., 02:48, "Ed" <nos...@xxxxxxxxxxx> wrote:
No, only for performance tuning on some processors. Compare:So they would be logically different? Used for different purposes?There may once have been. Today, however, an optimizing compiler willNOT IF and NIF could provide different branch prediction hints to the
optimize NOT IF cases anyway. So all one saves is some typing.
compiler.
: a IF x ELSE y THEN ;
: b NIF y ELSE x THEN ;
This is logically equivalent, but on processors with static branch
prediction, usually "TRUE a" will be faster than "TRUE b" and "FALSE
a" will will slower than "FALSE a".
Can you explain this statement? It would seem to me that the "TRUE a"
case (executing x) would be slower than the "TRUE b" case (also
executing x). The "TRUE a" case has to execute two jumps, the first
one being conditional and the second at the "ELSE". The "TRUE b"
example only has a single, conditional jump instruction. The
manipulation of the flag depends on the details of the instruction set
of the processor used. Some are capable of branching on zero or not
zero as needed. Others have fewer condition options and would require
manipulation of the flag before the conditional instruction.
No, the code for IF (the "TRUE a" case) performs the test, but only
branches on zero (FALSE). The TRUE case falls through into the TRUE
code, but then branches at the ELSE (which is why it's nice that ELSE is
optional).
Yes, it only take the branch on a FALSE, but the instruction is
executed regardless. The TRUE case always has to take a branch at the
end if there is an else case, so the TRUE case is slower. Both have a
branch, but the TRUE case runs the same code the FALSE case does, plus
the branch at the end. So the TRUE case is slower than the FALSE
given that a FALSE exists.
Rick
.
- Follow-Ups:
- Re: IF NOTs
- From: Jonah Thomas
- Re: IF NOTs
- References:
- IF NOTs
- From: anders . koburg
- Re: IF NOTs
- From: Ed
- Re: IF NOTs
- From: Reinhold Straub
- Re: IF NOTs
- From: Ed
- Re: IF NOTs
- From: Reinhold Straub
- Re: IF NOTs
- From: rickman
- Re: IF NOTs
- From: Elizabeth D Rather
- IF NOTs
- Prev by Date: Re: INTELLASYS - What is Going On!?
- Next by Date: Re: Dual XTs (compilation tokens) and DOES>
- Previous by thread: Re: IF NOTs
- Next by thread: Re: IF NOTs
- Index(es):
Relevant Pages
|
Loading