From 332345c5dda9f16e549803f6155c81c9e4fb904b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kim=20Nguy=E1=BB=85n?= Date: Tue, 29 May 2012 08:14:09 +0200 Subject: [PATCH] Small fixes and optimization - make sure the efficient popcount is called - inline faste version of next_sibling in case the sibling is close by. --- Makefile | 2 +- bp-core.c | 21 ++++++++++----------- bp-darray.c | 2 +- bp-darray.h | 8 ++++++-- bp-utils.h | 3 +-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index 94027c1..f639648 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ endif ifeq ($(DEBUG), true) OPT_FLAGS=-O0 -g $(POPCOUNT_FLAG) -static else - OPT_FLAGS=-O3 $(POPCOUNT_FLAG) -static -flto + OPT_FLAGS=-O3 $(POPCOUNT_FLAG) -static endif diff --git a/bp-core.c b/bp-core.c index 67cc780..700e3e5 100644 --- a/bp-core.c +++ b/bp-core.c @@ -14,17 +14,16 @@ #define MBid(i) ((i)>>logMB) #define MBfirst(i) ((i) & (~(MB-1))) #define MBlast(i) ((i) | (MB-1)) -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) +static int min(int a, int b) +{ + return (a <= b) ? a : b; +} -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a <= _b ? _a : _b; }) - +static int max(int a, int b) +{ + return (a >= b) ? a : b; +} pb getpat_preorder(pb *b) { @@ -109,7 +108,7 @@ int search_SB_r(bp *b, int i, int rel) pb *p,x,w; n = b->n; - il = min((SBid(i) + 1) << logSB,n); + il = min((SBid(i) + 1) << logSB, n); p = &b->B[i>>logD]; while (i> logRR; i_rrr = i >> logRRR; r = da->rl[i>>logR] + da->rm[i_rr]; j = (i_rrr) & (RR/RRR-1); + offset = i_rr << (logRR-logRRR); + buff = &(da->rs[offset-1]); while (j > 0) { - r += da->rs[((i_rr)<<(logRR-logRRR))+j-1]; + r += buff[j]; j--; } diff --git a/bp-utils.h b/bp-utils.h index 56f2d73..2397d6f 100644 --- a/bp-utils.h +++ b/bp-utils.h @@ -28,8 +28,7 @@ extern "C" { #ifdef HAS_NATIVE_POPCOUNT static inline UNUSED unsigned int popcount(unsigned int n){ - asm ("popcnt %1, %0" : "=r" (n) : "0" (n)); - return n; + return __builtin_popcount(n); } static inline UNUSED unsigned int popcount8(unsigned int n) { -- 2.17.1