1/* 2 * (c) Copyright 1986 HEWLETT-PACKARD COMPANY 3 * 4 * To anyone who acknowledges that this file is provided "AS IS" 5 * without any express or implied warranty: 6 * permission to use, copy, modify, and distribute this file 7 * for any purpose is hereby granted without fee, provided that 8 * the above copyright notice and this notice appears in all 9 * copies, and that the name of Hewlett-Packard Company not be 10 * used in advertising or publicity pertaining to distribution 11 * of the software without specific, written prior permission. 12 * Hewlett-Packard Company makes no representations about the 13 * suitability of this software for any purpose. 14 */ 15 16/* HPUX_ID: @(#) $Revision$ */ 17/* 18 * memcpy(s1, s2, n) 19 * 20 * Copy n characters from s2 to s1; returns s1. 21 */ 22 23#include <picolibc.h> 24 25#define d_addr arg0 26#define s_addr arg1 27#define count arg2 28#define tmp5 arg3 29#define tmp1 r19 30#define tmp2 r20 31#define tmp3 r21 32#define tmp4 r22 33#define tmp6 r31 34 35#include "DEFS.h" 36 37ENTRY(memcpy) 38 comib,>= 5,count,byteloop /* If count is <= 6 don't get fancy.*/ 39 movb,=,n d_addr,ret0,done /* The return value is defined to be the value of d_addr. DELAY SLOT */ 40 /* if d_addr is null then exit */ 41 extru s_addr,31,2,tmp1 /* Extract the low two bits of the source address. */ 42 extru d_addr,31,2,tmp2 /* Extract the low two bits of the destination address. */ 43 add count,tmp2,count /* pre increment the count to adjust for alignment of s1 */ 44 comb,<> tmp2,tmp1,not_aligned /* see if s1 is aligned w.r.t. s2. */ 45 dep 0,31,2,s_addr /* Compute the word address of the source. DELAY SLOT. */ 46 47/* aligned */ 48 49/* We will now begin the 16 byte at a time word move if count >= 16 ! */ 50/* Else we will branch to the 4 byte-at-a time word move ! */ 51 52 addibt,<,n -16,count,chekchunk /* If count < 16 then we can't move 16 byte chunks ! */ 53 /* actually we can legally move 13 or more bytes on the first loop. */ 54 /* These loads and stores are done so as to prevent processor interlock. */ 55chunks: 56 ldwm 16(0,s_addr),tmp1 /* tmp1 = *s_addr s_addr += 16 */ 57 ldw -12(0,s_addr),tmp2 /* tmp2 = 2nd word */ 58 ldw -8(0,s_addr),tmp3 /* tmp3 = 3rd word */ 59 ldw -4(0,s_addr),tmp4 /* tmp4 = 4th word */ 60 /* Now store the results ! */ 61 stbys,b,m tmp1,4(0,d_addr) /* tmp1 = 1st word stored d_addr += 16 also take care of front porch. */ 62 stwm tmp2,4(0,d_addr) /* tmp2 = 2nd word stored. */ 63 stwm tmp3,4(0,d_addr) /* tmp3 = 3rd word stored. */ 64 addibf,< -16,count,chunks /* If count is still >= 16 do another loop. */ 65 stwm tmp4,4(0,d_addr) /* tmp4 = 4th word stored. DELAY SLOT */ 66 67chekchunk: 68 addibt,<,n 12,count,back_porch /* since the count is already decremented by -16 we're testing */ 69 /* to see if there are at least 4 bytes left ? */ 70subchunk: 71 ldws,ma 4(s_addr),tmp1 /* tmp1 = *s_addr++ */ 72 addibf,< -4,count,subchunk /* count -= 4 */ 73 stbys,b,m tmp1,4(d_addr) /* *d_addr++ = tmp1 */ 74 75 76back_porch: 77 addibt,=,n 4,count,done /* if count = 0 we're, of course, done ! */ 78 ldws 0(s_addr),tmp1 /* load up the back_porch */ 79 add d_addr,count,d_addr/* final store address is +1 too high ! */ 80 bv 0(r2) /* return--were done. */ 81 stbys,e tmp1,0(d_addr) /* kerplunk! whew ! */ 82 83/* Begin non_aligned code. (no refrence to politics) */ 84not_aligned: 85 sub,>= tmp2,tmp1,tmp3 /* compute the shift quantity again and skip the load if tmp2 > tmp1. */ 86 ldwm 4(0,s_addr),tmp1 /* load up the first word from the source. tmp1 = *s_addr++ */ 87 zdep tmp3,28,29,tmp4 /* compute the number of bits to shift based on the number of bytes above. */ 88 mtctl tmp4,11 /* load the shift count into cr11 = shift count register. */ 89 90 addibt,<,n -16,count,chkchnk2 /* first step in pre adjustment of count for looping. */ 91 92chunk2: 93 ldwm 16(0,s_addr),tmp2 /* get either first or second word . tmp2 = *s_addr++ */ 94 ldw -12(s_addr),tmp3 95 ldw -8(s_addr),tmp4 96 ldw -4(s_addr),tmp5 97 vshd tmp1,tmp2,tmp6 /* position data ! */ 98 stbys,b,m tmp6,4(0,d_addr) /* store ! */ 99 100 vshd tmp2,tmp3,tmp6 /* position data ! */ 101 stwm tmp6,4(0,d_addr) /* store ! */ 102 103 vshd tmp3,tmp4,tmp6 /* position data ! */ 104 stwm tmp6,4(0,d_addr) /* store ! */ 105 106 vshd tmp4,tmp5,tmp6 /* position data ! */ 107 stwm tmp6,4(0,d_addr) /* store the data ! */ 108 addibf,< -16,count,chunk2 /* If count is still >= 16 do another loop. */ 109 copy tmp5,tmp1 110 111 112chkchnk2: 113 addibt,<,n 12,count,bp_0 /* if we don't have 4 bytes left then do the back porch (bp_0) */ 114 115subchnk2: 116 ldwm 4(0,s_addr),tmp2 /* get next word ! */ 117 vshd tmp1,tmp2,tmp3 /* position data ! */ 118 addibt,< -4,count,bp_1 /* decrement count and when count < 4 goto back_porch (bp_1) */ 119 stbys,b,m tmp3,4(0,d_addr) /* store ! */ 120 121 ldwm 4(0,s_addr),tmp1 /* get 4th word ! */ 122 vshd tmp2,tmp1,tmp3 /* position data ! */ 123 addib,>= -4,count,subchnk2 /* decrement count and when count <= 4 go to back porch (bp_2) */ 124 stbys,b,m tmp3,4(0,d_addr) /* store the data ! */ 125 126bp_0: copy tmp1,tmp2 /* switch registers used in the shift process. */ 127bp_1: addibt,<=,n 4,count,done /* if count = -4 this implies that count = 0 -> done */ 128 add d_addr,count,d_addr /* bump destination address to be +1 too high ! */ 129 mfctl sar,tmp3 /* suppress final ldwm unless result used */ 130 extru tmp3,28,2,tmp3 /* convert bitshift to byteshift */ 131 sub,<= count,tmp3,r0 /* bytes unused if (count-byteshift <= 0*/ 132 133 ldwm 4(0,s_addr),tmp1 /* get final word ! */ 134 vshd tmp2,tmp1,tmp3 /* position data ! */ 135 bv 0(r2) /* return */ 136 stbys,e tmp3,0(0,d_addr) /* store the data ! */ 137 138/* here we do ye old byte-at-a-time moves. */ 139byteloop: 140 comb,>=,n 0,count,done 141 142encore: 143 ldbs,ma 1(s_addr),tmp1 144 addibf,= -1,count,encore 145 stbs,ma tmp1,1(d_addr) 146 147done: 148EXIT(memcpy) 149