SCCS-vsn: lib/libc/mips/net/htonl.s 5.3
SCCS-vsn: lib/libc/mips/net/htons.s 5.3
SCCS-vsn: lib/libc/mips/string/bcmp.s 5.3
SCCS-vsn: lib/libc/mips/string/bcopy.s 5.3
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("@(#)htonl.s 5.2 (Berkeley) %G%")
+ ASMSTR("@(#)htonl.s 5.3 (Berkeley) %G%")
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
+#include <machine/endian.h>
+#undef htonl
+#undef ntohl
+
/*
* netorder = htonl(hostorder)
* hostorder = ntohl(netorder)
*/
LEAF(htonl) # a0 = 0x11223344, return 0x44332211
ALEAF(ntohl)
/*
* netorder = htonl(hostorder)
* hostorder = ntohl(netorder)
*/
LEAF(htonl) # a0 = 0x11223344, return 0x44332211
ALEAF(ntohl)
+#if BYTE_ORDER == LITTLE_ENDIAN
srl v1, a0, 24 # v1 = 0x00000011
sll v0, a0, 24 # v0 = 0x44000000
or v0, v0, v1
srl v1, a0, 24 # v1 = 0x00000011
sll v0, a0, 24 # v0 = 0x44000000
or v0, v0, v1
srl v1, a0, 8
and v1, v1, 0xff00 # v1 = 0x00002200
or v0, v0, v1
srl v1, a0, 8
and v1, v1, 0xff00 # v1 = 0x00002200
or v0, v0, v1
+#else
+#if BYTE_ORDER == BIG_ENDIAN
+ move v0, a0
+#else
+ ERROR
+#endif
+#endif
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("@(#)htons.s 5.2 (Berkeley) %G%")
+ ASMSTR("@(#)htons.s 5.3 (Berkeley) %G%")
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
+#include <machine/endian.h>
+#undef htons
+#undef ntohs
+
/*
* netorder = htons(hostorder)
* hostorder = ntohs(netorder)
*/
LEAF(htons)
ALEAF(ntohs)
/*
* netorder = htons(hostorder)
* hostorder = ntohs(netorder)
*/
LEAF(htons)
ALEAF(ntohs)
+#if BYTE_ORDER == LITTLE_ENDIAN
srl v0, a0, 8
and v0, v0, 0xff
sll v1, a0, 8
and v1, v1, 0xff00
or v0, v0, v1
srl v0, a0, 8
and v0, v0, 0xff
sll v1, a0, 8
and v1, v1, 0xff00
or v0, v0, v1
+#else
+#if BYTE_ORDER == BIG_ENDIAN
+ move v0, a0
+#else
+ ERROR
+#endif
+#endif
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("@(#)bcmp.s 5.2 (Berkeley) %G%")
+ ASMSTR("@(#)bcmp.s 5.3 (Berkeley) %G%")
#endif /* LIBC_SCCS and not lint */
/* bcmp(s1, s2, n) */
#endif /* LIBC_SCCS and not lint */
/* bcmp(s1, s2, n) */
+#include <machine/endian.h>
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define LWHI lwr
+# define LWLO lwl
+# define SWHI swr
+# define SWLO swl
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+# define LWHI lwl
+# define LWLO lwr
+# define SWHI swl
+# define SWLO swr
+#endif
+
LEAF(bcmp)
.set noreorder
blt a2, 16, small # is it worth any trouble?
LEAF(bcmp)
.set noreorder
blt a2, 16, small # is it worth any trouble?
beq a3, zero, 1f
subu a2, a2, a3 # subtract from remaining count
move v0, v1 # init v0,v1 so unmodified bytes match
beq a3, zero, 1f
subu a2, a2, a3 # subtract from remaining count
move v0, v1 # init v0,v1 so unmodified bytes match
- lwr v0, 0(a0) # read 1, 2, or 3 bytes
- lwr v1, 0(a1)
+ LWHI v0, 0(a0) # read 1, 2, or 3 bytes
+ LWHI v1, 0(a1)
addu a1, a1, a3
bne v0, v1, nomatch
addu a0, a0, a3
addu a1, a1, a3
bne v0, v1, nomatch
addu a0, a0, a3
subu a2, a2, a3 # which has to be >= (16-3) & ~3
addu a3, a3, a0 # compute ending address
3:
subu a2, a2, a3 # which has to be >= (16-3) & ~3
addu a3, a3, a0 # compute ending address
3:
- lwr v0, 0(a0) # compare words a0 unaligned, a1 aligned
- lwl v0, 3(a0)
+ LWHI v0, 0(a0) # compare words a0 unaligned, a1 aligned
+ LWLO v0, 3(a0)
lw v1, 0(a1)
addu a0, a0, 4
bne v0, v1, nomatch
lw v1, 0(a1)
addu a0, a0, 4
bne v0, v1, nomatch
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
#include "DEFS.h"
#if defined(LIBC_SCCS) && !defined(lint)
- ASMSTR("@(#)bcopy.s 5.2 (Berkeley) %G%")
+ ASMSTR("@(#)bcopy.s 5.3 (Berkeley) %G%")
#endif /* LIBC_SCCS and not lint */
/* bcopy(s1, s2, n) */
#endif /* LIBC_SCCS and not lint */
/* bcopy(s1, s2, n) */
+#include <machine/endian.h>
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define LWHI lwr
+# define LWLO lwl
+# define SWHI swr
+# define SWLO swl
+#endif
+#if BYTE_ORDER == BIG_ENDIAN
+# define LWHI lwl
+# define LWLO lwr
+# define SWHI swl
+# define SWLO swr
+#endif
+
LEAF(bcopy)
.set noreorder
addu t0, a0, a2 # t0 = end of s1 region
LEAF(bcopy)
.set noreorder
addu t0, a0, a2 # t0 = end of s1 region
beq a3, zero, 1f
subu a2, a2, a3 # subtract from remaining count
beq a3, zero, 1f
subu a2, a2, a3 # subtract from remaining count
- lwr v0, 0(a0) # get next 4 bytes (unaligned)
- lwl v0, 3(a0)
+ LWHI v0, 0(a0) # get next 4 bytes (unaligned)
+ LWLO v0, 3(a0)
- swr v0, 0(a1) # store 1, 2, or 3 bytes to align a1
+ SWHI v0, 0(a1) # store 1, 2, or 3 bytes to align a1
addu a1, a1, a3
1:
and v0, a2, 3 # compute number of words left
addu a1, a1, a3
1:
and v0, a2, 3 # compute number of words left
move a2, v0
addu a3, a3, a0 # compute ending address
2:
move a2, v0
addu a3, a3, a0 # compute ending address
2:
- lwr v0, 0(a0) # copy words a0 unaligned, a1 aligned
- lwl v0, 3(a0)
+ LWHI v0, 0(a0) # copy words a0 unaligned, a1 aligned
+ LWLO v0, 3(a0)
addu a0, a0, 4
addu a1, a1, 4
bne a0, a3, 2b
addu a0, a0, 4
addu a1, a1, 4
bne a0, a3, 2b
aligned:
beq a3, zero, 1f
subu a2, a2, a3 # subtract from remaining count
aligned:
beq a3, zero, 1f
subu a2, a2, a3 # subtract from remaining count
- lwr v0, 0(a0) # copy 1, 2, or 3 bytes to align
+ LWHI v0, 0(a0) # copy 1, 2, or 3 bytes to align
addu a1, a1, a3
1:
and v0, a2, 3 # compute number of whole words left
addu a1, a1, a3
1:
and v0, a2, 3 # compute number of whole words left