Commit ea7d0656 authored by John Esmet's avatar John Esmet Committed by Yoni Fogel

refs #5629 make sure we have 64 bit versions and there is a test for it


git-svn-id: file:///svn/toku/tokudb@50318 c7de825b-a66e-492c-adef-691d508d4ae1
parent c4a230cb
/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
// vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
#ident "$Id: test-pagesize.cc 45903 2012-07-19 13:06:39Z leifwalsh $"
#ident "Copyright (c) 2007-2012 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
#include <toku_assert.h>
#include <portability/toku_htonl.h>
static void test32(void) {
uint32_t k = 0xDEADBEEF;
uint32_t n_k = toku_htonl(k);
const int num_bytes = 4;
for (int i = 0; i < num_bytes; i++) {
unsigned char *c = (unsigned char *) &k;
unsigned char *n_c = (unsigned char *) &n_k;
invariant(c[i] == n_c[(num_bytes - 1) - i]);
}
}
static void test64(void) {
uint64_t k = 0xDEADBEEFABCDBADC;
uint64_t n_k = toku_htonl64(k);
const int num_bytes = 8;
for (int i = 0; i < num_bytes; i++) {
unsigned char *c = (unsigned char *) &k;
unsigned char *n_c = (unsigned char *) &n_k;
invariant(c[i] == n_c[(num_bytes - 1)- i]);
}
}
int main(void) {
test32();
test64();
return 0;
}
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
//#error //#error
#endif #endif
// TODO: This byte order stuff should all be in once place (ie: portability layer, not toku_include)
#include <stdint.h> #include <toku_htod.h>
#include <arpa/inet.h> #include <arpa/inet.h>
static inline uint32_t toku_htonl(uint32_t i) { static inline uint32_t toku_htonl(uint32_t i) {
...@@ -23,15 +23,23 @@ static inline uint32_t toku_ntohl(uint32_t i) { ...@@ -23,15 +23,23 @@ static inline uint32_t toku_ntohl(uint32_t i) {
} }
static inline uint64_t toku_htonl64(uint64_t i) { static inline uint64_t toku_htonl64(uint64_t i) {
#if HOST_BYTE_ORDER != NETWORK_BYTE_ORDER
uint64_t a = ((uint64_t) htonl(i & 0xFFFFFFFF)) << 32; uint64_t a = ((uint64_t) htonl(i & 0xFFFFFFFF)) << 32;
uint64_t b = htonl(i >> 32); uint64_t b = htonl(i >> 32);
return a | b; return a | b;
#else
return i;
#endif
} }
static inline uint64_t toku_ntohl64(uint64_t i) { static inline uint64_t toku_ntohl64(uint64_t i) {
#if HOST_BYTE_ORDER != NETWORK_BYTE_ORDER
uint64_t a = ((uint64_t) ntohl(i & 0xFFFFFFFF)) << 32; uint64_t a = ((uint64_t) ntohl(i & 0xFFFFFFFF)) << 32;
uint64_t b = ntohl(i >> 32); uint64_t b = ntohl(i >> 32);
return a | b; return a | b;
#else
return i;
#endif
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment