add: fast reverse 16bit

This commit is contained in:
iceman1001
2018-01-27 23:16:35 +01:00
parent e76b4f93b8
commit e396575424
4 changed files with 27 additions and 6 deletions

View File

@@ -741,6 +741,27 @@ uint32_t SwapBits(uint32_t v, int b) {
uint8_t reflect8(uint8_t b) {
return ((b * 0x80200802ULL) & 0x0884422110ULL) * 0x0101010101ULL >> 32;
}
uint16_t reflect16(uint16_t b) {
uint16_t v = 0;
v |= (b & 0x8000) >> 15;
v |= (b & 0x4000) >> 13;
v |= (b & 0x2000) >> 11;
v |= (b & 0x1000) >> 9;
v |= (b & 0x0800) >> 7;
v |= (b & 0x0400) >> 5;
v |= (b & 0x0200) >> 3;
v |= (b & 0x0100) >> 1;
v |= (b & 0x0080) << 1;
v |= (b & 0x0040) << 3;
v |= (b & 0x0020) << 5;
v |= (b & 0x0010) << 7;
v |= (b & 0x0008) << 9;
v |= (b & 0x0004) << 11;
v |= (b & 0x0002) << 13;
v |= (b & 0x0001) << 15;
return v;
}
/*
ref http://www.csm.ornl.gov/~dunigan/crc.html
Returns the value v with the bottom b [0,32] bits reflected.

View File

@@ -204,7 +204,8 @@ extern uint32_t PackBits(uint8_t start, uint8_t len, uint8_t* bits);
extern void rol(uint8_t *data, const size_t len);
extern uint32_t SwapBits(uint32_t value, int nrbits);
extern uint32_t reflect(uint32_t v, int b);
extern uint8_t reflect8(uint8_t b); // dedicated 8bit reversal
extern uint8_t reflect8(uint8_t b); // dedicated 8bit reversal
extern uint16_t reflect16(uint16_t b); // dedicated 16bit reversal
extern uint64_t HornerScheme(uint64_t num, uint64_t divider, uint64_t factor);
extern int num_CPUs(void); // number of logical CPUs