learning sample of likely() and unlikely() compiler hints
问题 How can I demonstrate for students the usability of likely and unlikely compiler hints ( __builtin_expect )? Can you write an sample code, which will be several times faster with these hints comparing the code without hints. 回答1: Here is the one I use, a really inefficient implementation of the Fibonacci numbers: #include <stdio.h> #include <inttypes.h> #include <time.h> #include <assert.h> #define likely(x) __builtin_expect((x),1) #define unlikely(x) __builtin_expect((x),0) uint64_t fib