; -*-MIDAS-*- subttl Fast String Copy ; FSCOPY copies N 7 bit bytes from a source to a destination. Both are ; specified by BPs which will increment to point to the first byte to ; transfer or store into. ; Arguments: ; A source BP ; B destination BP ; C no. of bytes ; Results: ; A updated source BP ; B updated destination BP ; Assumes C,D and T1,T2 are contiguous. Clobbers T1 and T2. fscopy: caile c,18. ; compare N to breakeven point jrst fscpy2 ; hairy copy is faster jumple c,[popj p,] ; N <= 0 does no moving ; N is less than breakeven point. ; Use ILDB/IDPB loop. fscpy1: ildb t1,a ; get byte of source idpb t1,b ; deposit in destination sojg c,fscpy1 ; do N bytes popj p, ; N greater than breakeven point. fscpy2: push p,d ; save AC jumpge b,fsc2 ; if not 440700 then enter byte copy loop sub b,[430000,,1] ; 440700, convert to 10700 jrst fsc3 ; skip byte copy loop, we're already there ; First deposit in destination until destination BP will increment to point ; to the first byte of a word. fsc1: ildb t1,a ; load byte from source idpb t1,b ; deposit in destination fsc2: tlne b,320000 ; ready to increment to new word? soja c,fsc1 ; decrement count, keep going ; B+1 is now address of next destination word fsc3: idivi c,5 ; no. of words in C, leftover chars in D tlnn a,320000 ; source BP 440700 or 10700? jrst fscblt ; yes, use BLT! ; Non-BLT copy. skipn kl10 ; KL10? jrst fscka ; no, use ACs move t1,(a) ; read word source BP points to lsh t1,-1 ; put into low 35 bits addi a,(c) ; add word count to source BP addi b,(c) ; add word count to destination BP hrrm a,fscl+0 ; make MOVE T2,SOURCE+COUNT(C) hrrm b,fscl+2 ; make MOVEM T1,DESTINATION+COUNT(C) ldb t2,[360600,,a] ; get bit position from source BP movei t2,-2(t2) hrrm t2,fscl+3 movni t2,-35.(t2) hrrm t2,fscl+1 movn c,c ; negate count aojle c,fscl ; start loop jrst @fsclt(d) ; String copy loop. bvar ; this code is impure!! fscl: move t2,0(c) lshc t1,0 ; shift into place movem t1,0(c) lshc t1,0 aojle c,fscl ; increment count, keep going until zero jrst @fsclt(d) evar ; KA10 version - use ACs. fscka: addi a,(c) ; add word count to source BP addi b,(c) ; add word count to destination BP move t1,[7,,fscacs] blt t1,fscacs+16-7 movsi 11,(move 10,0(c)) ; make MOVE T2,SOURCE+COUNT(C) hrri 11,(a) ; ... movsi 13,(movem 7,0(c)) ; make MOVEM T1,DESTINATION+COUNT(C) hrri 13,(b) ldb 14,[360600,,a] ; get bit position from source BP add 14,[-1000000] movni 12,-35.(14) hrli 12,(lshc 7,) move 16,[jrst fsck1] movn c,c ; negate count move 7,@11 lsh 7,-1 move 15,.+1 aojle c,11 ; start loop fsck1: move c,[fscacs,,7] blt c,16 jrst @fsclt(d) var fscacs(16-7+1) ; room to save ACs 7-16 ; Use BLT! fscblt: jumpge a,.+2 ; 10700 or 440700? sub a,[430000,,1] ; it's 440700, convert to 10700 movsi t1,1(a) ; BLT AC: source address in LH hrri t1,1(b) ; and destination address in RH addi a,(c) ; bump up BP to last word of source addi b,(c) ; get BLT stop address blt t1,(b) ; move words from source to destination jrst @fsclt(d) fsclt: fscl0 ? fscl1 ? fscl2 ? fscl3 ? fscl4 ; Copy remaining bytes to last destination word. fscl4: ildb t1,a ; load byte from source idpb t1,b ; deposit byte in destination fscl3: ildb t1,a ; load byte from source idpb t1,b ; deposit byte in destination fscl2: ildb t1,a ; load byte from source idpb t1,b ; deposit byte in destination fscl1: ildb t1,a ; load byte from source idpb t1,b ; deposit byte in destination fscl0: pop p,d ; restore AC popj p,