Tuesday, October 12, 2010

Maverick's font

Just upgraded to Ubuntu Maverick on my work machine. The new font is pretty cool.

Friday, October 1, 2010

Perhaps the best way to paste code in blogger

Github Gists.

Here's a simple example

Syntax highlighting for a gazillion langugaes, forkable, editable, and revisions to boot. What's not to like compared to methods like these?

Honestly, I think any dev worth his salt should switch to this method or it's equivalent.

Sunday, September 5, 2010

Testing out Github Pages

Github's really cool. They have some awesome services on top of the already awesome git based version control. I just made a test page to checkout the possibility of hosting a blog over there.

Thursday, July 29, 2010

Another compiler in haskell series

Here's another compiler in Haskell series. This one's based on Crenshaw's famous series, and is quite a a bit simpler than the prior one. But it takes quite a different route as well.

Saturday, July 17, 2010


I'll miss you.

Tuesday, June 15, 2010

GCC: Now you are going to unroll the loop or should I?

A codelet to calculate the log (to base 2) of a number which is known to be a power of 2.

unsigned int log2_pow2(unsigned int v) // 32-bit value to find the log2 of
static const unsigned int b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0,
0xFF00FF00, 0xFFFF0000};
register unsigned int r = (v & b[0]) != 0;
int i;
for (i = 4; i > 0; i--) // unroll for speed...
r |= ((v & b[i]) != 0) <<>
return r;

Let's see what do we get with GCC 4.4 at O3,

400550: 31 c0 xor %eax,%eax 400552: f7 c7 aa aa aa aa test $0xaaaaaaaa,%edi 400558: 0f 95 c0 setne %al 40055b: 31 d2 xor %edx,%edx 40055d: f7 c7 00 00 ff ff test $0xffff0000,%edi 400563: 0f 95 c2 setne %dl 400566: 31 c9 xor %ecx,%ecx 400568: c1 e2 04 shl $0x4,%edx 40056b: f7 c7 00 ff 00 ff test $0xff00ff00,%edi 400571: 0f 95 c1 setne %cl 400574: c1 e1 03 shl $0x3,%ecx 400577: 09 ca or %ecx,%edx 400579: 09 c2 or %eax,%edx 40057b: 31 c0 xor %eax,%eax 40057d: f7 c7 f0 f0 f0 f0 test $0xf0f0f0f0,%edi 400583: 0f 95 c0 setne %al 400586: c1 e0 02 shl $0x2,%eax 400589: 09 c2 or %eax,%edx 40058b: 31 c0 xor %eax,%eax 40058d: f7 c7 cc cc cc cc test $0xcccccccc,%edi 400593: 0f 95 c0 setne %al 400596: 01 c0 add %eax,%eax 400598: 09 d0 or %edx,%eax 40059a: c3 retq 40059b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)

So GCC unrolled the code for us. Nice. But how about this bit of assistance?

