Small fixes and optimization
authorKim Nguyễn <kn@lri.fr>
Tue, 29 May 2012 06:14:09 +0000 (08:14 +0200)
committerKim Nguyễn <kn@lri.fr>
Tue, 29 May 2012 06:14:09 +0000 (08:14 +0200)
      - make sure the efficient popcount is called
      - inline faste version of next_sibling in case
        the sibling is close by.

Makefile
bp-core.c
bp-darray.c
bp-darray.h
bp-utils.h

index 94027c1..f639648 100644 (file)
--- 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
 
 
index 67cc780..700e3e5 100644 (file)
--- a/bp-core.c
+++ b/bp-core.c
 #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<il) {
     x = *p++;
@@ -126,7 +125,7 @@ int search_SB_r(bp *b, int i, int rel)
         }
       }
       r = min(j,ETW);
-      rel -= 2*popcount(w)-r;
+      rel -= (popcount(w) << 1)-r;
       x <<= r;
       i += r;
       j -= r;
index 866ce6f..eecaccb 100644 (file)
@@ -56,7 +56,7 @@ static int getpattern(pb *B, int i, int k, pb pat)
   return x;\r
 }\r
 \r
-static int selecttbl[8*256];\r
+int selecttbl[8*256];\r
 static int selecttbl_init = 0;\r
 static void prbin(unsigned int x)\r
 {\r
index 75808f1..e46834f 100644 (file)
@@ -38,17 +38,21 @@ void bp_darray_free(darray *da);
 
 int bp_darray_select(darray *da, int i,int f);
 
-static int bp_darray_rank(darray *da, int i)
+static inline int bp_darray_rank(darray *da, int i)
 {
   int r,j,i_rr, i_rrr;
+  int offset;
   pb *p;
+  byte *buff;
   i_rr = 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--;
   }
 
index 56f2d73..2397d6f 100644 (file)
@@ -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) {