| xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame] | 1 | /* Optimized version of the standard strcpy() function. | 
 | 2 |    This file is part of the GNU C Library. | 
 | 3 |    Copyright (C) 2000-2016 Free Software Foundation, Inc. | 
 | 4 |    Contributed by Dan Pop <Dan.Pop@cern.ch>. | 
 | 5 |  | 
 | 6 |    The GNU C Library is free software; you can redistribute it and/or | 
 | 7 |    modify it under the terms of the GNU Lesser General Public | 
 | 8 |    License as published by the Free Software Foundation; either | 
 | 9 |    version 2.1 of the License, or (at your option) any later version. | 
 | 10 |  | 
 | 11 |    The GNU C Library is distributed in the hope that it will be useful, | 
 | 12 |    but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 13 |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
 | 14 |    Lesser General Public License for more details. | 
 | 15 |  | 
 | 16 |    You should have received a copy of the GNU Lesser General Public | 
 | 17 |    License along with the GNU C Library; if not, see | 
 | 18 |    <http://www.gnu.org/licenses/>.  */ | 
 | 19 |  | 
 | 20 | /* Return: dest | 
 | 21 |  | 
 | 22 |    Inputs: | 
 | 23 |         in0:    dest | 
 | 24 |         in1:    src | 
 | 25 |  | 
 | 26 |    In this form, it assumes little endian mode.  For big endian mode, | 
 | 27 |    the two shifts in .l2 must be inverted: | 
 | 28 |  | 
 | 29 | 	shl   	value = r[1], sh1   	// value = w0 << sh1 | 
 | 30 | 	shr.u   tmp = r[0], sh2   	// tmp = w1 >> sh2 | 
 | 31 |  */ | 
 | 32 |  | 
 | 33 | #include <sysdep.h> | 
 | 34 | #undef ret | 
 | 35 |  | 
 | 36 | #define saved_lc	r15 | 
 | 37 | #define saved_pr	r16 | 
 | 38 | #define thresh		r17 | 
 | 39 | #define dest		r19 | 
 | 40 | #define src		r20 | 
 | 41 | #define len		r21 | 
 | 42 | #define asrc		r22 | 
 | 43 | #define tmp		r23 | 
 | 44 | #define pos		r24 | 
 | 45 | #define w0		r25 | 
 | 46 | #define w1		r26 | 
 | 47 | #define c		r27 | 
 | 48 | #define sh2		r28 | 
 | 49 | #define	sh1		r29 | 
 | 50 | #define loopcnt		r30 | 
 | 51 | #define	value		r31 | 
 | 52 |  | 
 | 53 | ENTRY(strcpy) | 
 | 54 | 	.prologue | 
 | 55 | 	alloc 	r2 = ar.pfs, 2, 0, 30, 32 | 
 | 56 |  | 
 | 57 | #define MEMLAT 2 | 
 | 58 | 	.rotr	r[MEMLAT + 2] | 
 | 59 | 	.rotp	p[MEMLAT + 1] | 
 | 60 |  | 
 | 61 | 	mov	ret0 = in0		// return value = dest | 
 | 62 | 	.save pr, saved_pr | 
 | 63 | 	mov	saved_pr = pr           // save the predicate registers | 
 | 64 | 	.save ar.lc, saved_lc | 
 | 65 |         mov 	saved_lc = ar.lc	// save the loop counter | 
 | 66 | 	.body | 
 | 67 | 	sub	tmp = r0, in0 ;;	// tmp = -dest | 
 | 68 | 	mov 	dest = in0		// dest | 
 | 69 | 	mov 	src = in1		// src | 
 | 70 | 	and	loopcnt = 7, tmp ;;	// loopcnt = -dest % 8 | 
 | 71 | 	cmp.eq	p6, p0 = loopcnt, r0 | 
 | 72 | 	adds	loopcnt = -1, loopcnt	// --loopcnt | 
 | 73 | (p6)	br.cond.sptk .dest_aligned ;; | 
 | 74 | 	mov	ar.lc = loopcnt | 
 | 75 | .l1:					// copy -dest % 8 bytes | 
 | 76 | 	ld1	c = [src], 1		// c = *src++ | 
 | 77 | 	;; | 
 | 78 | 	st1	[dest] = c, 1		// *dest++ = c | 
 | 79 | 	cmp.eq	p6, p0 = c, r0 | 
 | 80 | (p6)	br.cond.dpnt .restore_and_exit | 
 | 81 | 	br.cloop.dptk .l1 ;; | 
 | 82 | .dest_aligned: | 
 | 83 | 	and	sh1 = 7, src 		// sh1 = src % 8 | 
 | 84 | 	mov	ar.lc = -1		// "infinite" loop | 
 | 85 | 	and	asrc = -8, src ;;	// asrc = src & -OPSIZ  -- align src | 
 | 86 | 	sub	thresh = 8, sh1 | 
 | 87 | 	mov	pr.rot = 1 << 16	// set rotating predicates | 
 | 88 | 	cmp.ne	p7, p0 = r0, r0		// clear p7 | 
 | 89 | 	shl	sh1 = sh1, 3 ;;		// sh1 = 8 * (src % 8) | 
 | 90 | 	sub	sh2 = 64, sh1		// sh2 = 64 - sh1 | 
 | 91 | 	cmp.eq  p6, p0 = sh1, r0 	// is the src aligned? | 
 | 92 | (p6)    br.cond.sptk .src_aligned ;; | 
 | 93 | 	ld8	r[1] = [asrc],8 ;; | 
 | 94 |  | 
 | 95 | 	.align	32 | 
 | 96 | .l2: | 
 | 97 | 	ld8.s	r[0] = [asrc], 8 | 
 | 98 | 	shr.u	value = r[1], sh1 ;; 	// value = w0 >> sh1 | 
 | 99 | 	czx1.r	pos = value ;;		// do we have an "early" zero | 
 | 100 | 	cmp.lt	p7, p0 = pos, thresh	// in w0 >> sh1? | 
 | 101 | (p7)	br.cond.dpnt .found0 | 
 | 102 | 	chk.s	r[0], .recovery2	// it is safe to do that only | 
 | 103 | .back2:					// after the previous test | 
 | 104 | 	shl	tmp = r[0], sh2  	// tmp = w1 << sh2 | 
 | 105 | 	;; | 
 | 106 | 	or	value = value, tmp ;;	// value |= tmp | 
 | 107 | 	czx1.r	pos = value ;; | 
 | 108 | 	cmp.ne	p7, p0 = 8, pos | 
 | 109 | (p7)	br.cond.dpnt .found0 | 
 | 110 | 	st8	[dest] = value, 8	// store val to dest | 
 | 111 | 	br.ctop.dptk    .l2 ;; | 
 | 112 | .src_aligned: | 
 | 113 | .l3: | 
 | 114 | (p[0])		ld8.s	r[0] = [src], 8 | 
 | 115 | (p[MEMLAT])	chk.s	r[MEMLAT], .recovery3 | 
 | 116 | .back3: | 
 | 117 | (p[MEMLAT])	mov	value = r[MEMLAT] | 
 | 118 | (p[MEMLAT])	czx1.r	pos = r[MEMLAT] ;; | 
 | 119 | (p[MEMLAT])	cmp.ne	p7, p0 = 8, pos | 
 | 120 | (p7)		br.cond.dpnt .found0 | 
 | 121 | (p[MEMLAT])	st8	[dest] = r[MEMLAT], 8 | 
 | 122 | 		br.ctop.dptk .l3 ;; | 
 | 123 | .found0: | 
 | 124 | 	mov	ar.lc = pos | 
 | 125 | .l4: | 
 | 126 | 	extr.u	c = value, 0, 8		// c = value & 0xff | 
 | 127 | 	shr.u	value = value, 8 | 
 | 128 | 	;; | 
 | 129 | 	st1	[dest] = c, 1 | 
 | 130 | 	br.cloop.dptk	.l4 ;; | 
 | 131 | .restore_and_exit: | 
 | 132 | 	mov 	ar.lc = saved_lc	// restore the loop counter | 
 | 133 | 	mov	pr = saved_pr, -1	// restore the predicate registers | 
 | 134 | 	br.ret.sptk.many b0 | 
 | 135 | .recovery2: | 
 | 136 | 	add	tmp = -8, asrc ;; | 
 | 137 | 	ld8	r[0] = [tmp] | 
 | 138 | 	br.cond.sptk .back2 | 
 | 139 | .recovery3: | 
 | 140 | 	add	tmp = -(MEMLAT + 1) * 8, src ;; | 
 | 141 | 	ld8	r[MEMLAT] = [tmp] | 
 | 142 | 	br.cond.sptk .back3 | 
 | 143 | END(strcpy) | 
 | 144 | libc_hidden_builtin_def (strcpy) |