/*1* arch/alpha/lib/ev6-clear_user.S2* 21264 version contributed by Rick Gorton <[email protected]>3*4* Zero user space, handling exceptions as we go.5*6* We have to make sure that $0 is always up-to-date and contains the7* right "bytes left to zero" value (and that it is updated only _after_8* a successful copy). There is also some rather minor exception setup9* stuff.10*11* NOTE! This is not directly C-callable, because the calling semantics12* are different:13*14* Inputs:15* length in $016* destination address in $617* exception pointer in $718* return address in $28 (exceptions expect it there)19*20* Outputs:21* bytes left to copy in $022*23* Clobbers:24* $1,$2,$3,$4,$5,$625*26* Much of the information about 21264 scheduling/coding comes from:27* Compiler Writer's Guide for the Alpha 2126428* abbreviated as 'CWG' in other comments here29* ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html30* Scheduling notation:31* E - either cluster32* U - upper subcluster; U0 - subcluster U0; U1 - subcluster U133* L - lower subcluster; L0 - subcluster L0; L1 - subcluster L134* Try not to change the actual algorithm if possible for consistency.35* Determining actual stalls (other than slotting) doesn't appear to be easy to do.36* From perusing the source code context where this routine is called, it is37* a fair assumption that significant fractions of entire pages are zeroed, so38* it's going to be worth the effort to hand-unroll a big loop, and use wh64.39* ASSUMPTION:40* The believed purpose of only updating $0 after a store is that a signal41* may come along during the execution of this chunk of code, and we don't42* want to leave a hole (and we also want to avoid repeating lots of work)43*/4445/* Allow an exception for an insn; exit if we get one. */46#define EX(x,y...) \4799: x,##y; \48.section __ex_table,"a"; \49.long 99b - .; \50lda $31, $exception-99b($31); \51.previous5253.set noat54.set noreorder55.align 45657.globl __do_clear_user58.ent __do_clear_user59.frame $30, 0, $2860.prologue 06162# Pipeline info : Slotting & Comments63__do_clear_user:64and $6, 7, $4 # .. E .. .. : find dest head misalignment65beq $0, $zerolength # U .. .. .. : U L U L6667addq $0, $4, $1 # .. .. .. E : bias counter68and $1, 7, $2 # .. .. E .. : number of misaligned bytes in tail69# Note - we never actually use $2, so this is a moot computation70# and we can rewrite this later...71srl $1, 3, $1 # .. E .. .. : number of quadwords to clear72beq $4, $headalign # U .. .. .. : U L U L7374/*75* Head is not aligned. Write (8 - $4) bytes to head of destination76* This means $6 is known to be misaligned77*/78EX( ldq_u $5, 0($6) ) # .. .. .. L : load dst word to mask back in79beq $1, $onebyte # .. .. U .. : sub-word store?80mskql $5, $6, $5 # .. U .. .. : take care of misaligned head81addq $6, 8, $6 # E .. .. .. : L U U L8283EX( stq_u $5, -8($6) ) # .. .. .. L :84subq $1, 1, $1 # .. .. E .. :85addq $0, $4, $0 # .. E .. .. : bytes left -= 8 - misalignment86subq $0, 8, $0 # E .. .. .. : U L U L8788.align 489/*90* (The .align directive ought to be a moot point)91* values upon initial entry to the loop92* $1 is number of quadwords to clear (zero is a valid value)93* $2 is number of trailing bytes (0..7) ($2 never used...)94* $6 is known to be aligned 0mod895*/96$headalign:97subq $1, 16, $4 # .. .. .. E : If < 16, we can not use the huge loop98and $6, 0x3f, $2 # .. .. E .. : Forward work for huge loop99subq $2, 0x40, $3 # .. E .. .. : bias counter (huge loop)100blt $4, $trailquad # U .. .. .. : U L U L101102/*103* We know that we're going to do at least 16 quads, which means we are104* going to be able to use the large block clear loop at least once.105* Figure out how many quads we need to clear before we are 0mod64 aligned106* so we can use the wh64 instruction.107*/108109nop # .. .. .. E110nop # .. .. E ..111nop # .. E .. ..112beq $3, $bigalign # U .. .. .. : U L U L : Aligned 0mod64113114$alignmod64:115EX( stq_u $31, 0($6) ) # .. .. .. L116addq $3, 8, $3 # .. .. E ..117subq $0, 8, $0 # .. E .. ..118nop # E .. .. .. : U L U L119120nop # .. .. .. E121subq $1, 1, $1 # .. .. E ..122addq $6, 8, $6 # .. E .. ..123blt $3, $alignmod64 # U .. .. .. : U L U L124125$bigalign:126/*127* $0 is the number of bytes left128* $1 is the number of quads left129* $6 is aligned 0mod64130* we know that we'll be taking a minimum of one trip through131* CWG Section 3.7.6: do not expect a sustained store rate of > 1/cycle132* We are _not_ going to update $0 after every single store. That133* would be silly, because there will be cross-cluster dependencies134* no matter how the code is scheduled. By doing it in slightly135* staggered fashion, we can still do this loop in 5 fetches136* The worse case will be doing two extra quads in some future execution,137* in the event of an interrupted clear.138* Assumes the wh64 needs to be for 2 trips through the loop in the future139* The wh64 is issued on for the starting destination address for trip +2140* through the loop, and if there are less than two trips left, the target141* address will be for the current trip.142*/143nop # E :144nop # E :145nop # E :146bis $6,$6,$3 # E : U L U L : Initial wh64 address is dest147/* This might actually help for the current trip... */148149$do_wh64:150wh64 ($3) # .. .. .. L1 : memory subsystem hint151subq $1, 16, $4 # .. .. E .. : Forward calculation - repeat the loop?152EX( stq_u $31, 0($6) ) # .. L .. ..153subq $0, 8, $0 # E .. .. .. : U L U L154155addq $6, 128, $3 # E : Target address of wh64156EX( stq_u $31, 8($6) ) # L :157EX( stq_u $31, 16($6) ) # L :158subq $0, 16, $0 # E : U L L U159160nop # E :161EX( stq_u $31, 24($6) ) # L :162EX( stq_u $31, 32($6) ) # L :163subq $0, 168, $5 # E : U L L U : two trips through the loop left?164/* 168 = 192 - 24, since we've already completed some stores */165166subq $0, 16, $0 # E :167EX( stq_u $31, 40($6) ) # L :168EX( stq_u $31, 48($6) ) # L :169cmovlt $5, $6, $3 # E : U L L U : Latency 2, extra mapping cycle170171subq $1, 8, $1 # E :172subq $0, 16, $0 # E :173EX( stq_u $31, 56($6) ) # L :174nop # E : U L U L175176nop # E :177subq $0, 8, $0 # E :178addq $6, 64, $6 # E :179bge $4, $do_wh64 # U : U L U L180181$trailquad:182# zero to 16 quadwords left to store, plus any trailing bytes183# $1 is the number of quadwords left to go.184#185nop # .. .. .. E186nop # .. .. E ..187nop # .. E .. ..188beq $1, $trailbytes # U .. .. .. : U L U L : Only 0..7 bytes to go189190$onequad:191EX( stq_u $31, 0($6) ) # .. .. .. L192subq $1, 1, $1 # .. .. E ..193subq $0, 8, $0 # .. E .. ..194nop # E .. .. .. : U L U L195196nop # .. .. .. E197nop # .. .. E ..198addq $6, 8, $6 # .. E .. ..199bgt $1, $onequad # U .. .. .. : U L U L200201# We have an unknown number of bytes left to go.202$trailbytes:203nop # .. .. .. E204nop # .. .. E ..205nop # .. E .. ..206beq $0, $zerolength # U .. .. .. : U L U L207208# $0 contains the number of bytes left to copy (0..31)209# so we will use $0 as the loop counter210# We know for a fact that $0 > 0 zero due to previous context211$onebyte:212EX( stb $31, 0($6) ) # .. .. .. L213subq $0, 1, $0 # .. .. E .. :214addq $6, 1, $6 # .. E .. .. :215bgt $0, $onebyte # U .. .. .. : U L U L216217$zerolength:218$exception: # Destination for exception recovery(?)219nop # .. .. .. E :220nop # .. .. E .. :221nop # .. E .. .. :222ret $31, ($28), 1 # L0 .. .. .. : L U L U223.end __do_clear_user224225226227