Tuesday, May 05, 2009

A benchmark where clang wins gcc

I have sent my last post about clang to a friend, suggesting that the final days of gcc could be coming, and he refuted with a very pragmatic point: "talk is cheap, show me the (generated) code". :-P So I decided to get serious.

I have already told in the article that clang is in development stage, so how could I show him a working example ? I know clang able to compile large projects, like gcc and FreeBSD. After playing with some small projects, I found this one, from the Computer Language Benchmarks Game. The benchmark is called fasta, and it generates pseudo random DNA sequences. I chose this one because it was small and, even though floating point was used in the program, outputs could be directly compared without rounding errors (becuase they're composed of DNA elements).

My system: My machine is a HP Pavilion dv9000, Core 2 Duo T5500 1.66 GHz, 2GB RAM, with Ubuntu 9.04.

The compilers: the old guy is gcc 4.3.3 from the standard Ubuntu package. The new guy is clang, downloaded today from svn (llvm rev 71035/clang rev 71041). llvm and clang were compiled with "--prefix=/opt/clang --enable-optimized".

The execution: I've just used GNU time repeatedly until the execution time converged, chose a result at random and rounded it to one decimal figure. Remember that I just have to convince a friend. :-P Standard output was redirected to /dev/null.

At first I did this:
$ gcc -O3 -o b b.c
$ /opt/clang/bin/clang -O3 -o bb b.c
$ time ./b 25000000 > /dev/null
$ time ./bb 25000000 > /dev/null


But this gave incredible 11.1s for gcc and 7.4s for clang. It was a good surprise to see clang surpassing gcc, but there was something wrong, since gcc is not a bad compiler. A quick look in assembly output showed that clang was using SSE registers for moving data around and for calculating, while gcc was not. This is a good point for the clang driver, but it doesn't tell us anything. So, the correct command line for gcc is:

$ gcc -O3 -march=native -mmmx -msse -msse2 -msse3 -mfpmath=sse -o b b.c

Then we finally settle with the results: 7.7s for gcc and 7.4s for clang. Clang wins !

Friday, April 17, 2009

clang compiler quickstart

Have you ever heard about clang ? It's a new compiler for C, C++ and Objective C languages. clang is being developed in a fast pace and is expected to become an alternative for the gcc compilers.

What are its advantages ? It's a compiler written from scratch, its code is completely modular and easily readable, it aims to offer user-friendly expressive diagnostics, it's much smaller and faster than gcc, it's expected to support IDE integration and code analysis and it's compatible with gcc. The C part of the compiler is in an advanced stage and can build large projects, like sqlite and the FreeBSD kernel. The C++ part is in an early stage (clang can't compile itself, for example).

Quick start:

$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
$ cd llvm/tools
$ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
$ cd ..
$ ./configure --prefix=/opt/clang
$ make
$ sudo make install

In the sequence above, llvm is the compiler back end and clang is the compiler front end. The compiler is installed in the /opt/clang directory, so it's available at /opt/clang/bin/clang (the directory can be deleted for a full uninstall when you're done).

Try it out:

$ cat hello.c
#include "stdio.h"

int main (void) {
printf("Hello world!\n");
return 0;
}
$ /opt/clang/bin/clang -o hello hello.c
$ ./hello
Hello world!
$ tar xf lame-398-2.tar.gz
$ cd lame-398-2
$ ./configure --prefix=/opt/lame CC=/opt/clang/bin/clang
$ make
$ sudo make install
$ /opt/lame/bin/lame myaudio.wav

As you can see, clang is in development stage, so it's only available trough svn.

Do you want to contribute ? See more information at clang home page !


Wednesday, April 01, 2009

POSIX 2008

The POSIX standard has been updated in December 2008. The standard is an attempt to standardize the core API of all Unix systems and, nowadays, most Unix clones try to adhere to the standard in some level of conformance (including GNU and BSD based systems). Register and read the new standard in the Open Group UNIX System site.

Tuesday, January 13, 2009

The best job in the world

Australian's Queensland Tourism is seeking applicants for what they call the best job in the world. Are you interested in a 6 month contract and AUD$ 150.000,00 (US$ 100.950,00) for diving, feeding turtles and blogging, while living in paradise ? Then apply for the island caretaker job in Hamilton Island. See the pdf in the site Island Reef Job for details.

Tuesday, December 30, 2008

Android is updated and goes unnoticed

This December Android source code received a significant update, but apparently it went completelly unnoticed. The git repository of most components were updated to be compatible with the new Android kernel, based on linux 2.6.27 (previously 2.6.25). Most components have merged a repository called "cupcake", with lots of changes that have now become official. Also, external libraries were updated too. I think we should expect a new minor release of the SDK in a few weeks too. Remember to run a "repo sync" to keep your source code up-to-date (this one will take a lot of time).

This is great news for me, since I was not being able to port Palm TX to Android. I needed version 2.6.27 because it's the first version with official support for Palm TX. I was getting segfaults when executing one of the core applications in Android (servicemanager) in that version. Now I believe the port will work flawlessly. :-D

Thursday, December 11, 2008

Meet Python 3.0

Python 3.0 was released this December ! Check out What's New in Pyhton 3.0, the full documentation and the conversion tool 2to3.

Tuesday, October 28, 2008

Palm TX support added in the main kernel

On October 9, Linux kernel 2.6.27 was released with support for the Palm TX handhelds. That was a merge from the hackndev kernels, which have had experimental support for many PDAs for a long time. Also, I have noticed that general support for PXA2xx/PXA3xx microcontrollers are much more mature than it was one year ealier.

Congratulations for the achievement !

Thursday, October 23, 2008

Google Android source code released

On October 21, Google officially released Android full source code under the Apache license. Quoting the official site:

"Android is the first free, open source, and fully customizable mobile platform. Android offers a full stack: an operating system, middleware, and key mobile applications. It also contains a rich set of APIs that allows third-party developers to develop great applications."

That's right ! An official, supported, open source distribution for cell phones. :-) Congratulations to everyone who has made this possible !

Thursday, August 07, 2008

Concept Idea - Webkit for Firefox ! (Mozilla Labs)

This is my contribution for Mozilla Labs concepts. PLEASE, SWITCH TO WEBKIT !

Why develop two HTML engines that are supposed to do exactly the same thing, when you could join forces and develop only one ? The user doesn't have access to the engine, it's the "user experience" that matters !

Dump Gecko !

Development in Webkit is much faster ! In less than four months (beginning in January, 2008) Webkit got around 50 points in Acid3, while there are no plans for Gecko to support it yet.

Webkit is faster, smaller, portable !

It's been proven that Webkit has low overhead ! Consider the actual list of architectures that support it:
  • Safari on Mac
  • iPhone's Safari Browser
  • Epiphany on Gnome (gtk+ port)
  • Integrated to Qt (Qt 4.4)
  • Browser for Google Android phones
  • Nokia S60 phone
  • (planned) Konqueror on KDE 4.1
  • etc !
On the other hand, as of August 2008, nobody really considers using Gecko in embedded systems (the only exception is the OLPC project, which is rather a downscaled Linux/x86 standard architecture).

Dump the legacy !

Even though supporting buggy websites is still important these days, the slow development of Gecko, compared to Webkit, hints to us how bad supporting legacy code can be to maintenance. Let's switch the development models. We can't wait a full year to support Acid3 and other standards when we can wait just four months !

It's free software !

Why duplicating efforts when everything is free source ? Just build the shell above a single great engine that gets the job done. You can do it, because it's free software !

(for a more critic opinion of the same problem, see the post from October 2007 in the Peer Pressure blog)

Saturday, July 26, 2008

Yet another website that refuses to support linux

Terra Networks is a large internet content provider and ISP company (currently owned by Spanish Telefónica). In Brazil it started as a nice ISP for dialup Internet (I had an account there for a few years) and then moved to the "web portal" business. Apparently, however, it doesn't care about linux users. Even if you don't know Portuguese you will understand what's being said in the picture (I believe there is a static link to the page also). Digg if you think Terra Networks should do something about that.

Thursday, March 27, 2008

Webkit and Presto on Acid !

Links to the first screenshots of Webkit and Presto scoring 100 points in the Acid3 test. After correcting small glitches (and Presto being temporarily downgraded to 99 points), both rendering engines will pass the test completely. The amazing part is that both teams were able to fix more than 40 tests in a couple of months. Surely, both rendering engines were designed for the future.

Congratulations !

Tuesday, May 01, 2007

Kiel oni skribas ... ? Typing Esperanto characters in Ubuntu

[update 20081102: Finally, almost three years after the bug report, Ubuntu 8.10 Intrepid Ibex has full, built-in support for Esperanto letters. This post may be considered out-of-date now. Congratulations for the gtk+ team !]

Gtk+ (and thus Ubuntu) multilingualism environment is not as good as it could be. Imagine that you can write in some exotic language. Now try to write a blog in such language using firefox in Ubuntu. You'll hit a wall and that's it.

For the impatient: add the line:

GTK_IM_MODULE=xim

In your /etc/environment file and reboot. [update 20080317: gtk will be fixed so that this is not necessary anymore, see gnome bug 321896] For the patient: read on.

Interestingly, a set of small bugs, still present in Feisty Fawn, makes me unable to write in Esperanto, an interesting constructed European language (that I learn just for fun), that uses the following special characters: ĉ, ĝ, ĥ, ĵ, ŝ and ŭ. The first, and most basic problem is the following: gtk+ could allow, with zero configuration, anybody write such characters (on a typical international keyboard). Qt based and Xlib based application allow this. If I used Kubuntu I wouldn't be writing this post, because Esperanto characters would work out of the box !

You may try this out in your Ubuntu or gnome based distribution: in firefox and gedit, type ^ + a, ^ + e (using an international keyboard). You'll have the â and ê characters. Now type ^ + c, ^ + h. Firefox and gedit will beep and won't show neither ĉ nor ĥ. Now open xterm and type ^ + a, ^ + e, ^ + c, ^ + h. You'll have âêĉĥ.

In X-Windows, complex character typing is handled by modules called input methods. X has a default API for handling input methods, called XIM. That's what xterm uses. Gtk+ provides it's own API and set of input methods for gtk+ based applications. Gtk+ input methods don't provide Esperanto characters. Why ? Simply because gtk+ developers don't want to. I have filed this bug more than one year ago. Also, I could find a similar bug in gnome database that is 4,5 years ago. Now, in your Ubuntu, install some Qt/KDE application and type âêĉĥ. Easy, ain't it ?

Fortunatelly, one of the input methods from the gtk+ set is to use the fallback XIM input method. It's the input method that says "I was unable to do what I was supposed to, so I'll let you use the standard, simpler input method because it works". In gedit, right-click in the text area, select the menu "input methods", then "X input method". Now type âêĉĥ. Voilà ! Firefox doesn't have this menu, however :'(. How one could make the X input method the default method, so that all applications work and I don't have to select it from a menu ? Here we go to our second multilingualization bug. There's no way, in gnome or gtk, to set our default input method. That's right. No way. Ni feliĉe batu en la muron, denove !

The solution is to edit by hand the configuration file given above, /etc/environment (or in your personal enviroments file, ~/.bashrc, or maybe in some other place, depending on your system). In the next boot, when applications load the new environment, XIM will take control. Finally, we have a multilingual environment for Ubuntu... but wait !

Firefox still doesn't work. Why is that ? Here we have a Ubuntu specific bug. More specifically: a 64-bit Ubuntu bug. Almost all the applications I use are compiled for 64-bit. Firefox (and a few others) is an exception. I need to browse sites that use Java and Flash software. Java has just become free software. Flash is closed source software. Neither of them offer 64-bit support for firefox. So my firefox must be 32 bits (see Ubuntu forums if you'd like to know more about this). There are a few support packages that I have to install in order to support 32 bit applications, like "ia32-libs", "ia32-libs-gtk", etc. Those applications don't correctly install the 32 bit environment. Two extra hacks are necessary for 32 bit, gtk apps, to work. The first: add the following line to your firefox32 script (mine is /usr/local/bin/firefox32 or /usr/local/firefox32/firefox):

