ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/util.h
(Generate patch)

Comparing deliantra/server/include/util.h (file contents):
Revision 1.84 by root, Wed Dec 31 17:35:37 2008 UTC vs.
Revision 1.87 by root, Mon Jan 12 03:40:21 2009 UTC

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
412struct xorshift_random_generator 415struct 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)
678void assign (char *dst, const char *src, int maxlen); 682int assign (char *dst, const char *src, int maxsize);
679 683
680// type-safe version of assign 684// type-safe version of assign
681template<int N> 685template<int N>
682inline void assign (char (&dst)[N], const char *src) 686inline 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
687typedef double tstamp; 691typedef double tstamp;
688 692
689// return current time as timestamp 693// return current time as timestamp

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines