Aliasing (computing)


Aliasing (computing)

In computing, aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program. Thus, modifying the data through one name implicitly modifies the values associated to all aliased names, which may not be expected by the programmer. As a result, aliasing makes it particularly difficult to understand, analyze and optimize programs. Aliasing analyses intend to compute useful information for understanding aliasing in programs.

Examples

Array bounds checking

For example, the C programming language does not perform array bounds checking. One can then exploit the implementation of the programming language by the compiler, plus the computer architecture's assembly language conventions, to achieve aliasing effects.

If an array is created on the stack, with a variable laid out in memory directly beside that array, one could index outside that array and then directly change that variable by changing the relevant array element. For example, if we have an int array of size ten (for this example's sake, calling it vector), next to another int variable (call it i), vector [10] would be aliased to i if they are adjacent in memory.

This is possible in some implementations of C because an array is in reality a pointer to some location in memory, and array elements are merely offsets off that memory location. Since C has no bounds checking, indexing and addressing outside of the array is possible. Note that the aforementioned aliasing behaviour is implementation specific. Some implementations may leave space between arrays and variables on the stack, for instance, to minimize possible aliasing effects. C programming language specifications do not specify how data is to be laid out in memory (ISO/IEC 9899:1999, section 6.2.6.1).

It is not erroneous for a compiler to omit aliasing effects for accesses that fall outside the bounds of an array, as having a pointer even pointing out of range invokes undefined behavior.

Aliased pointers

Another variety of aliasing can occur in any language that can refer to one location in memory with more than one name (for example, with pointers). See the C example of the xor swap algorithm that is a function; it assumes the two pointers passed to it are distinct, but if they are in fact equal (or aliases of each other), the function fails. This is a common problem with functions that accept pointer arguments, and their tolerance (or the lack thereof) for aliasing must be carefully documented, particularly for functions that perform complex manipulations on memory areas passed to them.

Specified aliasing

Controlled aliasing behaviour may be desirable in some cases (that is, aliasing behaviour that is specified, unlike that relevant to memory layout in C). It is common practice in Fortran. The Perl programming language specifies, in some constructs, aliasing behaviour, such as in foreach loops. This allows certain data structures to be modified directly with less code. For example,

my @array = (1, 2, 3); foreach my $element (@array) { # Increment $element, thus automatically # modifying @array, since $element is "aliased" # to each of @array's elements in turn. $element++; } print "@array ";

will print out "2 3 4" as a result. If one wanted to bypass aliasing effects, one could copy the contents of the index variable into another and change the copy.

Conflicts with optimization

Many times optimizers have to make conservative assumptions about variables in the presence of pointers. For example, a constant propagation process which knows that the value of variable x is 5 would not be able to keep using this information after an assignment to another variable (for example, *y = 10) because it could be that *y is an alias of x. This could be the case after an assignment like y = &x.

As an effect of the assignment to *y, the value of x would be changed as well, so propagating the information that x is 5 to the statements following *y = 10 would be potentially wrong (if *y is indeed an alias of x). However, if we have information about pointers, the constant propagation process could make a query like: can x be an alias of *y? Then, if the answer is no, x = 5 can be propagated safely.

Another optimization that is impacted by aliasing is code reordering; if the compiler decides that x is not an alias of *y, then code that uses or changes the value of x can be moved before the assignment *y = 10, if this would improve scheduling or enable more loop optimizations to be carried out.

In order to enable such optimizations to be carried out in a predictable manner, the ISO standard for the C programming language (including its newer C99 edition) specifies that it is illegal (with some exceptions) for pointers of different types to reference the same memory location. This rule, known as "strict aliasing", allows impressive increases in performance Fact|date=February 2008, but has been known to break some otherwise valid code. Several software projects intentionally violate this portion of the C99 standard. For example, Python does so in order to implement reference counting [ cite web | url=http://mail.python.org/pipermail/python-dev/2003-July/036898.html |author=Neil Schemenauer |date=2003-07-17 |title=ANSI strict aliasing and Python] . and the Linux kernel does so because it causes problems with optimization of inlined code [ cite web | url=http://lkml.org/lkml/2003/2/26/158 |author=Linus Torvalds |date=2003-02-26 |title=Re: Invalid compilation without -fno-strict-aliasing] . In such cases, when compiled with gcc, the option -fno-strict-aliasing is invoked in order to prevent unwanted or invalid optimizations that could produce incorrect code.

External links

* [http://www.cellperformance.com/mike_acton/2006/06/understanding_strict_aliasing.html Understanding Strict Aliasing] - Mike Acton
* [http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html Aliasing, pointer casts and gcc 3.3] - Informational article on NetBSD mailing list

ee also

* See aliasing for uses of the word when applied to signal processing, including computer graphics.

Notes


Wikimedia Foundation. 2010.

Look at other dictionaries:

  • Aliasing — This article applies to signal processing, including computer graphics. For uses in computer programming, please refer to aliasing (computing). In statistics, signal processing, computer graphics and related disciplines, aliasing refers to an… …   Wikipedia

  • aliasing — alias ► ADVERB ▪ also known as. ► NOUN 1) a false identity. 2) Computing an identifying label used to access a file, command, or address. DERIVATIVES aliasing noun. ORIGIN Latin, at another time, otherwise …   English terms dictionary

  • aliasing — noun 1》 Physics & Telecommunications the misidentification of a signal frequency. 2》 Computing the use of aliases to designate files, commands, etc. 3》 Computing the distortion of a reproduced image so that curved or inclined lines appear… …   English new terms dictionary

  • Spatial anti-aliasing — In digital signal processing, spatial anti aliasing is the technique of minimizing the distortion artifacts known as aliasing when representing a high resolution image at a lower resolution. Anti aliasing is used in digital photography, computer… …   Wikipedia

  • Anti-aliasing — In digital signal processing, anti aliasing is the technique of minimizing the distortion artifacts known as aliasing when representing a high resolution signal at a lower resolution. Anti aliasing is used in digital photography, computer… …   Wikipedia

  • List of computing and IT abbreviations — This is a list of computing and IT acronyms and abbreviations. Contents: 0–9 A B C D E F G H I J K L M N O P Q R S T U V W X Y …   Wikipedia

  • Palette (computing) — Color depth 1 bit monochrome 8 bit grayscale 8 bit color 15/16 bit color (High color) 24 bit color (True color) 30/36/48 bit color (Deep color) Related Indexed color Palette RGB color model Web safe color This box …   Wikipedia

  • OpenHMPP — HMPP for Hybrid Multicore Parallel Programming. Based on a set of directives, OpenHMPP Standard is a programming model designed to handle hardware accelerators without the complexity associated with GPU programming. This approach based on… …   Wikipedia

  • Alias — An alias is a pseudonym and may also refer to:In family names: *An additional component of a surname to distinguish its users from other families of the same surname. So whereas an alias is used nowadays to hide someone s identity, an alias was… …   Wikipedia

  • Автоматическое распараллеливание — Автоматическое распараллеливание  оптимизация программы компилятором, состоящая в автоматическом ее преобразовании в форму, работающую на параллельном компьютере, например, на SMP или NUMA машине. Целью автоматизации распараллеливания… …   Википедия


Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”

We are using cookies for the best presentation of our site. Continuing to use this site, you agree with this.