r205250 - MS ABI: Simplify endian swapping code

David Majnemer david.majnemer at gmail.com
Mon Mar 31 14:46:05 PDT 2014


Author: majnemer
Date: Mon Mar 31 16:46:05 2014
New Revision: 205250

URL: http://llvm.org/viewvc/llvm-project?rev=205250&view=rev
Log:
MS ABI: Simplify endian swapping code

No functionality change.

Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=205250&r1=205249&r2=205250&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon Mar 31 16:46:05 2014
@@ -2388,31 +2388,15 @@ void MicrosoftMangleContextImpl::mangleS
   auto GetLittleEndianByte = [&Mangler, &SL](unsigned Index) {
     unsigned CharByteWidth = SL->getCharByteWidth();
     uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth);
-    if (CharByteWidth == 1) {
-      return static_cast<char>(CodeUnit);
-    } else if (CharByteWidth == 2) {
-      if (Index % 2)
-        return static_cast<char>((CodeUnit >> 8) & 0xff);
-      else
-        return static_cast<char>(CodeUnit & 0xff);
-    } else {
-      llvm_unreachable("unsupported CharByteWidth");
-    }
+    unsigned OffsetInCodeUnit = Index % CharByteWidth;
+    return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
   };
 
   auto GetBigEndianByte = [&Mangler, &SL](unsigned Index) {
     unsigned CharByteWidth = SL->getCharByteWidth();
     uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth);
-    if (CharByteWidth == 1) {
-      return static_cast<char>(CodeUnit);
-    } else if (CharByteWidth == 2) {
-      if (Index % 2)
-        return static_cast<char>(CodeUnit & 0xff);
-      else
-        return static_cast<char>((CodeUnit >> 8) & 0xff);
-    } else {
-      llvm_unreachable("unsupported CharByteWidth");
-    }
+    unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth);
+    return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
   };
 
   // CRC all the bytes of the StringLiteral.





More information about the cfe-commits mailing list