diff options
author | Joshua Haberman <jhaberman@gmail.com> | 2019-03-14 09:53:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 09:53:29 -0700 |
commit | 9cd426495e9ce11e8896a576601fab97052276c4 (patch) | |
tree | 21ceb38f639c8e96fd11d180b5985b478a263072 /upb/pb/varint.int.h | |
parent | ed9faae0993704b033c594b072d65e1bf19207fa (diff) | |
parent | 17db3722678f2ea11edbe2aeb34efdbce030c07f (diff) |
Merge pull request #151 from linux-on-ibm-z/master
Adding support for big endian platform (s390x)
Diffstat (limited to 'upb/pb/varint.int.h')
-rw-r--r-- | upb/pb/varint.int.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/upb/pb/varint.int.h b/upb/pb/varint.int.h index 9c54311..b216a94 100644 --- a/upb/pb/varint.int.h +++ b/upb/pb/varint.int.h @@ -24,6 +24,18 @@ extern "C" { * descriptor type (upb_descriptortype_t). */ extern const uint8_t upb_pb_native_wire_types[]; +UPB_INLINE uint64_t byteswap64(uint64_t val) +{ + return ((((val) & 0xff00000000000000ull) >> 56) + | (((val) & 0x00ff000000000000ull) >> 40) + | (((val) & 0x0000ff0000000000ull) >> 24) + | (((val) & 0x000000ff00000000ull) >> 8) + | (((val) & 0x00000000ff000000ull) << 8) + | (((val) & 0x0000000000ff0000ull) << 24) + | (((val) & 0x000000000000ff00ull) << 40) + | (((val) & 0x00000000000000ffull) << 56)); +} + /* Zig-zag encoding/decoding **************************************************/ UPB_INLINE int32_t upb_zzdec_32(uint32_t n) { @@ -130,6 +142,9 @@ UPB_INLINE uint64_t upb_vencode32(uint32_t val) { uint64_t ret = 0; UPB_ASSERT(bytes <= 5); memcpy(&ret, buf, bytes); +#ifdef UPB_BIG_ENDIAN + ret = byteswap64(ret); +#endif UPB_ASSERT(ret <= 0xffffffffffU); return ret; } |