Posts Tagged ‘c++’

GCC Vs. LLVM – Simple Test Code Optimizations

As a companion piece to this test suite on Phoronix I took the following *very simple* code and ran it though GCC 4.6 (Fedora 15) and the Clang/LLVM 2.8 Suite to check performance and various optimizations being performed:

#include <stdio.h>
#include <stdlib.h>

int test_noRef(int value)
{
	return value + 1;
}

int test_ref(int &value){
	return value += 1;
}

int main(int argc, char *argv[]){

	int t = 1;

	for(int i = 0; i < 100000000; i++){
		//t = test_noRef(t);
		test_ref(t);
	}

	// final result = n loops + 1
	printf("%d\n", t);

}

Read More

C++ Performance – Counting Clocks

Performance computing can be an interesting task to undertake, as it lets us get under the hood of a complex abstraction (C++) and talk to the machine directly.

In the next two posts we’ll take a look at the Fibonacci algorithm used in a few other posts and see just how fast we can make it by looking at loop implementation, data type usage, and assembly code optimizations. In this first post we’ll take a look at some basic timing code, what gcc will do for us using the -O2 flag, then in the second post, see what we can do (if anything) to improve upon the generated code.

Read More

C++ 64-bit Inline Assembly Primer – Part 2

In this series we examine the relationship and implementations of C++ and raw assembly code. In this post we create our own add function in gcc extended assembly.

In the previous post we wrote a short C++ program that loaded two numbers. Despite its simplicity in C++, we saw how the assembly version was comprised of several dozen individual instructions in a rather cryptic format. Much of this complexity stems from the fact that in our sample program we called a function to perform our addition. Calling functions means dealing with a stack, base pointers, and the setup and maintenance of that stack. It means dealing with memory offsets, relative positions, and several other factors. The good news is that at this point we can safely ignore these details. In fact, we will do well to ignore them and focus on just the core competencies of function implementation code. In other words, we’ll let gcc create the function shells, calls, and stack management, we’ll focus on the core logic.

Read More

Porting to the Qt C++ Framework :: Part 4

Having created a shell of our app in step 2, porting the image cleaner code in step 3, we’re now at the stage where we can to port our command line XML cleaner code to Qt. At the end of this post we’ll have a fully functioning C++ Qt app.

Read More

Porting to the Qt C++ Framework :: Part 3

In this part of our series we’ll dive in and start implementing our logic from the command line application to the GUI version.

The goal during this step is to make exclusive use of the Qt frameworks built-in functions and methods for handling these tasks, as the end result must be a cross-platform compatible app.

We’re already getting a valid directory entry from part 2, so the first step in this part is to figure out how we iterate and query files from our base folder.

Read More

Posix Threads In C++

It’s sometimes hard to find a good example of working with threads in C++. Thus, in the course of implementing a very simple working example I decided it wouldn’t hurt to post what I came up with.

Read More