aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-03-08 23:14:03 +0000
committerlloyd <[email protected]>2008-03-08 23:14:03 +0000
commit05bb536fbebb4e856bbcf15e3bc5f8df6d7fb48f (patch)
tree66c0024d7d0bf6cace06970d1c55b71af45138d4
parent90be13de6fa5fb2778b5d6d296c81fd0e9393b97 (diff)
Put reverse_bytes into bit_ops.h so they can be inlined. Rewrite the version
for 64-bit to not use 64-bit constants - that way GCC won't complain everwhere. Plan is for a module to replace all of these with asm (bswap, xchg on x86), at least for x86-64
-rw-r--r--include/bit_ops.h21
-rw-r--r--src/bit_ops.cpp29
2 files changed, 17 insertions, 33 deletions
diff --git a/include/bit_ops.h b/include/bit_ops.h
index 3576f8ce1..d0fb03d1f 100644
--- a/include/bit_ops.h
+++ b/include/bit_ops.h
@@ -24,11 +24,24 @@ template<typename T> inline T rotate_right(T input, u32bit rot)
}
/*************************************************
-* Byteswap *
+* Byte Swapping Functions *
*************************************************/
-u16bit reverse_bytes(u16bit);
-u32bit reverse_bytes(u32bit);
-u64bit reverse_bytes(u64bit);
+inline u16bit reverse_bytes(u16bit input)
+ {
+ return rotate_left(input, 8);
+ }
+
+inline u32bit reverse_bytes(u32bit input)
+ {
+ input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
+ return rotate_left(input, 16);
+ }
+
+inline u64bit reverse_bytes(u64bit input)
+ {
+ return rotate_left(static_cast<u32bit>(input ), 16) |
+ rotate_left(static_cast<u32bit>(input >> 32), 16);
+ }
/*************************************************
* Array XOR *
diff --git a/src/bit_ops.cpp b/src/bit_ops.cpp
index dad2b0fb9..2db947d01 100644
--- a/src/bit_ops.cpp
+++ b/src/bit_ops.cpp
@@ -43,35 +43,6 @@ void xor_buf(byte out[], const byte in[], const byte mask[], u32bit length)
}
/*************************************************
-* Reverse bytes *
-*************************************************/
-u16bit reverse_bytes(u16bit input)
- {
- return rotate_left(input, 8);
- }
-
-/*************************************************
-* Reverse bytes *
-*************************************************/
-u32bit reverse_bytes(u32bit input)
- {
- input = ((input & 0xFF00FF00) >> 8) | ((input & 0x00FF00FF) << 8);
- return rotate_left(input, 16);
- }
-
-/*************************************************
-* Reverse bytes *
-*************************************************/
-u64bit reverse_bytes(u64bit input)
- {
- input = ((input & 0xFF00FF00FF00FF00) >> 8) |
- ((input & 0x00FF00FF00FF00FF) << 8);
- input = ((input & 0xFFFF0000FFFF0000) >> 16) |
- ((input & 0x0000FFFF0000FFFF) << 16);
- return rotate_left(input, 32);
- }
-
-/*************************************************
* Return true iff arg is 2**n for some n > 0 *
*************************************************/
bool power_of_2(u64bit arg)