/*1* arch/alpha/lib/ev6-copy_page.S2*3* Copy an entire page.4*/56/* The following comparison of this routine vs the normal copy_page.S7was written by an unnamed ev6 hardware designer and forwarded to me8via Steven Hobbs <[email protected]>.910First Problem: STQ overflows.11-----------------------------1213It would be nice if EV6 handled every resource overflow efficiently,14but for some it doesn't. Including store queue overflows. It causes15a trap and a restart of the pipe.1617To get around this we sometimes use (to borrow a term from a VSSAD18researcher) "aeration". The idea is to slow the rate at which the19processor receives valid instructions by inserting nops in the fetch20path. In doing so, you can prevent the overflow and actually make21the code run faster. You can, of course, take advantage of the fact22that the processor can fetch at most 4 aligned instructions per cycle.2324I inserted enough nops to force it to take 10 cycles to fetch the25loop code. In theory, EV6 should be able to execute this loop in269 cycles but I was not able to get it to run that fast -- the initial27conditions were such that I could not reach this optimum rate on28(chaotic) EV6. I wrote the code such that everything would issue29in order.3031Second Problem: Dcache index matches.32-------------------------------------3334If you are going to use this routine on random aligned pages, there35is a 25% chance that the pages will be at the same dcache indices.36This results in many nasty memory traps without care.3738The solution is to schedule the prefetches to avoid the memory39conflicts. I schedule the wh64 prefetches farther ahead of the40read prefetches to avoid this problem.4142Third Problem: Needs more prefetching.43--------------------------------------4445In order to improve the code I added deeper prefetching to take the46most advantage of EV6's bandwidth.4748I also prefetched the read stream. Note that adding the read prefetch49forced me to add another cycle to the inner-most kernel - up to 1150from the original 8 cycles per iteration. We could improve performance51further by unrolling the loop and doing multiple prefetches per cycle.5253I think that the code below will be very robust and fast code for the54purposes of copying aligned pages. It is slower when both source and55destination pages are in the dcache, but it is my guess that this is56less important than the dcache miss case. */575859.text60.align 461.global copy_page62.ent copy_page63copy_page:64.prologue 06566/* Prefetch 5 read cachelines; write-hint 10 cache lines. */67wh64 ($16)68ldl $31,0($17)69ldl $31,64($17)70lda $1,1*64($16)7172wh64 ($1)73ldl $31,128($17)74ldl $31,192($17)75lda $1,2*64($16)7677wh64 ($1)78ldl $31,256($17)79lda $18,11880lda $1,3*64($16)8182wh64 ($1)83nop84lda $1,4*64($16)85lda $2,5*64($16)8687wh64 ($1)88wh64 ($2)89lda $1,6*64($16)90lda $2,7*64($16)9192wh64 ($1)93wh64 ($2)94lda $1,8*64($16)95lda $2,9*64($16)9697wh64 ($1)98wh64 ($2)99lda $19,10*64($16)100nop101102/* Main prefetching/write-hinting loop. */1031: ldq $0,0($17)104ldq $1,8($17)105unop106unop107108unop109unop110ldq $2,16($17)111ldq $3,24($17)112113ldq $4,32($17)114ldq $5,40($17)115unop116unop117118unop119unop120ldq $6,48($17)121ldq $7,56($17)122123ldl $31,320($17)124unop125unop126unop127128/* This gives the extra cycle of aeration above the minimum. */129unop130unop131unop132unop133134wh64 ($19)135unop136unop137unop138139stq $0,0($16)140subq $18,1,$18141stq $1,8($16)142unop143144unop145stq $2,16($16)146addq $17,64,$17147stq $3,24($16)148149stq $4,32($16)150stq $5,40($16)151addq $19,64,$19152unop153154stq $6,48($16)155stq $7,56($16)156addq $16,64,$16157bne $18, 1b158159/* Prefetch the final 5 cache lines of the read stream. */160lda $18,10161ldl $31,320($17)162ldl $31,384($17)163ldl $31,448($17)164165ldl $31,512($17)166ldl $31,576($17)167nop168nop169170/* Non-prefetching, non-write-hinting cleanup loop for the171final 10 cache lines. */1722: ldq $0,0($17)173ldq $1,8($17)174ldq $2,16($17)175ldq $3,24($17)176177ldq $4,32($17)178ldq $5,40($17)179ldq $6,48($17)180ldq $7,56($17)181182stq $0,0($16)183subq $18,1,$18184stq $1,8($16)185addq $17,64,$17186187stq $2,16($16)188stq $3,24($16)189stq $4,32($16)190stq $5,40($16)191192stq $6,48($16)193stq $7,56($16)194addq $16,64,$16195bne $18, 2b196197ret198nop199unop200nop201202.end copy_page203204205