unsigned int log2_pow2_2(unsigned int v) { register unsigned int r = (v & 0xAAAAAAAA) != 0; r |= ((v & 0xFFFF0000) != 0) <<>

Shouldn't make much difference, right? Let's ask the GCC gods for their verdict.

4005a0: 89 f8 mov %edi,%eax 4005a2: 89 fa mov %edi,%edx 4005a4: 66 31 c0 xor %ax,%ax 4005a7: 83 f8 01 cmp $0x1,%eax 4005aa: 19 c0 sbb %eax,%eax 4005ac: 81 e2 00 ff 00 ff and $0xff00ff00,%edx 4005b2: f7 d0 not %eax 4005b4: 83 e0 10 and $0x10,%eax 4005b7: 83 fa 01 cmp $0x1,%edx 4005ba: 89 fa mov %edi,%edx 4005bc: 19 f6 sbb %esi,%esi 4005be: 81 e2 f0 f0 f0 f0 and $0xf0f0f0f0,%edx 4005c4: f7 d6 not %esi 4005c6: 83 e6 08 and $0x8,%esi 4005c9: 83 fa 01 cmp $0x1,%edx 4005cc: 89 fa mov %edi,%edx 4005ce: 19 c9 sbb %ecx,%ecx 4005d0: 81 e2 cc cc cc cc and $0xcccccccc,%edx 4005d6: f7 d1 not %ecx 4005d8: 83 e1 04 and $0x4,%ecx 4005db: 83 fa 01 cmp $0x1,%edx 4005de: 19 d2 sbb %edx,%edx 4005e0: f7 d2 not %edx 4005e2: 83 e2 02 and $0x2,%edx 4005e5: 81 e7 aa aa aa aa and $0xaaaaaaaa,%edi 4005eb: 40 0f 95 c7 setne %dil 4005ef: 40 0f b6 ff movzbl %dil,%edi 4005f3: 09 f8 or %edi,%eax 4005f5: 09 f0 or %esi,%eax 4005f7: 09 c8 or %ecx,%eax 4005f9: 09 d0 or %edx,%eax 4005fb: c3 retq 4005fc: 0f 1f 40 00 nopl 0x0(%rax)

Gee, that was unexpected. The code size grew. And is probably slower because of it. I do not claim to know much of non-SSEx assembly, but the manual unrolling seems to produce worse code.

Who knew? :|

Thursday, June 3, 2010

Quote of the day.

"Cache coherence certainly can scale -- for codes designed to scale on it. This generally means codes designed to not use coherence very much"

-Greg Pfister


Wednesday, May 26, 2010

Emacs and unicode

Of late, my Emacs had been throwing up at the quote marks in the compile window. Here's how to fix it.

BTW, I didn't need the clipboard-coding-system bit. My emacs works fine without it.

Friday, May 7, 2010

Eclipse with Arduino

This is a very good guide.

Tuesday, May 4, 2010

Indian electronic voting machines are vulnerable to fraud

Full paper


Broadly speaking, I see three problems.

1) Belief in the magic of security through obscurity.

2) Near-total absence of understanding of electronic technology and it's security related aspects.

3) Confusing the comfort of Powerpoint presentations for a reliable and robust defence against hardcore cracking by motivated and well-resourced individuals.

Friday, April 30, 2010

Web 2.0 Calc

A really nice web app. Very useful at times when you don't have a physical calculator at hand and the problem is too small to fire up an ipython/scipy console.

Wednesday, April 28, 2010

Build a compiler series

A great 15 part series here. Definitely worth bookmarking.

The approach taken is an interesting one. Ruthlessly eliminate features. Relentlessly punt to user. Just focus on building a working, complete - and functionally correct - baseline. By functionally correct, I mean it should correctly - and in all cases completely - raise the red flag whenever it encounters anything illegal according the syntax or semantics.

Perhaps it deserves to be given a name. How about "The Crenshaw approach"?

Saturday, April 10, 2010

Apple's latest

Have a look.

Great job, Apple. HTML5 can't land here fast enough. I wonder why then, they seem to be interested in HTML5 so much by their participation in WHATWG.

Friday, April 2, 2010

An eye opener...

"Indeed, the government predicts the jobless rate will average 9.8 percent next year and 8.4 percent in 2012 before falling to 5 percent in 2016."

~3 years to reduce unemployment by ~1%. Really eye opening.

Sunday, March 28, 2010

Python reference management

I ran into a crazy Python reference management behavior today. I wanted to do

x=y=[None for i in xrange(10)]

and then add elements to both x and y separately. Basically, wanted to avoid creating an empty list and then append stuff to each. No particular reason, just for the heck of it.

Turns out there is some kind of weird reference management policy in Python, which it so happens that I don't have the time to dive into right now. What this does is that it couples x to y, in such a way that changing elements of one affects the other.

So, the solution is to change the above line into

x=[None for i in xrange(10)]
y=[None for i in xrange(10)]

Monday, March 22, 2010

x86-64 unsupported.

Sorry we don't support the X86_64 build environment (we never use it internally). An AMD employee, who presumably works on open64, in Dec 2009.

I am not sure whether to laugh or cry.

Sunday, March 21, 2010

New/old style classes in Python

I just got bitten by the new/old style classes in Python. :P

Here's a reasonably good description/discussion/summary/...

Thursday, March 18, 2010

GPU acceleration in IE 9

This is definitely something exciting.

It's nice to see GPU acceleration coming to consumer apps other than games. :) In the next couple of years, we can expect pervasive support for fast texturing and drawing in web browsers. Even though it leverages just the classic "drawing lines and triangles" bit of gpu's and not their emerging compute side, with imminent merger of cpu's and gpu's, I think gpu's might have found their killer app for the non-gaming folks. With on-die gpu's and faster JS, I think web apps are going to get quite cool, especially in the hands of competent web developers.

