From: H. Peter Anvin Date: Tue, 10 Jun 2008 16:35:26 +0000 (-0700) Subject: Introduce likely/unlikely macros, use them in saa.c X-Git-Tag: nasm-2.11.05~1439 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51997d3d44a9279508b16e9f3d5e2de173ece7c2;p=platform%2Fupstream%2Fnasm.git Introduce likely/unlikely macros, use them in saa.c Introduce the likely() and unlikely() macros, as used in Linux. They are compiler-dependent hints that a particular boolean expression is likely to be true or false, respectively. Currently only implemented for gcc. --- diff --git a/compiler.h b/compiler.h index 01e1127..51f4983 100644 --- a/compiler.h +++ b/compiler.h @@ -110,4 +110,16 @@ char *strsep(char **, const char *); # define X86_MEMORY 0 #endif +/* + * Hints to the compiler that a particular branch of code is more or + * less likely to be taken. + */ +#if defined(__GNUC__) && __GNUC__ >= 3 +# define likely(x) __builtin_expect(!!(x), 1) +# define unlikely(x) __builtin_expect(!!(x), 0) +#else +# define likely(x) (!!(x)) +# define unlikely(x) (!!(x)) +#endif + #endif /* NASM_COMPILER_H */ diff --git a/saa.c b/saa.c index 51123da..1704b7d 100644 --- a/saa.c +++ b/saa.c @@ -211,7 +211,7 @@ void saa_fread(struct SAA *s, size_t posn, void *data, size_t len) return; } - if (s->blk_len == SAA_BLKLEN) { + if (likely(s->blk_len == SAA_BLKLEN)) { ix = posn >> SAA_BLKSHIFT; s->rpos = posn & (SAA_BLKLEN-1); } else { @@ -235,7 +235,7 @@ void saa_fwrite(struct SAA *s, size_t posn, const void *data, size_t len) return; } - if (s->blk_len == SAA_BLKLEN) { + if (likely(s->blk_len == SAA_BLKLEN)) { ix = posn >> SAA_BLKSHIFT; s->wpos = posn & (SAA_BLKLEN-1); } else {