Archive

Archive for the ‘programming’ Category

Compiler optimization

January 13, 2010 2 comments

I saw this a while back, but i still think that this is an impressive example of what modern compilers can do. Say, when writing C code you have the need to rotate bits. There is no rotate operator in C so the bit rotation has to be implemented like this:

$ cat rotate.c
unsigned long rotate_left(unsigned long a, unsigned int shift)
{
return a << shift | a >> (sizeof(a) * 8 - shift);
}
unsigned long rotate_right(unsigned long a, unsigned int shift)
{
return a >> shift | a << (sizeof(a) * 8 - shift);
}

Now compile it with gcc (version 4.4.1 here, but most other versions should do the same):

$ gcc -c -O rotate.c

The compiler knows that the C code only rotates the bits and that this can be done with the x86 rol and ror instructions:

$ objdump -d rotate.o

rotate.o: file format elf32-i386

Disassembly of section .text:

00000000 :
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 4d 0c mov 0xc(%ebp),%ecx
6: 8b 45 08 mov 0x8(%ebp),%eax
9: d3 c0 rol %cl,%eax
b: 5d pop %ebp
c: c3 ret

0000000d :
d: 55 push %ebp
e: 89 e5 mov %esp,%ebp
10: 8b 4d 0c mov 0xc(%ebp),%ecx
13: 8b 45 08 mov 0x8(%ebp),%eax
16: d3 c8 ror %cl,%eax
18: 5d pop %ebp
19: c3 ret

This means that it is usually the best thing to write readable C code and let the compiler optimize things. Modern compilers can be pretty good at this.

Advertisements
Categories: programming Tags: ,

Diplomarbeit / diploma thesis

August 25, 2009 Leave a comment

This happened a while ago, but in case somebody is interested, here is the public version of my diploma thesis. It is written in German language with the title “Erweiterung einer standardisierten Software-Komponente zur effizienten Ansteuerung gro├čer Tape-Libraries” (Extending a standardized software component for efficient control of large Tape Libraries). As part of this work, i analyzed different interfaces to tape libraries and evaluated how to integrate them with IEEE 1244 based media management systems.

The thesis was written with using the LaTeX typesetting system, i can provide the source files upon request.