Author: Dieter Buerssner
Date: 10:31:29 07/29/03
Go up one level in this thread
On July 29, 2003 at 01:54:29, Gerd Isenberg wrote:
>On July 28, 2003 at 19:00:41, Dieter Buerssner wrote:
>i see your point - i have no problems with references, may be due to Java.
>References are very intuitive for me, but i don't use them "randomly" in
>functions.
>Most often the "output" paramter by reference is the first (left) one - and i
>use appropriate function identifiers, implying the desired side effect.
>
>  int bitScanAndReset(BitBoard &bb);
>  void assignWithMask(int &target, int source, int mask);
I would probably use
  int assignWithMask(int source, int mask);
which also has the advantage, that it can be used in nested function calls.
>>It may even be a performance issue. I read your suggestion about the small
>>inline functions vs. macros. I basically agree. But when using reference
>>paramaters (your example did), things might be very different. This might make
>>it very difficult or even impossible to make a good optimization for the
>>compiler.
>
>I never found a problem so far. I guess from compilers point of view, there is
>no pragmatical difference between a pointer and a reference.
I remember at least one case, where the macro was faster, than a function call
with a pointer parameter (actually, most probably the function had 2 outputs at
least). I don't have the case handy, but looking over my macros, I might find it
again. Perhaps the following rather constructed example can show the point:
extern unsigned or_tbl[], and_tbl[]; /* non const */
void foo(unsigned *ap, unsigned idx)
{
  /* Of course, one could write it in one line */
  *ap &= and_tbl[idx];
  *ap |= or_tbl[idx];
}
Now, the compiler must write back to *ap after the &=, before he can do the |=.
Because ap could be &or_tbl[idx]. In an inlining situation, it could probably
figure out, that there is no such alliasing, but it may show, that the work for
the optimizer can be more tricky already in such a simple case, when pointers
are involved. One may be able to construct a better example, where it gets
principially impossible for the compiler to figure it out.
BTW. The above example also shows, that a compiler can do more optimization when
writing the above 2 lines as one line. Looks so similar, but it is different.
Regards,
Dieter
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.