Module Name: src
Committed By: matt
Date: Sun Aug 30 20:59:34 UTC 2009
Modified Files:
src/common/lib/libc/arch/mips/gen [matt-nb5-mips64]: byte_swap_2.S
byte_swap_4.S
Log Message:
If compiling for mips32r2 or mips64r2, use new wshb/rotr instructions.
To generate a diff of this commit:
cvs rdiff -u -r1.2.40.1 -r1.2.40.2 \
src/common/lib/libc/arch/mips/gen/byte_swap_2.S \
src/common/lib/libc/arch/mips/gen/byte_swap_4.S
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/arch/mips/gen/byte_swap_2.S
diff -u src/common/lib/libc/arch/mips/gen/byte_swap_2.S:1.2.40.1 src/common/lib/libc/arch/mips/gen/byte_swap_2.S:1.2.40.2
--- src/common/lib/libc/arch/mips/gen/byte_swap_2.S:1.2.40.1 Sun Aug 16 03:02:47 2009
+++ src/common/lib/libc/arch/mips/gen/byte_swap_2.S Sun Aug 30 20:59:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: byte_swap_2.S,v 1.2.40.1 2009/08/16 03:02:47 matt Exp $ */
+/* $NetBSD: byte_swap_2.S,v 1.2.40.2 2009/08/30 20:59:34 matt Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -35,8 +35,11 @@
#include <mips/asm.h>
#if defined(LIBC_SCCS) && !defined(lint)
- /* RCSID("from: @(#)htons.s 8.1 (Berkeley) 6/4/93") */
- RCSID("$NetBSD: byte_swap_2.S,v 1.2.40.1 2009/08/16 03:02:47 matt Exp $")
+#if 0
+ RCSID("from: @(#)htons.s 8.1 (Berkeley) 6/4/93")
+#else
+ RCSID("$NetBSD: byte_swap_2.S,v 1.2.40.2 2009/08/30 20:59:34 matt Exp $")
+#endif
#endif /* LIBC_SCCS and not lint */
#undef _LOCORE
@@ -46,9 +49,6 @@
#if defined(_KERNEL) || defined(_STANDALONE)
#define BSWAP16_NAME bswap16
#else
-#ifdef __ABICALLS__
- .abicalls
-#endif
#define BSWAP16_NAME __bswap16
#endif
@@ -57,12 +57,21 @@
ALEAF(htons)
ALEAF(ntohs)
#endif
+#if (__mips == 32 || __mips == 64) && __mips_isa_rev == 2
+ /*
+ * If we are on MIPS32r2 or MIPS64r2, use the new instructions
+ */
+ wsbh a0, a0 # word swap bytes within halfwords
+ and v0, a0, 0xffff # bound it to 16bits
+ j ra
+#else
srl v0, a0, 8
and v0, v0, 0xff
sll v1, a0, 8
and v1, v1, 0xff00
or v0, v0, v1
j ra
+#endif
END(BSWAP16_NAME)
#if BYTE_ORDER == BIG_ENDIAN
Index: src/common/lib/libc/arch/mips/gen/byte_swap_4.S
diff -u src/common/lib/libc/arch/mips/gen/byte_swap_4.S:1.2.40.1 src/common/lib/libc/arch/mips/gen/byte_swap_4.S:1.2.40.2
--- src/common/lib/libc/arch/mips/gen/byte_swap_4.S:1.2.40.1 Sun Aug 16 03:02:47 2009
+++ src/common/lib/libc/arch/mips/gen/byte_swap_4.S Sun Aug 30 20:59:34 2009
@@ -1,4 +1,4 @@
-/* $NetBSD: byte_swap_4.S,v 1.2.40.1 2009/08/16 03:02:47 matt Exp $ */
+/* $NetBSD: byte_swap_4.S,v 1.2.40.2 2009/08/30 20:59:34 matt Exp $ */
/*-
* Copyright (c) 1991, 1993
@@ -35,8 +35,11 @@
#include <mips/asm.h>
#if defined(LIBC_SCCS) && !defined(lint)
- /* RCSID("from: @(#)htonl.s 8.1 (Berkeley) 6/4/93") */
- RCSID("$NetBSD: byte_swap_4.S,v 1.2.40.1 2009/08/16 03:02:47 matt Exp $")
+#if 0
+ RCSID("from: @(#)htonl.s 8.1 (Berkeley) 6/4/93")
+#else
+ RCSID("$NetBSD: byte_swap_4.S,v 1.2.40.2 2009/08/30 20:59:34 matt Exp $")
+#endif
#endif /* LIBC_SCCS and not lint */
#undef _LOCORE
@@ -46,9 +49,6 @@
#if defined(_KERNEL) || defined(_STANDALONE)
#define BSWAP32_NAME bswap32
#else
-#ifdef __ABICALLS__
- .abicalls
-#endif
#define BSWAP32_NAME __bswap32
#endif
@@ -57,6 +57,14 @@
ALEAF(htonl) # a0 = 0x11223344, return 0x44332211
ALEAF(ntohl)
#endif
+#if (__mips == 32 || __mips == 64) && __mips_isa_rev == 2
+ /*
+ * If we are on MIPS32R2 or MIPS64R2 it's much easier
+ */
+ wsbh a0, a0 # word swap bytes within halfwords
+ rotr v0, a0, 16 # rotate word 16bits
+ j ra
+#else
srl v1, a0, 24 # v1 = 0x00000011
sll v0, a0, 24 # v0 = 0x44000000
or v0, v0, v1
@@ -67,6 +75,7 @@
and v1, v1, 0xff00 # v1 = 0x00002200
or v0, v0, v1
j ra
+#endif
END(BSWAP32_NAME)
#if BYTE_ORDER == BIG_ENDIAN