minix/common/lib/libc/gen/bswap64.c
Lionel Sambuc 84d9c625bf Synchronize on NetBSD-CVS (2013/12/1 12:00:00 UTC)
- Fix for possible unset uid/gid in toproto
 - Fix for default mtree style
 - Update libelf
 - Importing libexecinfo
 - Resynchronize GCC, mpc, gmp, mpfr
 - build.sh: Replace params with show-params.
     This has been done as the make target has been renamed in the same
     way, while a new target named params has been added. This new
     target generates a file containing all the parameters, instead of
     printing it on the console.
 - Update test48 with new etc/services (Fix by Ben Gras <ben@minix3.org)
     get getservbyport() out of the inner loop

Change-Id: Ie6ad5226fa2621ff9f0dee8782ea48f9443d2091
2014-07-28 17:05:06 +02:00

48 lines
1.2 KiB
C

/* $NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $ */
/*
* Written by Manuel Bouyer <bouyer@NetBSD.org>.
* Public domain.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: bswap64.c,v 1.3 2009/03/16 05:59:21 cegger Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <machine/bswap.h>
#undef bswap64
#if defined(__minix) && defined(_STANDALONE)
#undef bswap32
#endif /* defined(__minix) && defined(_STANDALONE) */
uint64_t
bswap64(uint64_t x)
{
#ifdef _LP64
/*
* Assume we have wide enough registers to do it without touching
* memory.
*/
return ( (x << 56) & 0xff00000000000000UL ) |
( (x << 40) & 0x00ff000000000000UL ) |
( (x << 24) & 0x0000ff0000000000UL ) |
( (x << 8) & 0x000000ff00000000UL ) |
( (x >> 8) & 0x00000000ff000000UL ) |
( (x >> 24) & 0x0000000000ff0000UL ) |
( (x >> 40) & 0x000000000000ff00UL ) |
( (x >> 56) & 0x00000000000000ffUL );
#else
/*
* Split the operation in two 32bit steps.
*/
uint32_t tl, th;
th = bswap32((uint32_t)(x & 0x00000000ffffffffULL));
tl = bswap32((uint32_t)((x >> 32) & 0x00000000ffffffffULL));
return ((uint64_t)th << 32) | tl;
#endif
}