Move all the stuff that detects bswapxx(constant) into the MI sys/bswap.h

Put the minimum to define the required inline assembler or C into the MD files.
NB: there may be some fallout from this!
This commit is contained in:
dsl 2006-01-30 22:46:35 +00:00
parent 2723c11bd9
commit c88ae1f9ee
9 changed files with 162 additions and 155 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.3 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.4 2006/01/30 22:46:35 dsl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -43,48 +43,29 @@
#ifndef _AMD64_BYTE_SWAP_H_
#define _AMD64_BYTE_SWAP_H_
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline u_int32_t __byte_swap_long_variable(u_int32_t);
static __inline u_int16_t __byte_swap_word_variable(u_int16_t);
static __inline u_int32_t
__byte_swap_long_variable(u_int32_t x)
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t __byte_swap_u32_variable(uint32_t);
static __inline uint32_t
__byte_swap_u32_variable(uint32_t x)
{
__asm volatile ( "bswap %1" : "=r" (x) : "0" (x));
return (x);
}
static __inline u_int16_t
__byte_swap_word_variable(u_int16_t x)
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t __byte_swap_u16_variable(uint16_t);
static __inline uint16_t
__byte_swap_u16_variable(uint16_t x)
{
__asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x));
return (x);
}
#ifdef __OPTIMIZE__
#define __byte_swap_long_constant(x) \
((((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24))
#define __byte_swap_word_constant(x) \
((((x) & 0xff00) >> 8) | \
(((x) & 0x00ff) << 8))
#define __byte_swap_long(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_long_constant(x) : __byte_swap_long_variable(x))
#define __byte_swap_word(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_word_constant(x) : __byte_swap_word_variable(x))
#else /* __OPTIMIZE__ */
#define __byte_swap_long(x) __byte_swap_long_variable(x)
#define __byte_swap_word(x) __byte_swap_word_variable(x)
#endif /* __OPTIMIZE__ */
__END_DECLS
#endif
#endif /* !_AMD64_BYTE_SWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.5 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.6 2006/01/30 22:46:35 dsl Exp $ */
/*-
* Copyright (c) 1997, 1999, 2002 The NetBSD Foundation, Inc.
@ -39,12 +39,15 @@
#ifndef _ARM_BYTE_SWAP_H_
#define _ARM_BYTE_SWAP_H_
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline u_int32_t
__byte_swap_32_variable(u_int32_t v)
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t
__byte_swap_u32_variable(uint32_t v)
{
u_int32_t t1;
uint32_t t1;
t1 = v ^ ((v << 16) | (v >> 16));
t1 &= 0xff00ffffU;
@ -54,8 +57,9 @@ __byte_swap_32_variable(u_int32_t v)
return (v);
}
static __inline u_int16_t
__byte_swap_16_variable(u_int16_t v)
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t
__byte_swap_u16_variable(uint16_t v)
{
__asm volatile(
@ -68,31 +72,8 @@ __byte_swap_16_variable(u_int16_t v)
return (v);
}
#ifdef __OPTIMIZE__
__END_DECLS
#endif
#define __byte_swap_32_constant(x) \
((((x) & 0xff000000U) >> 24) | \
(((x) & 0x00ff0000U) >> 8) | \
(((x) & 0x0000ff00U) << 8) | \
(((x) & 0x000000ffU) << 24))
#define __byte_swap_16_constant(x) \
((((x) & 0xff00) >> 8) | \
(((x) & 0x00ff) << 8))
#define __byte_swap_32(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_32_constant(x) : __byte_swap_32_variable(x))
#define __byte_swap_16(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_16_constant(x) : __byte_swap_16_variable(x))
#else
#define __byte_swap_32(x) __byte_swap_32_variable(x)
#define __byte_swap_16(x) __byte_swap_16_variable(x)
#endif /* __OPTIMIZE__ */
#endif /* _ARM_BYTE_SWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.5 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.6 2006/01/30 22:46:35 dsl Exp $ */
/* $OpenBSD: endian.h,v 1.7 2001/06/29 20:28:54 mickey Exp $ */
@ -35,11 +35,15 @@
#ifndef _HPPA_BYTE_SWAP_H_
#define _HPPA_BYTE_SWAP_H_
static __inline u_int16_t __byte_swap_word __P((u_int16_t));
static __inline u_int32_t __byte_swap_long __P((u_int32_t));
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline u_int32_t
__byte_swap_long(u_int32_t x)
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t __byte_swap_u32_variable(uint32_t);
static __inline uint32_t
__byte_swap_u32_variable(uint32_t x)
{
register in_addr_t __swap32md_x; \
\
@ -61,8 +65,10 @@ __byte_swap_long(u_int32_t x)
*/
#define __swap16md(x) __swap16gen(x)
#else
static __inline u_int16_t
__byte_swap_word(u_int16_t x)
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t __byte_swap_u16_variable(uint16_t);
static __inline uint16_t
__byte_swap_u16_variable(uint16_t x)
{
register in_port_t __swap16md_x; \
\
@ -73,4 +79,7 @@ __byte_swap_word(u_int16_t x)
}
#endif
__END_DECLS
#endif
#endif /* !_HPPA_BYTE_SWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.9 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.10 2006/01/30 22:46:36 dsl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -45,12 +45,14 @@
#include "opt_cputype.h"
#endif
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline uint32_t __byte_swap_long_variable(uint32_t);
static __inline uint16_t __byte_swap_word_variable(uint16_t);
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t __byte_swap_u32_variable(uint32_t);
static __inline uint32_t
__byte_swap_long_variable(uint32_t x)
__byte_swap_u32_variable(uint32_t x)
{
__asm volatile (
#if defined(_KERNEL) && !defined(_LKM) && !defined(I386_CPU)
@ -62,35 +64,16 @@ __byte_swap_long_variable(uint32_t x)
return (x);
}
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t __byte_swap_u16_variable(uint16_t);
static __inline uint16_t
__byte_swap_word_variable(uint16_t x)
__byte_swap_u16_variable(uint16_t x)
{
__asm volatile ("rorw $8, %w1" : "=r" (x) : "0" (x));
return (x);
}
#ifdef __OPTIMIZE__
#define __byte_swap_long_constant(x) \
((((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24))
#define __byte_swap_word_constant(x) \
((((x) & 0xff00) >> 8) | \
(((x) & 0x00ff) << 8))
#define __byte_swap_long(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_long_constant(x) : __byte_swap_long_variable(x))
#define __byte_swap_word(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_word_constant(x) : __byte_swap_word_variable(x))
#else /* __OPTIMIZE__ */
#define __byte_swap_long(x) __byte_swap_long_variable(x)
#define __byte_swap_word(x) __byte_swap_word_variable(x)
#endif /* __OPTIMIZE__ */
__END_DECLS
#endif
#endif /* !_I386_BYTE_SWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.7 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.8 2006/01/30 22:46:36 dsl Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -39,22 +39,31 @@
#ifndef M68K_BYTE_SWAP_H_
#define M68K_BYTE_SWAP_H_
static __inline u_int16_t __byte_swap_word(u_int16_t);
static __inline u_int32_t __byte_swap_long(u_int32_t);
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline u_int16_t
__byte_swap_word(u_int16_t var)
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t __byte_swap_u16_variable(uint16_t);
static __inline uint16_t
__byte_swap_u16_variable(uint16_t var)
{
__asm volatile ("rorw #8, %0" : "=d" (var) : "0" (var));
return (var);
}
static __inline u_int32_t
__byte_swap_long(u_int32_t var)
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t __byte_swap_u32_variable(uint32_t);
static __inline uint32_t
__byte_swap_u32_variable(uint32_t var)
{
__asm volatile (
"rorw #8, %0; swap %0; rorw #8, %0" : "=d" (var) : "0" (var));
return (var);
}
__END_DECLS
#endif
#endif /* !M68K_BYTE_SWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.7 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.8 2006/01/30 22:46:36 dsl Exp $ */
/*
* Copyright (c) 1987, 1991 Regents of the University of California.
@ -33,45 +33,29 @@
#ifndef _PC532_BYTE_SWAP_H_
#define _PC532_BYTE_SWAP_H_
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline unsigned int
__byte_swap_long_variable(unsigned int x)
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t
__byte_swap_u32_variable(uint32_t x)
{
__asm ("rotw 8,%1; rotd 16,%1; rotw 8,%1" : "=r" (x) : "0" (x));
return (x);
}
static __inline unsigned short
__byte_swap_word_variable(unsigned short x)
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t
__byte_swap_u16_variable(uint16_t x)
{
__asm ("rotw 8,%1" : "=r" (x) : "0" (x));
return (x);
}
#ifdef __OPTIMIZE__
#define __byte_swap_long_constant(x) \
((((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24))
#define __byte_swap_word_constant(x) \
((((x) & 0xff00) >> 8) | \
(((x) & 0x00ff) << 8))
#define __byte_swap_long(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_long_constant(x) : __byte_swap_long_variable(x))
#define __byte_swap_word(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_word_constant(x) : __byte_swap_word_variable(x))
#else /* __OPTIMIZE__ */
#define __byte_swap_long(x) __byte_swap_long_variable(x)
#define __byte_swap_word(x) __byte_swap_word_variable(x)
#endif /* __OPTIMIZE__ */
__END_DECLS
#endif
#endif /* _PC532_BYTE_SWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.4 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.5 2006/01/30 22:46:36 dsl Exp $ */
/*
* Copyright 2002 Wasabi Systems, Inc.
@ -39,13 +39,14 @@
#define _SH5_BYTESWAP_H_
#include <sys/types.h>
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
static __inline u_int16_t _sh5_bswap16(u_int16_t);
static __inline u_int32_t _sh5_bswap32(u_int32_t);
static __inline u_int64_t _sh5_bswap64(u_int64_t);
static __inline u_int16_t
_sh5_bswap16(u_int16_t x)
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t
__byte_swap_u16_variable(uint16_t x)
{
__asm volatile("byterev %0, %0; shlri %0, 32, %0; shlri.l %0, 16, %0"
@ -54,8 +55,9 @@ _sh5_bswap16(u_int16_t x)
return (x);
}
static __inline u_int32_t
_sh5_bswap32(u_int32_t x)
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t
__byte_swap_u32_variable(uint32_t x)
{
__asm volatile("byterev %0, %0; shlri %0, 32, %0; add.l %0, r63, %0"
@ -64,8 +66,9 @@ _sh5_bswap32(u_int32_t x)
return (x);
}
static __inline u_int64_t
_sh5_bswap64(u_int64_t x)
#define __BYTE_SWAP_U64_VARIABLE __byte_swap_u64_variable
static __inline uint64_t
__byte_swap_u64_variable(uint64_t x)
{
__asm volatile("byterev %0, %0" : "+r"(x));
@ -73,4 +76,7 @@ _sh5_bswap64(u_int64_t x)
return (x);
}
__END_DECLS
#endif
#endif /* _SH5_BYTESWAP_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: byte_swap.h,v 1.9 2005/12/28 18:40:13 perry Exp $ */
/* $NetBSD: byte_swap.h,v 1.10 2006/01/30 22:46:36 dsl Exp $ */
/*
* Copyright (c) 1987, 1991 Regents of the University of California.
@ -33,11 +33,15 @@
#ifndef _VAX_BYTE_SWAP_H_
#define _VAX_BYTE_SWAP_H_
#ifdef __GNUC__
#include <sys/types.h>
__BEGIN_DECLS
#include <sys/types.h>
#define __BYTE_SWAP_U32_VARIABLE __byte_swap_u32_variable
static __inline uint32_t __attribute__((__unused__))
__byte_swap_long_variable(uint32_t x)
__byte_swap_u32_variable(uint32_t x)
{
uint32_t y;
@ -53,14 +57,14 @@ __byte_swap_long_variable(uint32_t x)
return (y);
}
#define __BYTE_SWAP_U16_VARIABLE __byte_swap_u16_variable
static __inline uint16_t __attribute__((__unused__))
__byte_swap_word_variable(uint16_t x)
__byte_swap_u16_variable(uint16_t x)
{
return (x << 8 | x >> 8);
}
#define __byte_swap_long(x) __byte_swap_long_variable(x)
#define __byte_swap_word(x) __byte_swap_word_variable(x)
__END_DECLS
#endif
#endif /* _VAX_BYTE_SWAP_H_ */

View File

@ -1,11 +1,7 @@
/* $NetBSD: bswap.h,v 1.5 2005/12/26 18:41:36 perry Exp $ */
/* $NetBSD: bswap.h,v 1.6 2006/01/30 22:46:36 dsl Exp $ */
/* Written by Manuel Bouyer. Public domain */
#ifndef _MACHINE_BSWAP_H_ /* _BEFORE_ #ifndef _SYS_BSWAP_H_ */
#include <machine/bswap.h>
#endif
#ifndef _SYS_BSWAP_H_
#define _SYS_BSWAP_H_
@ -13,7 +9,11 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <machine/bswap.h>
__BEGIN_DECLS
/* Always declare the functions in case their address is taken (etc) */
#if defined(_KERNEL) || defined(_STANDALONE) || !defined(__BSWAP_RENAME)
uint16_t bswap16(uint16_t);
uint32_t bswap32(uint32_t);
@ -22,6 +22,56 @@ uint16_t bswap16(uint16_t) __RENAME(__bswap16);
uint32_t bswap32(uint32_t) __RENAME(__bswap32);
#endif
uint64_t bswap64(uint64_t);
#if defined(__GNUC__) && defined(__OPTIMIZE__)
/* machine/byte_swap.h might have defined inline versions */
#ifndef __BYTE_SWAP_U64_VARIABLE
#define __BYTE_SWAP_U64_VARIABLE bswap64
#endif
#ifndef __BYTE_SWAP_U32_VARIABLE
#define __BYTE_SWAP_U32_VARIABLE bswap32
#endif
#ifndef __BYTE_SWAP_U16_VARIABLE
#define __BYTE_SWAP_U16_VARIABLE bswap16
#endif
#define __byte_swap_u64_constant(x) \
((((x) & 0xff00000000000000ull) >> 56) | \
(((x) & 0x00ff000000000000ull) >> 40) | \
(((x) & 0x0000ff0000000000ull) >> 24) | \
(((x) & 0x000000ff00000000ull) >> 8) | \
(((x) & 0x00000000ff000000ull) << 8) | \
(((x) & 0x0000000000ff0000ull) << 24) | \
(((x) & 0x000000000000ff00ull) << 40) | \
(((x) & 0x00000000000000ffull) << 56))
#define __byte_swap_u32_constant(x) \
((((x) & 0xff000000) >> 24) | \
(((x) & 0x00ff0000) >> 8) | \
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24))
#define __byte_swap_u16_constant(x) \
((((x) & 0xff00) >> 8) | \
(((x) & 0x00ff) << 8))
#define bswap64(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_u64_constant(x) : __BYTE_SWAP_U64_VARIABLE(x))
#define bswap32(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_u32_constant(x) : __BYTE_SWAP_U32_VARIABLE(x))
#define bswap16(x) \
(__builtin_constant_p((x)) ? \
__byte_swap_u16_constant(x) : __BYTE_SWAP_U16_VARIABLE(x))
#endif /* __OPTIMIZE__ */
__END_DECLS
#endif /* !_LOCORE */