Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/m68k/include Optimize bswap16() and bswap32() funct...



details:   https://anonhg.NetBSD.org/src/rev/ce355ef943e5
branches:  trunk
changeset: 507742:ce355ef943e5
user:      leo <leo%NetBSD.org@localhost>
date:      Fri Mar 30 20:00:05 2001 +0000

description:
Optimize bswap16() and bswap32() functions to inline assembly.

diffstat:

 sys/arch/m68k/include/bswap.h     |  12 +++++++-
 sys/arch/m68k/include/byte_swap.h |  59 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletions(-)

diffs (86 lines):

diff -r 5410040c747a -r ce355ef943e5 sys/arch/m68k/include/bswap.h
--- a/sys/arch/m68k/include/bswap.h     Fri Mar 30 18:33:22 2001 +0000
+++ b/sys/arch/m68k/include/bswap.h     Fri Mar 30 20:00:05 2001 +0000
@@ -1,8 +1,18 @@
-/*      $NetBSD: bswap.h,v 1.2 1999/08/21 05:39:53 simonb Exp $      */
+/*      $NetBSD: bswap.h,v 1.3 2001/03/30 20:00:05 leo Exp $      */
 
 #ifndef _MACHINE_BSWAP_H_
 #define        _MACHINE_BSWAP_H_
 
+#define        __BSWAP_RENAME
 #include <sys/bswap.h>
 
+#ifdef __GNUC__
+
+#include <m68k/byte_swap.h>
+
+#define bswap16(x)     __byte_swap_word(x)
+#define bswap32(x)     __byte_swap_long(x)
+
+#endif /* __GNUC__ */
+
 #endif /* !_MACHINE_BSWAP_H_ */
diff -r 5410040c747a -r ce355ef943e5 sys/arch/m68k/include/byte_swap.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/m68k/include/byte_swap.h Fri Mar 30 20:00:05 2001 +0000
@@ -0,0 +1,59 @@
+/*     $NetBSD: byte_swap.h,v 1.1 2001/03/30 20:00:05 leo Exp $        */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Leo Weppelman.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef        M68K_BYTE_SWAP_H_
+#define        M68K_BYTE_SWAP_H_
+
+#if defined(_KERNEL)
+
+#define __byte_swap_word(var)                          \
+        ({ u_int16_t    __var = (var);                 \
+               __asm__ __volatile ("rorw #8, %0"       \
+                                       : "=r" (__var)  \
+                                       : "0" (__var)); \
+            __var; })
+
+#define __byte_swap_long(var)    \
+        ({ u_int32_t    __var = (var);                                 \
+               __asm__ __volatile ("rorw #8, %0; swap %0; rorw #8, %0" \
+                                       : "=r" (__var) : "0" (__var));  \
+            __var; })
+
+#endif /* defined(_KERNEL) */
+
+#endif /* !M68K_BYTE_SWAP_H_ */



Home | Main Index | Thread Index | Old Index