GTK_IM_MODULE_FILE=/etc/gtk-2.0/gtk.immodules.32

This first bug means that the 32 bit gtk looks by default in gtk.immodules, instead of gtk.immodules.32. The second bug is that the base 32 bit environment doesn't set locales. You need the following command:

ln -s /usr/lib/locale /usr/lib32/locale

This should do. Notice how we pursued a single task: to write in Esperanto in Ubuntu. We've found 4 bugs. Not the way to go.

Saturday, April 28, 2007

Beginning Ruby on Rails

For those like me who may be wondering if web development is cool, the place to start is Ruby on Rails. Rails is a much famous web application framework, valued for its agility. In Rails home page, there's an interesting video of someone creating a complete web site in 15 minutes. An exciting tutorial is available in ONLamp.com web site, "Rolling with Ruby on Rails Revisited". Unfortunatelly I haven't found (as of April 2007) any free comprehensive manual of Rails on-line (there's a good oportunity here, eh ? :-) ), so I've decided to buy the book (Agile web development with Rails).

PS: for those who want to stick with python, an alternative to Rails is available, and it's called TurboGears ;-).

New GPIO API in linux kernel 2.6.21 !!!

The 2.6.1 kernel now features GPIO documentation and API !!! :-) See Documentation/gpio.txt.

