| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Copyright (C) 1996-2016 Free Software Foundation, Inc. | 
|  | 2 | This file is part of the GNU C Library. | 
|  | 3 | Contributed by Richard Henderson (rth@tamu.edu) | 
|  | 4 |  | 
|  | 5 | The GNU C Library is free software; you can redistribute it and/or | 
|  | 6 | modify it under the terms of the GNU Lesser General Public | 
|  | 7 | License as published by the Free Software Foundation; either | 
|  | 8 | version 2.1 of the License, or (at your option) any later version. | 
|  | 9 |  | 
|  | 10 | The GNU C Library is distributed in the hope that it will be useful, | 
|  | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|  | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|  | 13 | Lesser General Public License for more details. | 
|  | 14 |  | 
|  | 15 | You should have received a copy of the GNU Lesser General Public | 
|  | 16 | License along with the GNU C Library.  If not, see | 
|  | 17 | <http://www.gnu.org/licenses/>.  */ | 
|  | 18 |  | 
|  | 19 | /* Copy no more than COUNT bytes of the null-terminated string from | 
|  | 20 | SRC to DST.  If SRC does not cover all of COUNT, the balance is | 
|  | 21 | zeroed.  Return the address of the terminating null in DEST, if | 
|  | 22 | any, else DEST + COUNT.  */ | 
|  | 23 |  | 
|  | 24 | #include <sysdep.h> | 
|  | 25 |  | 
|  | 26 | .set noat | 
|  | 27 | .set noreorder | 
|  | 28 |  | 
|  | 29 | .text | 
|  | 30 |  | 
|  | 31 | ENTRY(__stpncpy) | 
|  | 32 | ldgp	gp, 0(pv) | 
|  | 33 | #ifdef PROF | 
|  | 34 | lda	AT, _mcount | 
|  | 35 | jsr	AT, (AT), _mcount | 
|  | 36 | #endif | 
|  | 37 | .prologue 1 | 
|  | 38 |  | 
|  | 39 | beq	a2, $zerocount | 
|  | 40 | jsr	t9, __stxncpy	# do the work of the copy | 
|  | 41 |  | 
|  | 42 | and	t8, 0xf0, t3	# binary search for byte offset of the | 
|  | 43 | and	t8, 0xcc, t2	# last byte written. | 
|  | 44 | and	t8, 0xaa, t1 | 
|  | 45 | andnot	a0, 7, v0 | 
|  | 46 | cmovne	t3, 4, t3 | 
|  | 47 | cmovne	t2, 2, t2 | 
|  | 48 | cmovne	t1, 1, t1 | 
|  | 49 | addq	v0, t3, v0 | 
|  | 50 | addq	t1, t2, t1 | 
|  | 51 | addq	v0, t1, v0 | 
|  | 52 |  | 
|  | 53 | bne	a2, $multiword	# do we have full words left? | 
|  | 54 |  | 
|  | 55 | .align 3 | 
|  | 56 | zapnot	t0, t8, t4	# e0    : was last byte a null? | 
|  | 57 | subq	t8, 1, t2	# .. e1 : | 
|  | 58 | addq	v0, 1, t5	# e0    : | 
|  | 59 | subq	t10, 1, t3	# .. e1 : | 
|  | 60 | or	t2, t8, t2	# e0    : clear the bits between the last | 
|  | 61 | or	t3, t10, t3	# .. e1 : written byte and the last byte in | 
|  | 62 | andnot	t3, t2, t3	# e0    : COUNT | 
|  | 63 | cmovne	t4, t5, v0	# .. e1 : if last written wasnt null, inc v0 | 
|  | 64 | zap	t0, t3, t0	# e0    : | 
|  | 65 | stq_u	t0, 0(a0)	# e1    : | 
|  | 66 | ret			# .. e1 : | 
|  | 67 |  | 
|  | 68 | .align 3 | 
|  | 69 | $multiword: | 
|  | 70 | subq	t8, 1, t7	# e0    : clear the final bits in the prev | 
|  | 71 | or	t7, t8, t7	# e1    : word | 
|  | 72 | zapnot	t0, t7, t0	# e0    : | 
|  | 73 | subq	a2, 1, a2	# .. e1 : | 
|  | 74 | stq_u	t0, 0(a0)	# e0    : | 
|  | 75 | addq	a0, 8, a0	# .. e1 : | 
|  | 76 |  | 
|  | 77 | beq	a2, 1f		# e1    : | 
|  | 78 | blbc	a2, 0f		# e1    : | 
|  | 79 |  | 
|  | 80 | stq_u	zero, 0(a0)	# e0    : zero one word | 
|  | 81 | subq	a2, 1, a2	# .. e1 : | 
|  | 82 | addq	a0, 8, a0	# e0    : | 
|  | 83 | beq	a2, 1f		# .. e1 : | 
|  | 84 |  | 
|  | 85 | 0:	stq_u	zero, 0(a0)	# e0    : zero two words | 
|  | 86 | subq	a2, 2, a2	# .. e1 : | 
|  | 87 | stq_u	zero, 8(a0)	# e0    : | 
|  | 88 | addq	a0, 16, a0	# .. e1 : | 
|  | 89 | bne	a2, 0b		# e1    : | 
|  | 90 | unop | 
|  | 91 |  | 
|  | 92 | 1:	ldq_u	t0, 0(a0)	# e0    : clear the leading bits in the final | 
|  | 93 | subq	t10, 1, t7	# .. e1 : word | 
|  | 94 | or	t7, t10, t7	# e0    : | 
|  | 95 | zap	t0, t7, t0	# e1 (stall) | 
|  | 96 | stq_u	t0, 0(a0)	# e0    : | 
|  | 97 | ret			# .. e1 : | 
|  | 98 |  | 
|  | 99 | $zerocount: | 
|  | 100 | mov	a0, v0 | 
|  | 101 | ret | 
|  | 102 |  | 
|  | 103 | END(__stpncpy) | 
|  | 104 |  | 
|  | 105 | libc_hidden_def (__stpncpy) | 
|  | 106 | weak_alias (__stpncpy, stpncpy) |