add bigendian support
authorRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sun, 21 Jun 1992 03:40:07 +0000 (19:40 -0800)
committerRalph Campbell <ralph@ucbvax.Berkeley.EDU>
Sun, 21 Jun 1992 03:40:07 +0000 (19:40 -0800)
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

usr/src/lib/libc/mips/net/htonl.s
usr/src/lib/libc/mips/net/htons.s
usr/src/lib/libc/mips/string/bcmp.s
usr/src/lib/libc/mips/string/bcopy.s

index fa6d490..f071ca1 100644 (file)
 #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
@@ -29,5 +34,12 @@ ALEAF(ntohl)
        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
        j       ra
 END(htonl)
        j       ra
 END(htonl)
index a63ea54..f330466 100644 (file)
 #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
        j       ra
 END(htons)
        j       ra
 END(htons)
index 0d18276..5f620a5 100644 (file)
 #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?
@@ -28,8 +43,8 @@ LEAF(bcmp)
        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
@@ -64,8 +79,8 @@ unaligned:
        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
index 51b7aaf..e1801f9 100644 (file)
 #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
@@ -46,10 +61,10 @@ forward:
 
        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)
        addu    a0, a0, a3
        addu    a0, a0, a3
-       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
@@ -57,8 +72,8 @@ forward:
        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
@@ -68,9 +83,9 @@ forward:
 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    a0, a0, a3
        addu    a0, a0, a3
-       swr     v0, 0(a1)
+       SWHI    v0, 0(a1)
        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