… | |
… | |
28 | |
28 | |
29 | #if __GNUC__ >= 3 |
29 | #if __GNUC__ >= 3 |
30 | # define is_constant(c) __builtin_constant_p (c) |
30 | # define is_constant(c) __builtin_constant_p (c) |
31 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
31 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
32 | # define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
32 | # define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
|
|
33 | # define noinline __attribute__((__noinline__)) |
33 | #else |
34 | #else |
34 | # define is_constant(c) 0 |
35 | # define is_constant(c) 0 |
35 | # define expect(expr,value) (expr) |
36 | # define expect(expr,value) (expr) |
36 | # define prefetch(addr,rw,locality) |
37 | # define prefetch(addr,rw,locality) |
|
|
38 | # define noinline |
37 | #endif |
39 | #endif |
38 | |
40 | |
39 | #if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) |
41 | #if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) |
40 | # define decltype(x) typeof(x) |
42 | # define decltype(x) typeof(x) |
41 | #endif |
43 | #endif |
… | |
… | |
407 | |
409 | |
408 | // Xorshift RNGs, George Marsaglia |
410 | // Xorshift RNGs, George Marsaglia |
409 | // http://www.jstatsoft.org/v08/i14/paper |
411 | // http://www.jstatsoft.org/v08/i14/paper |
410 | // this one is about 40% faster than the tausworthe one above (i.e. not much), |
412 | // this one is about 40% faster than the tausworthe one above (i.e. not much), |
411 | // despite the inlining, and has the issue of only creating 2**32-1 numbers. |
413 | // despite the inlining, and has the issue of only creating 2**32-1 numbers. |
|
|
414 | // see also http://www.iro.umontreal.ca/~lecuyer/myftp/papers/xorshift.pdf |
412 | struct xorshift_random_generator |
415 | struct xorshift_random_generator |
413 | { |
416 | { |
414 | uint32_t x, y; |
417 | uint32_t x, y; |
415 | |
418 | |
416 | void operator =(const xorshift_random_generator &src) |
419 | void operator =(const xorshift_random_generator &src) |
… | |
… | |
673 | erase (&obj); |
676 | erase (&obj); |
674 | } |
677 | } |
675 | }; |
678 | }; |
676 | |
679 | |
677 | // basically does what strncpy should do, but appends "..." to strings exceeding length |
680 | // basically does what strncpy should do, but appends "..." to strings exceeding length |
|
|
681 | // returns the number of bytes actually used (including \0) |
678 | void assign (char *dst, const char *src, int maxlen); |
682 | int assign (char *dst, const char *src, int maxsize); |
679 | |
683 | |
680 | // type-safe version of assign |
684 | // type-safe version of assign |
681 | template<int N> |
685 | template<int N> |
682 | inline void assign (char (&dst)[N], const char *src) |
686 | inline int assign (char (&dst)[N], const char *src) |
683 | { |
687 | { |
684 | assign ((char *)&dst, src, N); |
688 | return assign ((char *)&dst, src, N); |
685 | } |
689 | } |
686 | |
690 | |
687 | typedef double tstamp; |
691 | typedef double tstamp; |
688 | |
692 | |
689 | // return current time as timestamp |
693 | // return current time as timestamp |