Sunday, December 16, 2012
Thursday, October 11, 2012
Using named branches in Mercurial can be rather difficult especially when it gets to merging these branches. There are several useful techniques and process improvements that simplify the development/release loop. You can find some of them in the talk slides I did on Oct 11, 2012 here at Quickoffice(aka DoctorMobile). It doesn't restrain any development flow and can be useful for any Mercurial (or even non-Mercurial) user. For those who are not familiar with Mercurial at all I recommend to read some guides before looking at the slides. What every programmer should know about merging branches in Mercurial Sources for the slides can be found here
Sunday, May 27, 2012
Here __builtin_popcount is a function that calculates the population count. If compiled with
gcc -O3 t.c -o bitcountone can get such results:
$ time ./bitcount real 0m17.465s user 0m17.425s sys 0m0.000sNot too fast, huh? Some of the time is wasted calling the function and inlining it can speed up things. But! There is even a better way. Compiling it with
gcc -O3 -mpopcnt t.c -o bitcountresults in:
$ time ./bitcount real 0m1.738s user 0m1.728s sys 0m0.004sThat's simply because modern processors have POPCNT instruction that can be used to count the number of bits and GCC is nice enough to support it. As you can see, in this case hardware optimization beats smart algorithm design with ease.
ResumeAlgorithms are designed on paper but executed on a real hardware. Knowing what your hardware is capable of is a must for a software engineer. And please don't tell me about all these patterns and object-oriented stuff: unless you invent a machine that can run concepts instead of machine instructions, you must be aware of all the low-level stuff
I also highly recommend an awesome article "Benchmarking CRC32 and PopCnt instructions" for further reading.
Thursday, March 29, 2012
Today I want to show you some of the plain old C black magic. This is the magic of direct user context manipulating. You can use this low-level feature to implement some high-level language abstractions such as generators and ruby-like blocks. Let's start with an example(test1.c):
The code above is a valid C code. It produces such output:
Let's take a look on the implementation of used generators (enumerate, for_each in gens.c):
As you can see, the implementation of generators is pretty straightforward. All the magic is done in cblocks.h:
Manual pages for swapcontext and getcontext can help in understanding what's going on here.
- It's possible to implement nifty language features in C using its low-level features. The generators described above can be even used to build cooperative multitasking systems.
- It doesn't mean that you should do it just because you can ;). Beware that context manipulating doesn't work on all platforms.
- You can find the source code on github. The code should be considered just a playground so please forgive me its untidiness. If you want something mature(e.g., you're seeking for coroutines support in C), check out the libtask, libtorque or libcoro
As always I will be happy to accept any criticism on the code above. Feel free to contact me in any way you can imagine.