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.95 by root, Tue Nov 10 00:01:31 2009 UTC vs.
Revision 1.98 by root, Fri Apr 2 03:41:24 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * 5 *
6 * Deliantra is free software: you can redistribute it and/or modify it under 6 * Deliantra is free software: you can redistribute it and/or modify it under
7 * the terms of the Affero GNU General Public License as published by the 7 * the terms of the Affero GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your 8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version. 9 * option) any later version.
240absdir (int d) 240absdir (int d)
241{ 241{
242 return ((d - 1) & 7) + 1; 242 return ((d - 1) & 7) + 1;
243} 243}
244 244
245// avoid ctz name because netbsd or freebsd spams it's namespace with it
246#if GCC_VERSION(3,4)
247static inline int least_significant_bit (uint32_t x)
248{
249 return __builtin_ctz (x);
250}
251#else
252int least_significant_bit (uint32_t x);
253#endif
254
255#define for_all_bits_sparse_32(mask, idxvar) \
256 for (uint32_t idxvar, mask_ = mask; \
257 mask_ && ((idxvar = least_significant_bit (mask_)), mask_ &= ~(1 << idxvar), 1);)
258
245extern ssize_t slice_alloc; // statistics 259extern ssize_t slice_alloc; // statistics
246 260
247void *salloc_ (int n) throw (std::bad_alloc); 261void *salloc_ (int n) throw (std::bad_alloc);
248void *salloc_ (int n, void *src) throw (std::bad_alloc); 262void *salloc_ (int n, void *src) throw (std::bad_alloc);
249 263
559 // FNV-1a is faster on many cpus because the multiplication 573 // FNV-1a is faster on many cpus because the multiplication
560 // runs concurrently with the looping logic. 574 // runs concurrently with the looping logic.
561 uint32_t hash = STRHSH_NULL; 575 uint32_t hash = STRHSH_NULL;
562 576
563 while (*s) 577 while (*s)
564 hash = (hash ^ *s++) * 16777619; 578 hash = (hash ^ *s++) * 16777619U;
565 579
566 return hash; 580 return hash;
567} 581}
568 582
569static inline uint32_t 583static inline uint32_t
570memhsh (const char *s, size_t len) 584memhsh (const char *s, size_t len)
571{ 585{
572 uint32_t hash = STRHSH_NULL; 586 uint32_t hash = STRHSH_NULL;
573 587
574 while (len--) 588 while (len--)
575 hash = (hash ^ *s++) * 16777619; 589 hash = (hash ^ *s++) * 16777619U;
576 590
577 return hash; 591 return hash;
578} 592}
579 593
580struct str_hash 594struct str_hash

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines