Created
March 2, 2012 10:26
-
-
Save pwl/1957567 to your computer and use it in GitHub Desktop.
memory alignment of binary128
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include <endian.h> | |
typedef union | |
{ | |
__float128 val; | |
struct | |
{ | |
#if __BYTE_ORDER == __BIG_ENDIAN | |
uint64_t sign : 1; | |
uint64_t exp : 15; | |
uint64_t frac1 : 48; | |
uint64_t frac0 : 64; | |
#else | |
uint64_t frac0 : 64; | |
uint64_t frac1 : 48; | |
uint64_t exp : 15; | |
uint64_t sign : 1; | |
#endif | |
} bits; | |
} qfloat; | |
int main() | |
{ | |
qfloat foo; | |
qfloat bar; | |
foo.val = 65536.0; | |
foo.val += 1.0; | |
foo.val *= foo.val; | |
bar.val = 8191.0; | |
printf("%04X %012llX %016llX\n", (uint16_t)foo.bits.exp, (uint64_t)foo.bits.frac1, foo.bits.frac0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment