Home | About | Partners | Contact Us

SourceForge Logo

Quick Links
Home
News
Status
Building XL
XL Mailing List

Understanding XL
Conceptual overview
XL examples
Inside XL
Concept Programming

In depth
Browse GIT
Bugs
SourceForge Info
Contact

Other projects
GNU Project
The Mozart Project

XLR: Extensible Language and Runtime

The art of turning ideas into code

XL as a high-performance programming language

Prev: XL as a domain-specific language

Up

Next: XL as a scripting language

An interesting effect of semantic noise is that it often precludes useful optimizations, because the compiler has no precise idea of what is happening.

A classical example of this is the overuse of pointers in C or C++. Pointers are used in these languages to represent (among others):

  • Pointers to arbitrary addresses in memory
  • Aliases (alternate names) for existing variables
  • References to dynamically allocated memory
  • Arrays
  • Output parameters of functions
  • Callback functions
  • Abstract types (using pointers to undeclared struct types)
  • Objects

The compiler has in general very little information to determine what use is being made of a specific pointer. For safety, it needs to be very pessimistic and assume the worst. Consider the following simple piece of code:

int width, height; GetWindowExtent (window, &width, &height);

By reading the code, we all know that this reads the window size into width and height. But the compiler has to assume that GetWindowExtent does something nasty, like saving a copy of the pointers away in a global variable, just so that another evildoer function can modify them. Now, let's say that you follow the above code with a loop, like:

for (x = 0; x < width; x++) for (y = 0; y < height; y++) color[x][y] = ComputeColor(x, y, width, height);

You look at the assembly code, and even at highest optmiization levels, you see that the compiler insists on loading width and height from memory, rather than storing them in a register. Why? Simply because the compiler now assumes that the ComputeColor function is the evildoer we mentioned above. The address of width and height has been exposed by the call to GetWindowExtent, even if that was just a side effect and not the intent of that call.

Accesses to memory are very slow relative to register accesses in modern computers. So this is a significant mis-optimization. But it happens all the time in C.

The root cause of this is the semantic noise around pointers. In that particular case, the actual concept that should be used for getting width and height is the notion of output parameter. Many other forms of semantic noise can contribute to similar lost optimizations. Here are a few examples, where understanding why they impact performance negatively is left as an exercise to the reader (following the links should help, e-mail me if you need more help):

By eliminating as much semantic noise as possible, XL as a language allows the compiler to have a very precise understanding of what is happening. Language extensions can even be used to implement domain-specific optimizations.

Prev: XL as a domain-specific language

Up

Next: XL as a scripting language


Copyright 2008 Christophe de Dinechin (Blog)
E-mail: XL Mailing List (polluted by spam, unfortunately)