[cfe-commits] r62447 - /cfe/trunk/lib/Lex/PTHLexer.cpp
Chris Lattner
sabre at nondot.org
Sat Jan 17 18:19:17 PST 2009
Author: lattner
Date: Sat Jan 17 20:19:16 2009
New Revision: 62447
URL: http://llvm.org/viewvc/llvm-project?rev=62447&view=rev
Log:
On i386 and x86-64, just do unaligned loads
instead of assembling from bytes. This speeds up -Eonly PTH reading
of cocoa.h by about 2ms, which is 4.2%.
Modified:
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=62447&r1=62446&r2=62447&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Sat Jan 17 20:19:16 2009
@@ -38,25 +38,45 @@
}
static inline uint16_t Read16(const unsigned char *&Data) {
+// Targets that directly support unaligned little-endian 16-bit loads can just
+// use them.
+#if defined(__i386__) || defined(__x86_64__)
+ uint16_t V = *((uint16_t*)Data);
+#else
uint16_t V = ((uint16_t)Data[0] << 0) |
((uint16_t)Data[1] << 8);
+#endif
Data += 2;
return V;
}
static inline uint32_t Read24(const unsigned char *&Data) {
+// Targets that directly support unaligned little-endian 16-bit loads can just
+// use them.
+#if defined(__i386__) || defined(__x86_64__)
+ uint32_t V = ((uint16_t*)Data)[0] |
+ ((uint32_t)Data[2] << 16);
+#else
uint32_t V = ((uint32_t)Data[0] << 0) |
((uint32_t)Data[1] << 8) |
((uint32_t)Data[2] << 16);
+#endif
+
Data += 3;
return V;
}
static inline uint32_t Read32(const unsigned char *&Data) {
+// Targets that directly support unaligned little-endian 32-bit loads can just
+// use them.
+#if defined(__i386__) || defined(__x86_64__)
+ uint32_t V = *((uint32_t*)Data);
+#else
uint32_t V = ((uint32_t)Data[0] << 0) |
((uint32_t)Data[1] << 8) |
((uint32_t)Data[2] << 16) |
((uint32_t)Data[3] << 24);
+#endif
Data += 4;
return V;
}
More information about the cfe-commits
mailing list