[llvm-commits] CVS: llvm/include/llvm/Support/MathExtras.h

Nate Begeman natebegeman at mac.com
Fri Jan 13 17:25:39 PST 2006



Changes in directory llvm/include/llvm/Support:

MathExtras.h updated: 1.27 -> 1.28
---
Log message:

Add bswap intrinsics as documented in the Language Reference


---
Diffs of the changes:  (+26 -0)

 MathExtras.h |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+)


Index: llvm/include/llvm/Support/MathExtras.h
diff -u llvm/include/llvm/Support/MathExtras.h:1.27 llvm/include/llvm/Support/MathExtras.h:1.28
--- llvm/include/llvm/Support/MathExtras.h:1.27	Fri Oct  7 00:29:25 2005
+++ llvm/include/llvm/Support/MathExtras.h	Fri Jan 13 19:25:24 2006
@@ -79,6 +79,32 @@
   return Value && !(Value & (Value - 1LL));
 }
 
+// ByteSwap_16 - This function returns a byte-swapped representation of the
+// 16-bit argument, Value.
+inline unsigned short ByteSwap_16(unsigned short Value) {
+  unsigned short Hi = Value << 8;
+  unsigned short Lo = Value >> 8;
+  return Hi | Lo;
+}
+
+// ByteSwap_32 - This function returns a byte-swapped representation of the
+// 32-bit argument, Value.
+inline unsigned ByteSwap_32(unsigned Value) {
+  unsigned Byte0 = Value & 0x000000FF;
+  unsigned Byte1 = Value & 0x0000FF00;
+  unsigned Byte2 = Value & 0x00FF0000;
+  unsigned Byte3 = Value & 0xFF000000;
+  return (Byte0 << 24) | (Byte1 << 8) | (Byte2 >> 8) | (Byte3 >> 24);
+}
+
+// ByteSwap_64 - This function returns a byte-swapped representation of the
+// 64-bit argument, Value.
+inline uint64_t ByteSwap_64(uint64_t Value) {
+  uint64_t Hi = ByteSwap_32(Value);
+  uint64_t Lo = ByteSwap_32(Value >> 32);
+  return (Hi << 32) | Lo;
+}
+
 // CountLeadingZeros_32 - this function performs the platform optimal form of
 // counting the number of zeros from the most significant bit to the first one
 // bit.  Ex. CountLeadingZeros_32(0x00F000FF) == 8.






More information about the llvm-commits mailing list