1
0
mirror of https://github.com/adtools/clib2.git synced 2025-12-08 14:59:05 +00:00
Files
amiga-clib2/library/contrib/byteswap/byteswap_bswap64.c
Olaf Barthel 66303e9ba2 - Added a directory to hold contributed code which has not been integrated
with the library yet.

- The byteswap code was contributed by Peter Bengtsson. Thank you very much!


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@15163 87f5fb63-7c3d-0410-a384-fd976d0f7a62
2006-11-13 09:49:49 +00:00

49 lines
732 B
C

#if defined(USE_64_BIT_INTS)
#if defined(__PPC__) && defined(__GNUC__)
asm(" .text\n\
.align 2\n\
.globl bswap64\n\
.type bswap64, @function\n\
bswap64:\n\
rlwinm %r5,%r3,8,8,31\n\
rlwimi %r5,%r3,24,0,7\n\
rlwimi %r5,%r3,24,16,23\n\
rlwinm %r3,%r4,8,8,31\n\
rlwimi %r3,%r4,24,0,7\n\
rlwimi %r3,%r4,24,16,23\n\
or %r4,%r5,%r5\n\
blr\n\
");
#else
#include <stdint.h>
uint64_t bswap64(uint64_t u64)
{
union {
uint64_t ll;
uint32_t l[2];
} v={.ll=u64};
uint32_t tmp;
tmp=v.l[0];
v.l[0]=((v.l[1]&0xff)<<24)|
((v.l[1]&0xff00)<<8)|
((v.l[1]&0xff0000)>>8)|
((v.l[1]&0xff000000)>>24);
v.l[1]=((tmp&0xff)<<24)|
((tmp&0xff00)<<8)|
((tmp&0xff0000)>>8)|
((tmp&0xff000000)>>24);
return(v.ll);
}
#endif
#endif