Archive for July, 2010

Counterpart of __assume in GCC

Microsoft Visual C++ has a keyword __assume, which is used to pass a hint to the compiler for optimization. It can be useful when optimizing hotspots in a program. For example, if we know a loop will run at least once, we can add an __assume hint:

__assume (0 < n);
for (i=0; i < n; i++)
    /* .... */

This eliminates the comparison of n against zero before entering the loop body for the first time, without changing it to a do-while structure, which is usually less preferable than a for loop. Another typical use is to tell the compiler the default branch of a switch-case statement is unreachable.

GCC does not have a counterpart. But now that GCC 4.5.0 introduced __builtin_unreachable, we can do everything in GCC what we do with __assume in MSVC. My tests show the following macro works:

#define __assume(cond) do { if (!(cond)) __builtin_unreachable(); } while (0)

(The “do { ... } while (0)” statement is just a small trick in defining macros. Actually it’s been so well known and widely used that it can hardly be called a trick anymore.)

Tags: ,

Switch from syslog-ng to rsyslog

I just think it is funny for a package as fundamental as system logger to depend on glib (part of the GTK+ project). (Of course, I don’t mean glib is a bad library. I’m not implying anything like that.)

Of course there are other reasons, but they are less important:

  • Many distributions also prefer rsyslog to syslog-ng because it’s more powerful and scalable. [1] [2]
  • Several people complained against the performance of syslog-ng [3], although the performance of syslog is normally not an issue for individual users.
  • Third, I don’t understand why the author of syslog-ng prefers listening on /dev/log as a stream socket (local counterpart of TCP) instead of a datagram one (local counterpart of UDP). (I know it can be changed in the configuration file.) None of the common issues of UDP is present in local datagram sockets: too short length limit; out of order; unreliability. On the contrary, syslog needs unidirectional channels carrying boundary-maintained messages, for which nothing can be more suitable.
  • Finally, licensing issues, upstream responsiveness, etc. They are less important for individual users, though.

Sure, syslog-ng also has its advantages. For example, I like the format of its configuration files.

Tags: ,