shithub: femtolisp

ref: 51dce20aa4c1560e1f0d9cdc54ff0b2baf86b8eb
dir: /bitreverse.c/

View raw version
#include "platform.h"

uint32_t
__builtin_bitreverse32(uint32_t x)
{
	uint32_t m;

	x = (x >> 16)      | (x << 16);       m = 0xff00ff00;
	x = ((x & m) >> 8) | ((x & ~m) << 8);
	m = 0xf0f0f0f0;
	x = ((x & m) >> 4) | ((x & ~m) << 4); m = 0xcccccccc;
	x = ((x & m) >> 2) | ((x & ~m) << 2); m = 0xaaaaaaaa;
	x = ((x & m) >> 1) | ((x & ~m) << 1);

	return x;
}