src/core/bitmath_func.hpp
changeset 8628 4e316518420a
parent 8609 8c0c3e9dd6a0
child 10429 1b99254f9607
equal deleted inserted replaced
8627:448ebf3a8291 8628:4e316518420a
   289  */
   289  */
   290 #define FOR_EACH_SET_BIT(i, b)      \
   290 #define FOR_EACH_SET_BIT(i, b)      \
   291 	for (i = 0; b != 0; i++, b >>= 1) \
   291 	for (i = 0; b != 0; i++, b >>= 1) \
   292 		if (b & 1)
   292 		if (b & 1)
   293 
   293 
       
   294 
       
   295 #if defined(__APPLE__)
       
   296 	/* Make endian swapping use Apple's macros to increase speed
       
   297 	 * (since it will use hardware swapping if available).
       
   298 	 * Even though they should return uint16 and uint32, we get
       
   299 	 * warnings if we don't cast those (why?) */
       
   300 	#define BSWAP32(x) ((uint32)Endian32_Swap(x))
       
   301 	#define BSWAP16(x) ((uint16)Endian16_Swap(x))
       
   302 #else
       
   303 	/**
       
   304 	 * Perform a 32 bits endianness bitswap on x.
       
   305 	 * @param x the variable to bitswap
       
   306 	 * @return the bitswapped value.
       
   307 	 */
       
   308 	static inline uint32 BSWAP32(uint32 x)
       
   309 	{
       
   310 		return ((x >> 24) & 0xFF) | ((x >> 8) & 0xFF00) | ((x << 8) & 0xFF0000) | ((x << 24) & 0xFF000000);
       
   311 	}
       
   312 
       
   313 	/**
       
   314 	 * Perform a 16 bits endianness bitswap on x.
       
   315 	 * @param x the variable to bitswap
       
   316 	 * @return the bitswapped value.
       
   317 	 */
       
   318 	static inline uint16 BSWAP16(uint16 x)
       
   319 	{
       
   320 		return (x >> 8) | (x << 8);
       
   321 	}
       
   322 #endif /* __APPLE__ */
       
   323 
   294 #endif /* BITMATH_FUNC_HPP */
   324 #endif /* BITMATH_FUNC_HPP */