--- deliantra/server/include/util.h 2009/11/10 00:01:31 1.95 +++ deliantra/server/include/util.h 2010/04/02 03:41:24 1.98 @@ -1,7 +1,7 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -242,6 +242,20 @@ return ((d - 1) & 7) + 1; } +// avoid ctz name because netbsd or freebsd spams it's namespace with it +#if GCC_VERSION(3,4) +static inline int least_significant_bit (uint32_t x) +{ + return __builtin_ctz (x); +} +#else +int least_significant_bit (uint32_t x); +#endif + +#define for_all_bits_sparse_32(mask, idxvar) \ + for (uint32_t idxvar, mask_ = mask; \ + mask_ && ((idxvar = least_significant_bit (mask_)), mask_ &= ~(1 << idxvar), 1);) + extern ssize_t slice_alloc; // statistics void *salloc_ (int n) throw (std::bad_alloc); @@ -561,7 +575,7 @@ uint32_t hash = STRHSH_NULL; while (*s) - hash = (hash ^ *s++) * 16777619; + hash = (hash ^ *s++) * 16777619U; return hash; } @@ -572,7 +586,7 @@ uint32_t hash = STRHSH_NULL; while (len--) - hash = (hash ^ *s++) * 16777619; + hash = (hash ^ *s++) * 16777619U; return hash; }