Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * arch/alpha/lib/ev67-strncat.S |
| 3 | * 21264 version contributed by Rick Gorton <rick.gorton@api-networks.com> |
| 4 | * |
| 5 | * Append no more than COUNT characters from the null-terminated string SRC |
| 6 | * to the null-terminated string DST. Always null-terminate the new DST. |
| 7 | * |
| 8 | * This differs slightly from the semantics in libc in that we never write |
| 9 | * past count, whereas libc may write to count+1. This follows the generic |
| 10 | * implementation in lib/string.c and is, IMHO, more sensible. |
| 11 | * |
| 12 | * Much of the information about 21264 scheduling/coding comes from: |
| 13 | * Compiler Writer's Guide for the Alpha 21264 |
| 14 | * abbreviated as 'CWG' in other comments here |
| 15 | * ftp.digital.com/pub/Digital/info/semiconductor/literature/dsc-library.html |
| 16 | * Scheduling notation: |
| 17 | * E - either cluster |
| 18 | * U - upper subcluster; U0 - subcluster U0; U1 - subcluster U1 |
| 19 | * L - lower subcluster; L0 - subcluster L0; L1 - subcluster L1 |
| 20 | * Try not to change the actual algorithm if possible for consistency. |
| 21 | */ |
| 22 | |
Al Viro | 00fc0e0 | 2016-01-11 09:51:29 -0500 | [diff] [blame] | 23 | #include <asm/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | .text |
| 25 | |
| 26 | .align 4 |
| 27 | .globl strncat |
| 28 | .ent strncat |
| 29 | strncat: |
| 30 | .frame $30, 0, $26 |
| 31 | .prologue 0 |
| 32 | |
| 33 | mov $16, $0 # set up return value |
| 34 | beq $18, $zerocount # U : |
| 35 | /* Find the end of the string. */ |
| 36 | ldq_u $1, 0($16) # L : load first quadword ($16 may be misaligned) |
| 37 | lda $2, -1($31) # E : |
| 38 | |
| 39 | insqh $2, $0, $2 # U : |
| 40 | andnot $16, 7, $16 # E : |
| 41 | nop # E : |
| 42 | or $2, $1, $1 # E : |
| 43 | |
| 44 | nop # E : |
| 45 | nop # E : |
| 46 | cmpbge $31, $1, $2 # E : bits set iff byte == 0 |
| 47 | bne $2, $found # U : |
| 48 | |
| 49 | $loop: ldq $1, 8($16) # L : |
| 50 | addq $16, 8, $16 # E : |
| 51 | cmpbge $31, $1, $2 # E : |
| 52 | beq $2, $loop # U : |
| 53 | |
| 54 | $found: cttz $2, $3 # U0 : |
| 55 | addq $16, $3, $16 # E : |
| 56 | nop # E : |
| 57 | bsr $23, __stxncpy # L0 :/* Now do the append. */ |
| 58 | |
| 59 | /* Worry about the null termination. */ |
| 60 | |
| 61 | zapnot $1, $27, $2 # U : was last byte a null? |
| 62 | cmplt $27, $24, $5 # E : did we fill the buffer completely? |
| 63 | bne $2, 0f # U : |
| 64 | ret # L0 : |
| 65 | |
| 66 | 0: or $5, $18, $2 # E : |
| 67 | nop |
| 68 | bne $2, 2f # U : |
| 69 | and $24, 0x80, $3 # E : no zero next byte |
| 70 | |
| 71 | nop # E : |
| 72 | bne $3, 1f # U : |
| 73 | /* Here there are bytes left in the current word. Clear one. */ |
| 74 | addq $24, $24, $24 # E : end-of-count bit <<= 1 |
| 75 | nop # E : |
| 76 | |
| 77 | 2: zap $1, $24, $1 # U : |
| 78 | nop # E : |
| 79 | stq_u $1, 0($16) # L : |
| 80 | ret # L0 : |
| 81 | |
| 82 | 1: /* Here we must clear the first byte of the next DST word */ |
| 83 | stb $31, 8($16) # L : |
| 84 | nop # E : |
| 85 | nop # E : |
| 86 | ret # L0 : |
| 87 | |
| 88 | $zerocount: |
| 89 | nop # E : |
| 90 | nop # E : |
| 91 | nop # E : |
| 92 | ret # L0 : |
| 93 | |
| 94 | .end strncat |
Al Viro | 00fc0e0 | 2016-01-11 09:51:29 -0500 | [diff] [blame] | 95 | EXPORT_SYMBOL(strncat) |