Lines 1-8
Link Here
|
1 |
/* libsswf_utils.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2006 */ |
1 |
/* libsswf_utils.c++ -- written by Alexis WILKE for Made to Order Software Corp. (c) 2002-2007 */ |
2 |
|
2 |
|
3 |
/* |
3 |
/* |
4 |
|
4 |
|
5 |
Copyright (c) 2002-2006 Made to Order Software Corp. |
5 |
Copyright (c) 2002-2007 Made to Order Software Corp. |
6 |
|
6 |
|
7 |
Permission is hereby granted, free of charge, to any |
7 |
Permission is hereby granted, free of charge, to any |
8 |
person obtaining a copy of this software and |
8 |
person obtaining a copy of this software and |
Lines 493-501
using namespace sswf;
Link Here
|
493 |
* The swap() function swaps the content of buffer s1 with buffer s2. |
493 |
* The swap() function swaps the content of buffer s1 with buffer s2. |
494 |
* 'size' bytes are swapped. |
494 |
* 'size' bytes are swapped. |
495 |
* |
495 |
* |
|
|
496 |
* If you have a 64 bits system, s1 and s2 both point to a 64 bit value |
497 |
* and the size is a multiple of 8 bytes, then the swap is done 64 bits |
498 |
* at a time. |
499 |
* |
496 |
* If s1 and s2 both point to a 32 bit value and the size is a multiple |
500 |
* If s1 and s2 both point to a 32 bit value and the size is a multiple |
497 |
* of 4 bytes, then the swap is done 32 bits at a time. Otherwise the |
501 |
* of 4 bytes, then the swap is done 32 bits at a time. |
498 |
* default 8 bits at a time function is used. |
502 |
* |
|
|
503 |
* Otherwise the 8 bits (1 byte) at a time function is used. |
504 |
* |
505 |
* \note |
506 |
* Modifications to support 64-bit by Fabio A. Correa <facorread at gmail> |
499 |
* |
507 |
* |
500 |
* \param s1 One of the buffers to swap |
508 |
* \param s1 One of the buffers to swap |
501 |
* \param s2 One of the buffers to swap |
509 |
* \param s2 One of the buffers to swap |
Lines 509-515
void sswf::swap(void *s1, void *s2, size
Link Here
|
509 |
if(size == 0) { |
517 |
if(size == 0) { |
510 |
return; |
518 |
return; |
511 |
} |
519 |
} |
512 |
if((size & 3) == 0 && (((int32_t) s1) & 3) == 0 && (((int32_t) s2) & 3) == 0) { |
520 |
// on 64 bits systems, swap 64 bits at once |
|
|
521 |
if(sizeof(void *) == 8 && (size & 7) == 0 && (((intptr_t) s1) & 7) == 0 && (((intptr_t) s2) & 7) == 0) { |
522 |
int64_t a; |
523 |
|
524 |
assert(sizeof(int64_t) == 8, "the swap() function assumes that the sizeof(int64_t) == 8...\n"); |
525 |
do { |
526 |
a = * (int64_t *) s1; |
527 |
* (int64_t *) s1 = * (int64_t *) s2; |
528 |
* (int64_t *) s2 = a; |
529 |
s1 = (int64_t *) s1 + 1; |
530 |
s2 = (int64_t *) s2 + 1; |
531 |
size -= sizeof(int64_t); |
532 |
} while(size > 0); |
533 |
} |
534 |
else if((size & 3) == 0 && (((intptr_t) s1) & 3) == 0 && (((intptr_t) s2) & 3) == 0) { |
513 |
int32_t a; |
535 |
int32_t a; |
514 |
|
536 |
|
515 |
assert(sizeof(int32_t) == 4, "the swap() function assumes that the sizeof(int32_t) == 4...\n"); |
537 |
assert(sizeof(int32_t) == 4, "the swap() function assumes that the sizeof(int32_t) == 4...\n"); |