/normxcorr/trunk

To get this branch, use:
bzr branch http://suren.me/webbzr/normxcorr/trunk

« back to all changes in this revision

Viewing changes to dict_hw/src/helpers.h

  • Committer: Suren A. Chilingaryan
  • Date: 2009-12-12 01:38:41 UTC
  • Revision ID: csa@dside.dyndns.org-20091212013841-feih3qa4i28x75j4
Provide stand-alone library

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if defined(_WIN32) || defined(_WIN64)
 
2
# include <windows.h>
 
3
    typedef UINT8 uint8_t;
 
4
    typedef UINT16 uint16_t;
 
5
    typedef UINT32 uint32_t;
 
6
    typedef INT8 int8_t;
 
7
    typedef INT16 int16_t;
 
8
    typedef INT32 int32_t;
 
9
#else
 
10
# include <stdint.h>
 
11
#endif
 
12
 
 
13
#define max4(a,b,c,d) max2(max2(a,b),max2(c,d))
 
14
#define max3(a,b,c) max2(max2(a,b),c)
 
15
#define max2(a,b) (((a)>(b))?(a):(b))
 
16
#define min2(a,b) (((a)<(b))?(a):(b))
 
17
 
 
18
#define calc_alloc(size,rounding) ((((size)/(rounding)) + (((size)%(rounding))?1:0))*(rounding))
 
19
#define calc_blocks(size,rounding) (((size)/(rounding)) + (((size)%(rounding))?1:0))
 
20
 
 
21
static const char debruijn[32] = {
 
22
    0,  1, 28,  2, 29, 14, 24,  3, 30, 22, 20, 15, 25, 17,  4,  8,
 
23
    31, 27, 13, 23, 21, 19, 16,  7, 26, 12, 18,  6, 11,  5, 10, 9
 
24
};
 
25
 
 
26
static inline int next_power(int n) {
 
27
    n--;
 
28
    n |= n >> 1;   // Divide by 2^k for consecutive doublings of k up to 32,
 
29
    n |= n >> 2;   // and then or the results.
 
30
    n |= n >> 4;
 
31
    n |= n >> 8;
 
32
    n |= n >> 16;
 
33
    n++;           // The result is a number of 1 bits equal to the number
 
34
                   // of bits in the original number, plus 1. That's the
 
35
                   // next highest power of 2.
 
36
    return n;
 
37
}
 
38
 
 
39
static inline int get_power(int n) {
 
40
    if (n&(n-1)) return -1;
 
41
    else return debruijn[((uint32_t)n * 0x077CB531) >> 27];
 
42
}