At any rate, it seems doubtful that web developers will stress even the lamest gpu's of today. They are just too ridiculously fast for these kind of workloads. And JS is going to be dog slow compared to C++ for ages to come. Unless, of course, somebody hires Mike Pall to speed up their JS engines, at which point all bets are off. :)

More generally, better web standards support from IE is great to see.

From the hardware accelerated video decoding point of view, I think Firefox going to be a loser here. H.264 seems to have won the web video codec war and so far Mozilla's policy has been to avoid it like plague.

Overall, these are exciting times for all those who browse the web, as your vehicle is about to get a serious overhaul.

I have only one question with that article. Since when has Apple solicited any kind of consumer feedback in the design phase for any of their products?

Monday, March 8, 2010


Swiftfox, an optimized build of Firefox for Linux is pretty good with speed. I am running the 64 bit build of 3.6 and it's cpu and mem usage seems pretty good to me. They have prebuilt binaries, but only for Ubuntu.

Check it out.

Sunday, February 28, 2010

Friday, February 19, 2010

Chromium begins to suck :(

I had no idea it will come so close to my praise for Chromium over Firefox. But it has happened.

I use the Chromium daily PPA for Ubuntu. And for a few days now, Chromium has been showing abnormally high CPU usage. It basically locks up a core, and when you have only a dual core machine, things get bad and ugly. The only saving grace is that I can shutdown chromium rather painlessly as usually, only one process is responsible for the CPU lockdown,.

My cribs against Firefox still stand, but a quirky browser is better than a useless browser.

Back to Firefox then, :|

Monday, February 8, 2010

Emacs theme based customization

Many softwares today ofter theme support to increase aesthetic attractiveness. Here's a good way to get it done in my favorite editor, emacs.

Sunday, February 7, 2010

Chrome gobbling up Firefox users

This is an interesting bit of news.

Overall, Firefox seems to have stalled while Chrome is growing. Amongst Ars Technica users, IE and Firefox are losing share to Safari and Chrome. A 14% share amongst a tech-savvy community within a year of it's public unveiling is good by any standards. At this rate, on this website atleast, by the end of summer, Chrome would be in the number 2 position.

While IE's decay is hardly unsurprising, the loss of mind share amongst a savvy community does not bode well for Firefox. I have been a chrome convert for a long time now. I was also unaware of the general stall in Firefox's growth

Speaking about overall internet aware community is pretty hard. After all some 20% of IE users are still using IE6. :P Why did I switch over to Chrome? Well actually I use the non trademarked, third party provided builds, so it is probably more accurate to call it Chromium.

Firefox has always been pretty good with it's rendering accuracy. FF2 and 3 were pretty good in this regard. However, where they really messed up was Javascript speed and tab isolation. All versions of FF so far have been a single process design and it used to lock up with many tabs/heavy javascript often. Many times, it would be just a single bad tab taking down the entire browser. The only way out was to kill the entire browser itself, losing your entire session.

The memory usage was another problem. I use my browsers for long periods of time often opening lots of tabs and the closing them and this usage cycle repeats often. All through this, FF's memory consumption keeps increasing due to memory fragmentation. I have seen a single Gmail tab use up more than 300 MB of memory after a long period of usage. In FF 3 and earlier, it was pretty common after just a couple of such usage cycles to have a single tab use up about 200 MB memory.

With these problems at hand, I switched over to Chromium for it's speed and scalability under heavy loads. For the most part, the rendering was fine but it did have occasional rendering SNAFU's. Within a couple of months they were sorted out too. It's not like Chromium never jams up. It does. But the failure rate is easily an order of magnitude less that FF3. FF3.5 has, for the most part, has competitive JS performance and the lock up issues occur much less frequently. I haven't looked at FF3.6 yet.

With those two bugbears off it's back, what is holding FF back for me? In no particular order, they are as follows.

First, it wastes a lot of window space, which Chromium reuses for actual web pages. The rest of browser window is unused 99% of the time, why waste screen real estate for the 1% case.

Second, it does not, yet, have flexible tab manipulation. By that, I mean easy (drag-and-drop) shuffling of tabs across browser windows. May be it is already there in FF and I don't know how to use it. For me, it is the browser's equivalent of multiple desktops in Linux world.

Third, the first option when you right click on a link is 'open in new tab' in Chromium. Juggling multiple browser windows is clumsy, which is why we have moved on to tabbed browsing today. Then what is the point of having 'open in new window' as the first option in right-click menus?

Fourth, Chromium's integrated address and search bar is enormously useful. It suits my browsing style so much that I positively detest the split bars in all other browsers today. I am not going back to any other browser if it does not have this feature.

Fifth, Chromium's another useful feature (largely overlooked by the competition) is that when you close off a tab, the rest of the tabs do not appropriate the whole horizontal window space immediately. There is a small pause, which is very useful in closing adjacent tabs, as the next tab's cross button smoothly slides into the now-closed tab's cross button's position. Try closing many tabs with your mouse in FF. You'll often have to move your pointer as you close off tabs. This is a big irritant for my daily use.

Which browser I am gonna be using in the future? Chromium, definitely. It won over FF because it was better in many (but not all) regards. Today it is better in all but one. No DownThemAll :(. I should mention that I didn't use many FF extensions. The one that I like (a lot) is DownThemAll. Sometimes, I often start up FF just to use this. But that's pretty much it.

It's the same situation with Google vs Bing. Initially people switched over to Google because it was better than everyone else in search. Now MS/Bing has been trying hard to compete with Google. And at the moment it is almost as good as Google. But it won't gain market/mind share until it becomes better than Google. And I won't go back to FF until it becomes better that Chromium.

On a side note, it appears that Ubuntu does not upgrade packages in it's update repositories. Although Ubuntu 9.10 has been keeping my FF updated with all the security and other bug fixes, it has not updated my FF 3.5 to 3.6. Apparently, it is their policy to provide feature updates in the next distribution release only. I like Fedora more on this count. :P

Semi-rant against python multiprocessing module

Go here. And now look at issue 13 in that bug track. Or just have a look at this.

This is bad news. The unpicklability of lambdas has forced me to make some ugly changes to the parallel code I was using to drive my python extensions. I really-really wish it was doable.

For a while, I have been thinking that use of python's multiprocessing module to parallelize your C extensions akin to solving the problem at the wrong abstraction level. This nails it.

OTOH, opencl has a wonderful parallelization and synchronization model. In future, I am looking to write OCL code only for compute intensive tasks. Implementations from AMD and nvidia are out of beta, but they are immature atm. Intel is missing in action.

I expect it will take them about a year more to mature.

Thursday, January 28, 2010

WebGL : updates

The draft spec is out. And here's a great place to learn more about it. Looks like I'll be tempted into learning web programming and JS after all. :)

Apple iPad


The concept has potential. But this iteration is bloody useless for my purposes. Let's hope Apple can do much better in the future versions.

Google Book Search - a personal experience

I have naturally been excited at the prospect of having all, (well, almost all) of the world's books scanned and made full text search searchable, with Google-level smarts in them.

I was kind of indifferent to the legal battle going on (go here for an update on that).

A few days ago, I had a profoundly useful experience with Google Books. I came across a solution to a problem I have been tackling (for a little hobby of mine) for a long time now. I had searched long and hard for it when I was actively working on it, but couldn't make much progress.

And then, a few days ago, when I gave it another shot, ~70% of the solution turned up in a book in Google Books. I had a look at the book title and author, and voila, a copy of it was available in my university library.

I had long thought that perhaps nobody had tried to tackle this before so a lot of heavy lifting would have to be done. But Google Books saved the day.

Which is why now I am *strongly* in favor of allowing the proposed deal to go through. I urge all the concerned decision makers to let this this wonderful thing happen. Newton stood on the shoulders of giants. Over the last ~350 years, we have accumulated the knowledge and the technology to let even folks like me stand on Mount Everest of human knowledge and make useful contributions, in whatever small way.

As for the various concerns, I have just one thing to say. Google made all the investment in technology, money, risk and effort. They have every right to milk it fwiw. However, I have just one quib. If exclusivity granted to Google were junked, it would be a Great Leap Forward for the entire humanity. In a really good way. After all, all of us stand to gain from the competition between search engines.

Tuesday, January 26, 2010

The way it's meant to be seen.

Saw Avatar.


It rocks. :)

Apparently, many people agree.

No really, it changes the way movies-are-meant-to-be-seen.