1 /* $NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $ */
4 * Written by Manuel Bouyer <bouyer@NetBSD.org>.
9 #if defined(LIBC_SCCS) && !defined(lint)
10 __RCSID("$NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $");
11 #endif /* LIBC_SCCS and not lint */
13 #include <sys/types.h>
14 #include <machine/bswap.h>
23 * Assume we have wide enough registers to do it without touching
26 return ( (x
<< 56) & 0xff00000000000000UL
) |
27 ( (x
<< 40) & 0x00ff000000000000UL
) |
28 ( (x
<< 24) & 0x0000ff0000000000UL
) |
29 ( (x
<< 8) & 0x000000ff00000000UL
) |
30 ( (x
>> 8) & 0x00000000ff000000UL
) |
31 ( (x
>> 24) & 0x0000000000ff0000UL
) |
32 ( (x
>> 40) & 0x000000000000ff00UL
) |
33 ( (x
>> 56) & 0x00000000000000ffUL
);
36 * Split the operation in two 32bit steps.
40 th
= bswap32((uint32_t)(x
& 0x00000000ffffffffULL
));
41 tl
= bswap32((uint32_t)((x
>> 32) & 0x00000000ffffffffULL
));
42 return ((uint64_t)th
<< 32) | tl
;