aliasing 
Author Message
 aliasing

Quote:

>I recently read that pointers can cause aliasing and prevent optimization by the
>compiler.  I don't understanding what aliasing is.  I'd appreciate if someone can
>explain it to me.

'Aliasing' is the computer science version of the philosopher's age-old
question 'is the morning star the same as the evening star?'  Of course,
modern astronomy says 'yes, they are both Venus'.  Shakespeare also put
it well: 'a rose by any other name would smell as sweet'.

Aliasing is tightly coupled with the 'problem of _identity_ in object-
oriented languages'.  A good operational description of 'identity' is
found by making changes to an object by means of one description, and
seeing whether the object referenced by the other description also
changes.  If yes, the objects are identical; if no, the objects are
not identical.

Pointers in C are excellent ways to achieve aliasing.  In this
context, they are _good_, because they are the semantics you want.
However, aliasing interferes with _caching_, which is a making of a
_copy_ of an object in a more convenient and efficient place (instead
of _moving_ the object to the more convenient place, but still keeping
only the one copy).  Thus, the semantics could be affected if someone
changes the original object, which will not be reflected in the cached
_copy_.

A particularly convenient and efficient place for an object is a
machine _register_, and compilers attempt to cache objects there as
much as possible.  Aliasing interferes with the compiler's ability to
cache values in this manner, and may thus slow down a potential
program.

One of the major reasons for incorporating hardware caches on modern
architectures is to properly and efficiently handle _aliasing_ of
values which the compiler is not able to cache in registers itself.

I wouldn't worry very much about trying to avoid aliasing to help the
compiler, unless you are doing something totally egregious.  (You are
in good company, because most C programs _alias_ things like crazy.)
Hardware caches are getting better and better, so the performance hit
for an object in the cache relative to one in a register isn't that
bad for most applications.



Thu, 31 Oct 1996 10:22:12 GMT  
 aliasing
I recently read that pointers can cause aliasing and prevent optimization by the
compiler.  I don't understanding what aliasing is.  I'd appreciate if someone can
explain it to me.

David



Thu, 31 Oct 1996 07:18:53 GMT  
 aliasing

Quote:

> I wouldn't worry very much about trying to avoid aliasing to help the
> compiler, unless you are doing something totally egregious.  (You are
> in good company, because most C programs _alias_ things like crazy.)
> Hardware caches are getting better and better, so the performance hit
> for an object in the cache relative to one in a register isn't that
> bad for most applications.

I wouldn't worry about it either, but for a more basic reason: avoiding
aliasing will not help most compilers one bit.  It is not the presence
of actual aliasing which causes the problem, but the mere possibility
that it might occur.  For example, if a function has two pointer
arguments it may be possible to produce better code if you know that
they point to different objects.  But the compiler has no way to know
this, so must assume the worst.  Whether or not you actually pass it
two pointers to the same thing is irrelevant.  To truly help most
compilers you would almost have to avoid pointers entirely.

(There are ways that a smart compiler could do better.  For example, it
could compile two versions of the function, one of which would be used
only for calls where it can be determined that there is no aliasing. But
I think this sort of thing is mostly beyond the state of the practice,
if not the art.)

- Roger Miller
  VeriFone, Inc.



Mon, 04 Nov 1996 07:36:45 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Aliasing through union, C++ vs. C

2. ANSI aliasing rules

3. Aliasing question...

4. Aliasing in ANSI C

5. Aliasing and character types

6. Sequence Points, Aliasing & Optimisation

7. difference between punning and aliasing

8. aliasing single quotes in macros

9. aliasing quotes in macros?

10. difference between punning and aliasing

11. aliasing

12. anti aliasing filter source

 

 
Powered by phpBB® Forum Software