diff options
author | Keith Packard <keithp@keithp.com> | 2013-07-11 16:09:34 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-10-31 16:58:18 -0700 |
commit | 0c33f47281c36726848daf513fb0483cdea57bff (patch) | |
tree | 6db949fbd83817cd6321e023c3aaf827b7bede42 /include/misc.h | |
parent | 26f013ba45b08a02bb028a461af68288a86fadb1 (diff) |
Add swapll to byte swap 64-bit datatypes
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'include/misc.h')
-rw-r--r-- | include/misc.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/misc.h b/include/misc.h index 0c67f11fe..17de71041 100644 --- a/include/misc.h +++ b/include/misc.h @@ -305,6 +305,35 @@ __builtin_constant_p(int x) } #endif +/* byte swap a 64-bit value */ +static inline void +swap_uint64(uint64_t *x) +{ + char n; + + n = ((char *) x)[0]; + ((char *) x)[0] = ((char *) x)[7]; + ((char *) x)[7] = n; + + n = ((char *) x)[1]; + ((char *) x)[1] = ((char *) x)[6]; + ((char *) x)[6] = n; + + n = ((char *) x)[2]; + ((char *) x)[2] = ((char *) x)[5]; + ((char *) x)[5] = n; + + n = ((char *) x)[3]; + ((char *) x)[3] = ((char *) x)[4]; + ((char *) x)[4] = n; +} + +#define swapll(x) do { \ + if (sizeof(*(x)) != 8) \ + wrong_size(); \ + swap_uint64((uint64_t *)(x)); \ + } while (0) + /* byte swap a 32-bit value */ static inline void swap_uint32(uint32_t * x) |