Archive for January, 2009

LLVM loop unrolling powers

Thursday, January 29th, 2009

I found a morning today to play a bit more with the Firtree compiler re-write. As you will remember, I’m replacing the current GLSL focussed hacky compiler with something a little nicer based on LLVM. The idea being that kernels are compiled to an LLVM IR, LLVM does it’s magic, linking happens and the backends just have to deal with one monolithic blob of LLVM. All the optimisation is handled by LLVM.

Today I implemented for/do/while loops. In Firtree it is a requirement that these loops be unwindable at runtime since not all backends will support loops. This also neatly avoids the problem of locking one’s graphics card with an infinite loop. After a few false starts I can now present this kernel:

kernel vec4 testKernel() {
  int c = 5;

  for(int dx=-3; dx<=3; dx++) {
    for(int dy=-3; dy<=3; dy++) {
      for(int dz=-3; dz<=3; dz++) {
        c = dx+dy+dz;
      }
    }
  }

  int a = 10;
  int d = 10;
  while(a > 3) {
    int f = 5;
    while(f > 2) { 
      --f; 
      --d;
    }
    --a;
  }

  int b = 5;
  do { --b; } while(b>0);

  return vec4(a,b,c,d);
}

And have this result:

define internal <4 x float> @testKernel(<2 x float> %__this__destCoord) nounwind readnone  {
entry:
	ret <4 x float> < float 3.000000e+00, float 0.000000e+00, float 9.000000e+00, float -1.100000e+01 >
}

This is a definite improvement over the 139-line monster that the compiler spits out pre-optimisation.

Raging at charities

Thursday, January 29th, 2009

Through the door today came a collection bag for the Cystic Fibrosis Trust. On the bag were a set of ‘fascinating facts’ about cystic fibrosis. Two of them caught my eye:

  • Five people per day are born with cystic fibrosis. Three of the babies don’t survive.
  • The average life expectancy for someone with cystic fibrosis is 31.

Now this is where I put my rage-at-incomplete-out-of-context-statistics hat on. This doesn’t give me anywhere near enough information to make a reasoned conclusion! Nevertheless, I found my thinking going along the following lines. I initially raged internally at their use of the phrase ‘average life expectancy’. This is meaningless unless one specifies from which age it is measured. The probability of reaching a given age is clearly dependent on the age which you have already reached. It is page one conditional probability theory. Without any other information I have to assume they mean ‘average life expectancy at birth’.

Now let’s consider that in relation to the first statement. Suppose there is a ‘life expectancy given you’re not one of the three babies that died’, λ. The first statement implies that the life expectancy at birth is 2λ / 5. Assuming this is equal to 31, we have λ = 5/2 × 31 = 77.5. Now let’s check in the CIA world fact book for the UK’s life expectancy at birth. It turns out to be… 77.5.

Now I know that I’ve put a lot of assumptions into the calculation above but I’m forced to by the misleading and incomplete statements on the original piece of propaganda. If I accept what is written there and use the first assumptions I made, I find that if I meet someone with cystic fibrosis in the street, they can expect to live as long as me. I feel cheated and annoyed.

This is of course entirely unrelated to the quality of life for a cystic fibrosis sufferer and the deservedness of a charity dedicated to helping them but if their little bag was supposed to make me think ‘oh, those poor cystic fibrosis suffers are doomed to live young’ then they failed spectacularly.

When I rule the world, this very example will be taught to school kids as part of the ‘remember, everyone is lying to you’ lessons.

Visualising data

Monday, January 26th, 2009

There is a beautiful video on Vimeo showing the contributions to Open Streetmap for 2008 on a 3D rotating globe. Just wonderful!

Moving forwards, looking back

Monday, January 26th, 2009

I earnestly believe that people can’t learn programming nowadays as easily as those of us fortunate to grow up in the tail end of the home computer revolution could.

Gone are the days when you got a new computer, plugged it into your television[1], switched it on and, apparently instantaneously, there was a prompt and a flashing cursor asking you for input. No booting, no EULA, no crapware asking if you want to create a Yahoo! account. Nothing but an open door.

The computer practically begged you to code. Even if all you learned was the command to load the first programme from tape and execute it, you learned that a computer fundamentally listens to what you say and Just Fsking Does It(TM).

The computer would come with a glossy printed book that didn’t try to sell you extended warranties or push the manufacturer’s own online music site. Instead it told you how to use your computer. How to instruct it to draw pictures, calculate things and to perform apparent miracles or computation. With three lines of magic runes you could have the instant gratification of making pictures jump and dance on the screen.

There were resources a plenty to help you learn. There were books, magazines, periodicals. All came with small programmes that let you, for little effort, create with your machine in a way that nowadays seems inconceivably complex to a novice user. Back then your machine came with everything you needed to start writing programmes and that everything was BASIC. Now you need to download Java, Python, or any one of a million other choices. It isn’t even obvious which language to start with, even Visual Basic has made it non-trivial to draw a spirograph pattern on screen. You can’t just jump in anymore.

What prompted my revere? Someone has just released a copy of the excellent Archimedes Operating System: A Dabhand Guide. The Dabs press books were my companions as I grew up with computers. Between those and the ever excellent Usbourne books I was shown an amazing new world in a way which I do not appreciate often enough. I am incredibly lucky to have been born when I was and I should realise that more often.

I can’t help feeling that if I were to start learning to program today, the magic would just not be there any more.

[1] Although with HD televisions, that part may return.

Political spectrum meme

Friday, January 23rd, 2009

From megamole@livejournal

My Political Views
I am a center-left moderate social libertarian
Left: 1.34, Libertarian: 1.38

Political Spectrum Quiz
My Foreign Policy Views
Score: -3.79

Political Spectrum Quiz
My Culture War Stance
Score: -4.43

Political Spectrum Quiz

The true cost of Windows

Thursday, January 22nd, 2009

The ubiquitous Dell have started selling their M1330 XPS laptops pre-installed with Ubuntu. I was curious about the price difference between Windows and Ubuntu, so I configured two laptops to the same specs as the base-level Windows laptop except that one had Ubuntu and one had Windows Vista I-need-to-actually-do-real-work-on-this-one edition.

On the Dell site, the Windows laptops only have the choice between Vista noddy[1] and the aforementioned ‘real’ version. Despite this, the Vista laptop still doesn’t come with an office suite or any of the other things bundled into the standard install of Ubuntu.

The difference speaks for itself:

Windows Ubuntu
819.01GBP 714.99GBP

And the Windows machine is on sale!

But wait, there is more! I had to configure the Ubuntu machine up to this spec. The Ubuntu machine by default comes with a smaller hard drive, less memory and Intel graphics (as opposed to nVidia). The Windows machine also comes with a non-optional fingerprint reader.

Removing just the fingerprint reader from the Ubuntu machine reduces it to £684.99 and going with Intel graphics plus the smaller battery this allows gives a final price of £599.00

So, depending on how you count it, the Windows tax on a Dell is somewhere between £104.02 and £220.01, not including the sale discount on the Windows laptop which would push the difference up by £20.00.

Is it really worth it?

[1] If you want to hobble your laptop, you can opt for Vista Home Premium which narrows the gap to £14.00 with fingerprint reader or £44.00 if you decide the fingerprint reader is useless.

Update: I forgot this other pearl of wisdom too. Look at what the Dell website uses as the icon for ‘an operating system’:

The Windows logo

You can checkout any time you like / But you can never leave!

Tuesday, January 13th, 2009

I just received the following email from the catering manager at my old college. I am presuming it is about electronic point of sale cards. I hear those crazy kids now use them to pay for things.

Your balance is now overdrawn. Please top-up to restore the balance to zero as a minimum. If you continue to spend without topping-up, your card will be stopped. Visit the website for information about topping-up. Contact me if you have a query.

I’m astonished I have any balance given I had graduated before this system had started. I can only assume that I still exist somewhere on the Robinson database and someone has coded balance <= 0 instead of balance < 0. :)