PERFORCE change 133787 for review
Warner Losh
imp at FreeBSD.org
Mon Jan 21 08:01:41 PST 2008
http://perforce.freebsd.org/chv.cgi?CH=133787
Change 133787 by imp at imp_lighthouse on 2008/01/21 16:00:56
Prefer the mips2 endian.h to the JNPR one since it handles both
endians.
Affected files ...
.. //depot/projects/mips2-jnpr/src/sys/mips/include/endian.h#6 integrate
Differences ...
==== //depot/projects/mips2-jnpr/src/sys/mips/include/endian.h#6 (text+ko) ====
@@ -1,8 +1,6 @@
-/* From: NetBSD: endian.h,v 1.5 1997/10/09 15:42:19 bouyer Exp */
-
/*-
- * Copyright (c) 1987, 1991, 1993
- * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 1987, 1991 Regents of the University of California.
+ * All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,16 +26,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * @(#)endian.h 8.1 (Berkeley) 6/10/93
- * JNPR: endian.h,v 1.8 2007/08/09 11:23:32 katta
- * $FreeBSD$
+ * @(#)endian.h 7.8 (Berkeley) 4/3/91
+ * $FreeBSD: src/sys/amd64/include/endian.h,v 1.8 2005/03/11 21:46:01 peter Exp $
*/
#ifndef _MACHINE_ENDIAN_H_
#define _MACHINE_ENDIAN_H_
+
#include <sys/cdefs.h>
+#include <sys/_types.h>
-#ifndef _POSIX_SOURCE
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/*
* Definitions for byte order, according to byte significance from low
* address to high.
@@ -46,6 +48,12 @@
#define _BIG_ENDIAN 4321 /* MSB first: 68000, ibm, net */
#define _PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
+#ifdef _MIPSEB
+#define _BYTE_ORDER _BIG_ENDIAN
+#else
+#define _BYTE_ORDER _LITTLE_ENDIAN
+#endif /* _MIBSEB */
+
/*
* Deprecated variants that don't have enough underscores to be useful in more
* strict namespaces.
@@ -57,22 +65,30 @@
#define BYTE_ORDER _BYTE_ORDER
#endif
-#define _BYTE_ORDER _BIG_ENDIAN
+#if defined(__GNUCLIKE_BUILTIN_CONSTANT_P) && defined(__OPTIMIZE__)
+#define __is_constant(x) __builtin_constant_p(x)
+#else
+#define __is_constant(x) 0
+#endif
-#ifndef _LOCORE
-#ifndef __ASSEMBLER__
-#include <sys/_types.h>
-#if defined(__CC_SUPPORTS___INLINE) && defined(__GNUCLIKE_ASM)
+#define __bswap16_const(x) (((x) >> 8) | (((x) << 8) & 0xff00))
+#define __bswap32_const(x) (((x) >> 24) | (((x) >> 8) & 0xff00) | \
+ (((x) << 8) & 0xff0000) | (((x) << 24) & 0xff000000))
+#define __bswap64_const(x) (((x) >> 56) | (((x) >> 40) & 0xff00) | \
+ (((x) >> 24) & 0xff0000) | (((x) >> 8) & 0xff000000) | \
+ (((x) << 8) & ((__uint64_t)0xff << 32)) | \
+ (((x) << 24) & ((__uint64_t)0xff << 40)) | \
+ (((x) << 40) & ((__uint64_t)0xff << 48)) | (((x) << 56)))
static __inline __uint16_t
-__bswap16(__uint16_t _x)
+__bswap16_var(__uint16_t _x)
{
return ((_x >> 8) | ((_x << 8) & 0xff00));
}
static __inline __uint32_t
-__bswap32(__uint32_t _x)
+__bswap32_var(__uint32_t _x)
{
return ((_x >> 24) | ((_x >> 8) & 0xff00) | ((_x << 8) & 0xff0000) |
@@ -80,7 +96,7 @@
}
static __inline __uint64_t
-__bswap64(__uint64_t _x)
+__bswap64_var(__uint64_t _x)
{
return ((_x >> 56) | ((_x >> 40) & 0xff00) | ((_x >> 24) & 0xff0000) |
@@ -89,43 +105,37 @@
((_x << 40) & ((__uint64_t)0xff << 48)) | ((_x << 56)));
}
-__uint32_t __htonl(__uint32_t);
-__uint16_t __htons(__uint16_t);
-__uint32_t __ntohl(__uint32_t);
-__uint16_t __ntohs(__uint16_t);
+#define __bswap16(x) (__uint16_t)(__is_constant(x) ? __bswap16_const(x) : \
+ __bswap16_var(x))
+#define __bswap32(x) (__uint32_t)(__is_constant(x) ? __bswap32_const(x) : \
+ __bswap32_var(x))
+#define __bswap64(x) (__uint64_t)(__is_constant(x) ? __bswap64_const(x) : \
+ __bswap64_var(x))
-#else /* !(__CC_SUPPORTS___INLINE && __GNUCLIKE_ASM) */
-
+#ifdef _MIPSEB
+#define __htonl(x) ((__uint32_t)(x))
+#define __htons(x) ((__uint16_t)(x))
+#define __ntohl(x) ((__uint32_t)(x))
+#define __ntohs(x) ((__uint16_t)(x))
/*
- * No optimizations are available for this compiler. Fall back to
- * non-optimized functions by defining the constant usually used to prevent
- * redefinition.
+ * Define the order of 32-bit words in 64-bit words.
*/
-#define _BYTEORDER_FUNC_DEFINED
-
-#endif /* __CC_SUPPORTS___INLINE && __GNUCLIKE_ASM */
-
-#endif /* !__ASSEMBLER__ */
-#endif /* !_LOCORE */
-
/*
- * Define the order of 32-bit words in 64-bit words.
+ * XXXMIPS: Additional parentheses to make gcc more happy.
*/
-#if _BYTE_ORDER == BIG_ENDIAN
-#define _QUAD_HIGHWORD 0
-#define _QUAD_LOWWORD 1
-#define __htonl(x) ((__uint32_t)(x))
-#define __htons(x) ((__uint16_t)(x))
-#define __ntohl(x) ((__uint32_t)(x))
-#define __ntohs(x) ((__uint16_t)(x))
+#define _QUAD_HIGHWORD 0
+#define _QUAD_LOWWORD 1
#else
-#define _QUAD_HIGHWORD 1
-#define _QUAD_LOWWORD 0
-#define __ntohl(x) (__bswap32(x))
-#define __ntohs(x) (__bswap16(x))
-#define __htonl(x) (__bswap32(x))
-#define __htons(x) (__bswap16(x))
-#endif /* _BYTE_ORDER == BIG_ENDIAN */
+#define _QUAD_HIGHWORD 1
+#define _QUAD_LOWWORD 0
+#define __ntohl(x) (__bswap32((x)))
+#define __ntohs(x) (__bswap16((x)))
+#define __htonl(x) (__bswap32((x)))
+#define __htons(x) (__bswap16((x)))
+#endif /* _MIPSEB */
+
+#ifdef __cplusplus
+}
+#endif
-#endif /* !_POSIX_SOURCE */
#endif /* !_MACHINE_ENDIAN_H_ */
More information about the p4-projects
mailing list