summaryrefslogtreecommitdiffstats
path: root/sys/alpha
diff options
context:
space:
mode:
authorgallatin <gallatin@FreeBSD.org>2002-02-28 18:21:51 +0000
committergallatin <gallatin@FreeBSD.org>2002-02-28 18:21:51 +0000
commitacb15d327f9b1dd379751ba58ef527ee003362fc (patch)
treee8912a17dec33e2ca12edbf46dc44465d38f42b9 /sys/alpha
parent3af87f82d6519487f875dd2c58e1d74aec880a69 (diff)
downloadFreeBSD-src-acb15d327f9b1dd379751ba58ef527ee003362fc.zip
FreeBSD-src-acb15d327f9b1dd379751ba58ef527ee003362fc.tar.gz
add inlines for bswap*.
smaller versions of the byteswap routines were obtained from NetBSD
Diffstat (limited to 'sys/alpha')
-rw-r--r--sys/alpha/include/endian.h43
1 files changed, 38 insertions, 5 deletions
diff --git a/sys/alpha/include/endian.h b/sys/alpha/include/endian.h
index 5f8c050..28f7dd0 100644
--- a/sys/alpha/include/endian.h
+++ b/sys/alpha/include/endian.h
@@ -56,14 +56,47 @@
#define PDP_ENDIAN 3412 /* LSB first in word, MSW first in long */
#define BYTE_ORDER LITTLE_ENDIAN
+#endif /* !_POSIX_SOURCE */
#ifdef _KERNEL
-#define _BSWAP16_DEFINED
-__uint16_t __bswap16(__uint16_t);
-#define _BSWAP32_DEFINED
-__uint32_t __bswap32(__uint32_t);
+#ifdef __GNUC__
+
+#define _BSWAP32_DEFINED
+static __inline __uint32_t
+__bswap32(__uint32_t __x)
+{
+ __uint32_t __r;
+
+ __asm __volatile__ (
+ "insbl %1, 3, $1\n\t"
+ "extbl %1, 1, $2\n\t"
+ "extbl %1, 2, $3\n\t"
+ "extbl %1, 3, $4\n\t"
+ "sll $2, 16, $2\n\t"
+ "sll $3, 8, $3\n\t"
+ "or $4, $1, %0\n\t"
+ "or $2, $3, $2\n\t"
+ "or $2, %0, %0"
+ : "=r" (__r) : "r" (__x) : "$1", "$2", "$3", "$4");
+ return (__r);
+}
+
+#define _BSWAP16_DEFINED
+static __inline __uint16_t
+__bswap16(__uint16_t __x)
+{
+ __uint16_t __r;
+
+ __asm __volatile__ (
+ "insbl %1, 1, $1\n\t"
+ "extbl %1, 1, $2\n\t"
+ "or $1, $2, %0"
+ : "=r" (__r) : "r" (__x) : "$1", "$2");
+ return (__r);
+}
+
#endif /* _KERNEL */
-#endif /* !_POSIX_SOURCE */
+#endif /* __GNUC__ */
#endif /* !_MACHINE_ENDIAN_H_ */
OpenPOWER on IntegriCloud