1/*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Ralph Campbell. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11#include "DEFS.h" 12 13#if defined(LIBC_SCCS) && !defined(lint) 14 ASMSTR("@(#)bcopy.s 5.3 (Berkeley) 06/20/92") 15#endif /* LIBC_SCCS and not lint */ 16 17/* bcopy(s1, s2, n) */ 18 19#include <machine/endian.h> 20 21#if BYTE_ORDER == LITTLE_ENDIAN 22# define LWHI lwr 23# define LWLO lwl 24# define SWHI swr 25# define SWLO swl 26#endif 27#if BYTE_ORDER == BIG_ENDIAN 28# define LWHI lwl 29# define LWLO lwr 30# define SWHI swl 31# define SWLO swr 32#endif 33 34LEAF(bcopy) 35 .set noreorder 36 addu t0, a0, a2 # t0 = end of s1 region 37 sltu t1, a1, t0 38 sltu t2, a0, a1 39 and t1, t1, t2 # t1 = true if from < to < (from+len) 40 beq t1, zero, forward # non overlapping, do forward copy 41 slt t2, a2, 12 # check for small copy 42 43 ble a2, zero, 2f 44 addu t1, a1, a2 # t1 = end of to region 451: 46 lb v0, -1(t0) # copy bytes backwards, 47 subu t0, t0, 1 # doesn't happen often so do slow way 48 subu t1, t1, 1 49 bne t0, a0, 1b 50 sb v0, 0(t1) 512: 52 j ra 53 nop 54forward: 55 bne t2, zero, smallcpy # do a small bcopy 56 xor v0, a0, a1 # compare low two bits of addresses 57 and v0, v0, 3 58 subu a3, zero, a1 # compute # bytes to word align address 59 beq v0, zero, aligned # addresses can be word aligned 60 and a3, a3, 3 61 62 beq a3, zero, 1f 63 subu a2, a2, a3 # subtract from remaining count 64 LWHI v0, 0(a0) # get next 4 bytes (unaligned) 65 LWLO v0, 3(a0) 66 addu a0, a0, a3 67 SWHI v0, 0(a1) # store 1, 2, or 3 bytes to align a1 68 addu a1, a1, a3 691: 70 and v0, a2, 3 # compute number of words left 71 subu a3, a2, v0 72 move a2, v0 73 addu a3, a3, a0 # compute ending address 742: 75 LWHI v0, 0(a0) # copy words a0 unaligned, a1 aligned 76 LWLO v0, 3(a0) 77 addu a0, a0, 4 78 addu a1, a1, 4 79 bne a0, a3, 2b 80 sw v0, -4(a1) 81 b smallcpy 82 nop 83aligned: 84 beq a3, zero, 1f 85 subu a2, a2, a3 # subtract from remaining count 86 LWHI v0, 0(a0) # copy 1, 2, or 3 bytes to align 87 addu a0, a0, a3 88 SWHI v0, 0(a1) 89 addu a1, a1, a3 901: 91 and v0, a2, 3 # compute number of whole words left 92 subu a3, a2, v0 93 move a2, v0 94 addu a3, a3, a0 # compute ending address 952: 96 lw v0, 0(a0) # copy words 97 addu a0, a0, 4 98 addu a1, a1, 4 99 bne a0, a3, 2b 100 sw v0, -4(a1) 101smallcpy: 102 ble a2, zero, 2f 103 addu a3, a2, a0 # compute ending address 1041: 105 lbu v0, 0(a0) # copy bytes 106 addu a0, a0, 1 107 addu a1, a1, 1 108 bne a0, a3, 1b 109 sb v0, -1(a1) 1102: 111 j ra 112 nop 113 .set reorder 114END(bcopy) 115