diff options
author | Eric Andersen <andersen@codepoet.org> | 2002-04-06 00:07:58 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2002-04-06 00:07:58 +0000 |
commit | f19b4d2f61aeafa443e45cee1229c9463e62fc8d (patch) | |
tree | 8466d7cb03612cfa90a19005f8d5c8092fdf7fd0 /libc/unistd | |
parent | cb64288cfed3d370f144dcfd2bc76094268019d9 (diff) | |
download | uClibc-alpine-f19b4d2f61aeafa443e45cee1229c9463e62fc8d.tar.bz2 uClibc-alpine-f19b4d2f61aeafa443e45cee1229c9463e62fc8d.tar.xz |
Faster implementation from Miles Bader
Diffstat (limited to 'libc/unistd')
-rw-r--r-- | libc/unistd/swab.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/libc/unistd/swab.c b/libc/unistd/swab.c index c63ca7284..41845d4cb 100644 --- a/libc/unistd/swab.c +++ b/libc/unistd/swab.c @@ -1,18 +1,18 @@ #include <unistd.h> #include <sys/types.h> +#include <byteswap.h> -/* swab() swaps the position of two adjacent bytes, every two bytes. - * Contributed by Kensuke Otake <kensuke@phreaker.net> */ +/* Updated implementation based on byteswap.h from Miles Bader + * <miles@gnu.org>. This should be much faster on arches with machine + * specific, optimized definitions in include/bits/byteswap.h (i.e. on + * x86, use the bswap instruction on i486 and better boxes). For + * platforms that lack such support, this should be no slower than it + * was before... */ +void swab (const void *source, void *dest, ssize_t count) +{ + const unsigned short *from = source, *from_end = from + (count >> 1); + unsigned short *to = dest; -void swab(const void *source, void *dest, ssize_t count) { - const char *from = (const char *)source; - char *to = (char *)dest; - - count &= ~((ssize_t)1); - - while (count > 1) { - const char b0 = from[--count], b1 = from[--count]; - to[count] = b0; - to[count + 1] = b1; - } + while (from < from_end) + *to++ = bswap_16 (*from++); } |