diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2014-10-26 23:33:50 -0500 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2014-10-26 23:33:50 -0500 |
commit | 40a6ba5c0a5f544bed9c11dc30b751e05a435b1e (patch) | |
tree | 796861388460ebfe3571ebc0699c3834d6eb83cf /swap.c | |
parent | 1e3548b039bd6b760ca3fe716c98065735110f58 (diff) |
Split helper functions into their own translation units
Diffstat (limited to 'swap.c')
-rw-r--r-- | swap.c | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -0,0 +1,27 @@ +#include <stddef.h> +#include <stdint.h> + +#include "common.h" + +void swap(char *a, char *b, size_t width) +{ +#ifdef __GNUC__ + typedef uint32_t __attribute__((__may_alias__)) u32; + + if ((uintptr_t)a % 4 == 0 && (uintptr_t)b % 4 == 0) { + for (; width >= 4; width -= 4) { + uint32_t tmp = *((u32*)a); + *((u32*)a) = *((u32*)b); + *((u32*)b) = tmp; + a += 4; + b += 4; + } + } +#endif + + while (width--) { + char tmp = *a; + *a++ = *b; + *b++ = tmp; + } +} |