Changes between Version 1 and Version 2 of PortableRrdFormat
- Timestamp:
- Jun 20, 2007, 9:47:35 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PortableRrdFormat
v1 v2 9 9 There are some provisions in RRD to detect such cross architecture access. But detection is not perfect. Some combinations are bound to even almost work. SPARC to PPC only differs in the representation of NANs. 10 10 11 == Creating a portable RRD format==11 == Figuring 64bit Floating Point Numbers == 12 12 13 13 The portable RRD format works on all platforms transparently. The first Idea was to use Suns XDR format for RRD. Unfortunately, XDR does not handle NANs which are pretty essential for RRDtool. So I did some investigations into binary representation of IEEE 754 floating point data. I found that it is actually pretty simple to bridge the gap between sparc, ppc and x86 at least, so I assume it won't be rocket science todo other CPUs as well. The following program helped a lot in this task. It shows the binary representation of a few 'interesting' floating point values. … … 19 19 typedef union INSPECTOR { 20 20 uint8_t b[8]; 21 uint64_t l; 21 22 double f; 22 23 } INSPECTOR; … … 42 43 }}} 43 44 44 I used this to figure the floating point representation for a number of differentarchitectures:45 I used this to figure the binary representation of double precision floating point numbers on several architectures: 45 46 46 47 SPARC 32 and 64 bit: … … 88 89 8.642135e+130 -> 2f 25 c0 c7 43 2b 1f 5b 89 90 }}} 91 92 As you can see, there is not all that much difference between the architectures (it is all IEEE 754 after all). For one there is the endianess difference and then there are the SPARCs how seem to have their own idea regarding NANs. In any event, a converter between these formats is only a few defines away. 93 94 {{{ 95 #define endianflip(A) ((((uint64_t)(A) & 0xff00000000000000LL) >> 56) | \ 96 (((uint64_t)(A) & 0x00ff000000000000LL) >> 40) | \ 97 (((uint64_t)(A) & 0x0000ff0000000000LL) >> 24) | \ 98 (((uint64_t)(A) & 0x000000ff00000000LL) >> 8) | \ 99 (((uint64_t)(A) & 0x00000000ff000000LL) << 8) | \ 100 (((uint64_t)(A) & 0x0000000000ff0000LL) << 24) | \ 101 (((uint64_t)(A) & 0x000000000000ff00LL) << 40) | \ 102 (((uint64_t)(A) & 0x00000000000000ffLL) << 56)) 103 104 #define sparc2x86(A) ((uint64_t)(A) == 0x7fffffffffffffffLL \ 105 ? 0x000000000000f87fLL \ 106 : endianflip(A)) 107 108 #define x862sparc(A) ((uint64_t)(A) == 0x000000000000f87fLL \ 109 ? 0x7fffffffffffffffLL \ 110 : endianflip(A)) 111 112 #define ppc2x86(A) endianflip(A) 113 114 #define x862ppc(A) endianflip(A) 115 }}} 116 117 == Data alignment differences == 118 119 Most of todays workstations run either 32 or 64 bit. This also influences the structure.