Sunday, April 01, 2007

A case for consistent (and beautiful) coding styles

As it's written in The Zen of Python (PEP 20), "Readability counts". Code is read much more often than written, so a nice looking source code is fundamental.

This is a criticism specifically aimed to the inconSistentCase that started to plague C++, C and even assembly code in the Internet, and, more generally, a criticism of ugly, useless coding styles, like pre/post-fixed notations, very long line styles, and, surely, inconSistentCase.

Whenever you write code or are in charge of deciding the coding style of your software, please, please, please, use consistent coding styles. For example, use full, first-letter-caps, CamelCase notation, not inconSistentCase. As for my personal coding style taste, do even more, minimize the amount of capitalized letters in your code and use the highly legible underscore_notation instead, like those used in most C code, in python and, especially, in C++ STL. Don't let your code strech to hundreds of characters per line and don't add completely useless "NrUserId" prefixed notations.

Here are many examples of nice, well thought coding styles, that you may adapt for your needs:
  • PEP 8: an exellent coding style guide for the python language. Mostly an underscore_notation style, with a little, easy on eye, CamelCase and post-fixed notation for special cases (ex: ClassNames, ExceptionsEndInError, etc.). The style is good for python and other high level languages, but it could be better for C++, which leads to...
  • STL: part of the C++ standard library, a good example of really well though piece of code. Uses full underscore_notation. If paired with selective namespace downloading (using std::vector, using std::string, etc.), will produce beautiful C++ code.
  • Xlib: Choose this one if you prefer a mostly CamelCase style. Even though Xlib is outdated and supposed to fade away, it was also a well thought library. It also shows a good way to add a namespace-like structure to a C library, using a single "X" prefix in most library functions.
  • linux kernel: Another great coding style for the C language. Useful for mostly non-object oriented, structured programming, but includes insightful hints for anybody (ex: local variables get short, "aux, tmp" names, external functions get long_descriptive_names, etc.), and is backed by the pseudo-chaotic-multi-million-people linux kernel development success.
There are many other projects that you may try that use similar, high legibility coding standards, just google for it. See, for example, Gtkmm, Gtk+ port to C++, the OpenTTD game, etc.

If you've found that all those coding styles are crappy (even after thinking of them in terms of readability), then you should just remember one thing from this post: don't use inconSistentCase, it sucks.

Sunday, March 18, 2007

Saturday, March 17, 2007

Amazing ! Logged in Palm TX !

Since Palm TX linux USB support in hackndev kernel works flawlessly, I was able to deploy buildroot's chroot jail and setup sshd in it ! I'll post a screenshot soon. :-)

Sunday, March 11, 2007

Linux on Palm TX !

This week, I bought a Palm TX, from a friend of a friend. I've been able to boot linux on it, using hackndev howto. I hope that I'll be able to research more fronts now (kernel, applications, performance, etc.), because Palm TX is expected to have a working USB support (so that I can telnet on it :-)) and because of the different capabilities of Palm Tungsten E2 (PXA 255, 16 MB main memory, 320x320 + input area) and Palm TX (PXA 270, 32 MB main memory, 320x480, no input area).

Sunday, March 04, 2007

Reference on GPIO programming with Intel PXA

In my quest to make the USB controller to work without messing the rest of the system, I've found an interesting reference about GPIO configuration for linux ARM. Devices may be activated/deactivated with GPIO ports and, as described in TE2 forum thread at hackndev, USB requires controling GPIO 53.