blob: 1fe49b75bb5fe3e3a0eeaeaf7e1eb6ba797c50ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#ifndef TENSORFLOW_LIB_CORE_RAW_CODING_H_
#define TENSORFLOW_LIB_CORE_RAW_CODING_H_
#include <string.h>
#include "tensorflow/core/platform/port.h"
namespace tensorflow {
namespace core {
// Lower-level versions of Get... that read directly from a character buffer
// without any bounds checking.
inline uint32 DecodeFixed32(const char* ptr) {
if (port::kLittleEndian) {
// Load the raw bytes
uint32 result;
memcpy(&result, ptr, sizeof(result)); // gcc optimizes this to a plain load
return result;
} else {
return ((static_cast<uint32>(static_cast<unsigned char>(ptr[0]))) |
(static_cast<uint32>(static_cast<unsigned char>(ptr[1])) << 8) |
(static_cast<uint32>(static_cast<unsigned char>(ptr[2])) << 16) |
(static_cast<uint32>(static_cast<unsigned char>(ptr[3])) << 24));
}
}
inline uint64 DecodeFixed64(const char* ptr) {
if (port::kLittleEndian) {
// Load the raw bytes
uint64 result;
memcpy(&result, ptr, sizeof(result)); // gcc optimizes this to a plain load
return result;
} else {
uint64 lo = DecodeFixed32(ptr);
uint64 hi = DecodeFixed32(ptr + 4);
return (hi << 32) | lo;
}
}
} // namespace core
} // namespace tensorflow
#endif // TENSORFLOW_LIB_CORE_RAW_CODING_H_
|