| 122 | } |
| 123 | |
| 124 | inline uint64_t DecodeFixed64(const char* ptr) { |
| 125 | const uint8_t* const buffer = reinterpret_cast<const uint8_t*>(ptr); |
| 126 | |
| 127 | if (port::kLittleEndian) { |
| 128 | // Fast path for little-endian CPUs. All major compilers optimize this to a |
| 129 | // single mov (x86_64) / ldr (ARM) instruction. |
| 130 | uint64_t result; |
| 131 | std::memcpy(&result, buffer, sizeof(uint64_t)); |
| 132 | return result; |
| 133 | } |
| 134 | |
| 135 | // Platform-independent code. |
| 136 | // Clang and gcc optimize this to a single mov / ldr instruction. |
| 137 | return (static_cast<uint64_t>(buffer[0])) | |
| 138 | (static_cast<uint64_t>(buffer[1]) << 8) | |
| 139 | (static_cast<uint64_t>(buffer[2]) << 16) | |
| 140 | (static_cast<uint64_t>(buffer[3]) << 24) | |
| 141 | (static_cast<uint64_t>(buffer[4]) << 32) | |
| 142 | (static_cast<uint64_t>(buffer[5]) << 40) | |
| 143 | (static_cast<uint64_t>(buffer[6]) << 48) | |
| 144 | (static_cast<uint64_t>(buffer[7]) << 56); |
| 145 | } |
| 146 | |
| 147 | // Internal routine for use by fallback path of GetVarint32Ptr |
| 148 | const char* GetVarint32PtrFallback(const char* p, const char* limit, |
no outgoing calls