From 40a6ba5c0a5f544bed9c11dc30b751e05a435b1e Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sun, 26 Oct 2014 23:33:50 -0500 Subject: Split helper functions into their own translation units --- swap.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 swap.c (limited to 'swap.c') diff --git a/swap.c b/swap.c new file mode 100644 index 0000000..626abb0 --- /dev/null +++ b/swap.c @@ -0,0 +1,27 @@ +#include +#include + +#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; + } +} -- cgit v1.2.3