Derecho  0.9
Distributed systems toolkit for RDMA
version_code.cpp
Go to the documentation of this file.
3 #include <functional>
4 
6 uint64_t mix(uint64_t v1, uint64_t v2) {
7  return v1 * 37 ^ v2;
8 }
9 
10 #define ISGNU 0
11 #define ISCLANG (1 << 32)
12 #if defined __GNUC__ && defined __GNUC_MINOR__
13 const uint64_t compiler = ISGNU | ((__GNUC__ << 16) + __GNUC_MINOR__);
14 #else
15 const uint64_t compiler = ISCLANG | (__clang_major__ << 16) + __clang_minor__ );
16 #endif
17 
18 const uint64_t derecho_version = ((((static_cast<uint64_t>(derecho::MAJOR_VERSION) << 16)
20  << 32)
22 
23 /*
24  * The following variables are for detection of Endian order for integers.
25  * The reason we do this at runtime and NOT compile time is to catch cases
26  * where code is compiled for platform A but then copied (incorrectly) to
27  * platform B. Of course it might simply seg fault. But if it manages to launch
28  * this way of checking would notice.
29  */
30 char int16_array[2]{1, 2};
31 char int32_array[4]{1, 2, 3, 4};
32 char int64_array[8]{1, 2, 3, 4, 5, 6, 7, 8};
33 
34 // Runtime detection of floating point storage order
35 float a_float = 123.4560001;
36 double a_double = 654.3210000987;
37 
38 struct s1 {
39  char something;
40  int16_t the_int;
41 };
42 const uint64_t int16_offset = (uint64_t)offsetof(struct s1, the_int);
43 
44 struct s2 {
45  char something;
46  int32_t the_int;
47 };
48 const uint64_t int32_offset = (uint64_t)offsetof(struct s2, the_int);
49 
50 struct s3 {
51  char something;
52  int64_t the_int;
53 };
54 
55 const uint64_t int64_offset1 = (uint64_t)offsetof(struct s3, the_int);
56 
57 struct s4 {
58  char something;
59  float fsomething;
60  int64_t the_int;
61 };
62 const uint64_t int64_offset2 = (uint64_t)offsetof(struct s4, the_int);
63 
64 struct s5 {
65  char something;
66  double dsomething;
67  int64_t the_int;
68 };
69 
70 const uint64_t int64_offset3 = (uint64_t)offsetof(struct s5, the_int);
71 
72 uint64_t int_offset_hash = mix(int64_offset3,
73  mix(int64_offset2,
74  mix(int64_offset1,
75  mix(int32_offset, int16_offset))));
76 
77 /*
78  * The above definitions and variables can be in "global namespace" because they
79  * are not used outside this file, but the final hashcode and function must be
80  * properly encapsulated in a namespace because they are externally visible.
81  */
82 
83 namespace derecho {
84 
85 // This function combines all the measurements defined above, using the "mix" function
86 uint64_t version_hashcode() {
87  return mix(mix(mix(mix(mix(mix(mix(std::hash<uint64_t>()(compiler),
88  std::hash<uint64_t>()(derecho_version)),
89  *reinterpret_cast<uint16_t*>(&int16_array)),
90  *reinterpret_cast<uint32_t*>(&int32_array)),
91  *reinterpret_cast<uint64_t*>(&int64_array)),
92  *reinterpret_cast<uint32_t*>(&a_float)),
93  *reinterpret_cast<uint64_t*>(&a_double)),
94  int_offset_hash);
95 }
96 
97 // Run the function once and cache the result in a global variable
99 
100 } // namespace derecho
uint64_t version_hashcode()
The function that computes the Derecho version hashcode.
uint64_t int_offset_hash
const uint64_t int16_offset
char int32_array[4]
float a_float
char int64_array[8]
const uint64_t derecho_version
const uint64_t int64_offset2
const int COMMITS_AHEAD_OF_VERSION
If the currently-compiled version of the Derecho library is more recent than the last "release" versi...
Definition: git_version.cpp:35
int32_t the_int
uint64_t mix(uint64_t v1, uint64_t v2)
A simple hash-combine function to "mix" two hashcodes.
Definition: version_code.cpp:6
const uint64_t int64_offset1
char something
char int16_array[2]
uint64_t my_version_hashcode
A runtime constant (computed once during static initialization) that represents the current running v...
int16_t the_int
int64_t the_int
float fsomething
#define ISCLANG
#define ISGNU
double a_double
const int MAJOR_VERSION
The current major version number of the Derecho library, as defined by Git.
Definition: git_version.cpp:32
const uint64_t compiler
char something
const uint64_t int64_offset3
const uint64_t int32_offset
double dsomething
int64_t the_int
const int MINOR_VERSION
The current minor version number of the Derecho library, as defined by Git.
Definition: git_version.cpp:33
int64_t the_int
char something
char something
char something