--- sswf-1.8.0-old/src/lib/libsswf_util.c++ 2006-11-28 09:08:07.000000000 +0100 +++ sswf-1.8.0/src/lib/libsswf_util.c++ 2007-04-03 04:31:15.000000000 +0200 @@ -1,8 +1,8 @@ -/* libsswf_utils.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2006 */ +/* libsswf_utils.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2007 */ /* -Copyright (c) 2002-2006 Made to Order Software Corp. +Copyright (c) 2002-2007 Made to Order Software Corp. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and @@ -493,9 +493,17 @@ using namespace sswf; * The swap() function swaps the content of buffer s1 with buffer s2. * 'size' bytes are swapped. * + * If you have a 64 bits system, s1 and s2 both point to a 64 bit value + * and the size is a multiple of 8 bytes, then the swap is done 64 bits + * at a time. + * * If s1 and s2 both point to a 32 bit value and the size is a multiple - * of 4 bytes, then the swap is done 32 bits at a time. Otherwise the - * default 8 bits at a time function is used. + * of 4 bytes, then the swap is done 32 bits at a time. + * + * Otherwise the 8 bits (1 byte) at a time function is used. + * + * \note + * Modifications to support 64-bit by Fabio A. Correa <facorread at gmail> * * \param s1 One of the buffers to swap * \param s2 One of the buffers to swap @@ -509,7 +517,21 @@ void sswf::swap(void *s1, void *s2, size if(size == 0) { return; } - if((size & 3) == 0 && (((int32_t) s1) & 3) == 0 && (((int32_t) s2) & 3) == 0) { + // on 64 bits systems, swap 64 bits at once + if(sizeof(void *) == 8 && (size & 7) == 0 && (((intptr_t) s1) & 7) == 0 && (((intptr_t) s2) & 7) == 0) { + int64_t a; + + assert(sizeof(int64_t) == 8, "the swap() function assumes that the sizeof(int64_t) == 8...\n"); + do { + a = * (int64_t *) s1; + * (int64_t *) s1 = * (int64_t *) s2; + * (int64_t *) s2 = a; + s1 = (int64_t *) s1 + 1; + s2 = (int64_t *) s2 + 1; + size -= sizeof(int64_t); + } while(size > 0); + } + else if((size & 3) == 0 && (((intptr_t) s1) & 3) == 0 && (((intptr_t) s2) & 3) == 0) { int32_t a; assert(sizeof(int32_t) == 4, "the swap() function assumes that the sizeof(int32_t) == 4...\n");